Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed DEVELOPMENT.md
Empty file.
10 changes: 6 additions & 4 deletions manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ author: qiniu
icon: icon_s_en.svg
created_at: '2025-07-31T00:13:50.29298939-04:00'
description:
en_US: Official Qiniu Cloud Dify plugin providing AI inference services, supporting models such as deepseek-r1, deepseek-v3, and more.
zh_Hans: 七牛云官方 Dify 插件,提供 AI 推理服务,支持例如 deepseek-r1、deepseek-v3 等模型
en_US: Official Qiniu Cloud Dify plugin providing comprehensive AI inference services and cloud storage management. Supports multiple LLM models including deepseek-r1, deepseek-v3, GLM-4.5, Kimi-K2, Qwen series, and offers complete file management capabilities such as file upload, bucket operations, and content retrieval.
zh_Hans: 七牛云官方 Dify 插件,提供全面的 AI 推理服务和云存储管理功能。支持 deepseek-r1、deepseek-v3、GLM-4.5、Kimi-K2、Qwen 系列等多种大语言模型,并提供完整的文件管理能力,包括文件上传、存储空间操作和内容获取等功能

label:
en_US: Qiniu Cloud
Expand All @@ -21,6 +21,8 @@ meta:
plugins:
models:
- provider/qiniu.yaml
tools:
- provider/qiniu_tools.yaml
resource:
memory: 268435456
permission:
Expand All @@ -33,6 +35,6 @@ resource:
text_embedding: false
tts: false
tool:
enabled: false
enabled: true
type: plugin
version: 0.0.3
version: 0.1.0
60 changes: 55 additions & 5 deletions provider/qiniu.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import logging
from dify_plugin.entities.model import ModelType
from dify_plugin.errors.model import CredentialsValidateFailedError
from dify_plugin import ModelProvider
from dify_plugin.errors.tool import ToolProviderCredentialValidationError
from dify_plugin import ModelProvider, ToolProvider
from qiniu import Auth, BucketManager

logger = logging.getLogger(__name__)


class QiniuProvider(ModelProvider):
class QiniuProvider(ModelProvider, ToolProvider):
"""
七牛云模型提供商实现类
七牛云提供商实现类

提供七牛云 AI 模型的接入能力,支持多种大语言模型
提供七牛云 AI 模型的接入能力和云存储工具能力,支持多种大语言模型和文件上传功能
"""

def validate_provider_credentials(self, credentials: dict) -> None:
"""
验证供应商认证信息
验证供应商认证信息(用于模型服务)
如果验证失败,会抛出异常

Args:
Expand All @@ -33,3 +35,51 @@ def validate_provider_credentials(self, credentials: dict) -> None:
except Exception as ex:
logger.exception(f"{self.get_provider_schema().provider} credentials validate failed")
raise ex

def _validate_credentials(self, credentials: dict) -> None:
"""
验证工具认证信息(用于工具服务)
验证七牛云 Access Key 和 Secret Key 的有效性

Args:
credentials: 认证信息字典,包含 qiniu_access_key 和 qiniu_secret_key

Raises:
ToolProviderCredentialValidationError: 认证验证失败
"""
try:
access_key = credentials.get("qiniu_access_key")
secret_key = credentials.get("qiniu_secret_key")

if not access_key or not secret_key:
raise ToolProviderCredentialValidationError("七牛云 Access Key 和 Secret Key 不能为空")

# 创建认证对象
auth = Auth(access_key, secret_key)
bucket_manager = BucketManager(auth)

# 尝试获取空间列表来验证认证信息
# 这里只是验证认证是否有效,不需要具体的空间名
try:
# 调用接口验证认证信息
ret, eof, info = bucket_manager.buckets()

if info.status_code == 200:
logger.info("七牛云认证验证成功")
elif info.status_code == 401:
raise ToolProviderCredentialValidationError("七牛云认证失败,请检查 Access Key 和 Secret Key 是否正确")
else:
raise ToolProviderCredentialValidationError(f"七牛云认证验证失败: HTTP {info.status_code}")

except Exception as api_error:
if "401" in str(api_error) or "Unauthorized" in str(api_error):
raise ToolProviderCredentialValidationError("七牛云认证失败,请检查 Access Key 和 Secret Key 是否正确")
else:
# 如果是网络错误等其他错误,我们假设认证信息是正确的
logger.warning(f"七牛云认证验证时出现网络错误,跳过验证: {str(api_error)}")

except ToolProviderCredentialValidationError:
raise
except Exception as e:
logger.exception("七牛云认证验证过程中发生未知错误")
raise ToolProviderCredentialValidationError(f"认证验证失败: {str(e)}")
64 changes: 64 additions & 0 deletions provider/qiniu_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import logging
from typing import Any

from dify_plugin import ToolProvider
from dify_plugin.errors.tool import ToolProviderCredentialValidationError
from qiniu import Auth, BucketManager

logger = logging.getLogger(__name__)


class QiniuProvider(ToolProvider):
"""
七牛云工具提供商实现类

提供七牛云存储工具能力,支持文件上传功能
"""

def _validate_credentials(self, credentials: dict[str, Any]) -> None:
"""
验证工具认证信息(用于工具服务)
验证七牛云 Access Key 和 Secret Key 的有效性

Args:
credentials: 认证信息字典,包含 qiniu_access_key 和 qiniu_secret_key

Raises:
ToolProviderCredentialValidationError: 认证验证失败
"""
try:
access_key = credentials.get("qiniu_access_key")
secret_key = credentials.get("qiniu_secret_key")

if not access_key or not secret_key:
raise ToolProviderCredentialValidationError("七牛云 Access Key 和 Secret Key 不能为空")

# 创建认证对象
auth = Auth(access_key, secret_key)
bucket_manager = BucketManager(auth)

# 尝试获取空间列表来验证认证信息
# 这里只是验证认证是否有效,不需要具体的空间名
try:
# 调用接口验证认证信息
ret, eof, info = bucket_manager.buckets()

if info.status_code == 200:
logger.info("七牛云认证验证成功")
elif info.status_code == 401:
raise ToolProviderCredentialValidationError("七牛云认证失败,请检查 Access Key 和 Secret Key 是否正确")
else:
raise ToolProviderCredentialValidationError(f"七牛云认证验证失败: HTTP {info.status_code}")

except Exception as api_error:
if "401" in str(api_error) or "Unauthorized" in str(api_error):
raise ToolProviderCredentialValidationError("七牛云认证失败,请检查 Access Key 和 Secret Key 是否正确")
else:
# 如果是网络错误等其他错误,我们假设认证信息是正确的
logger.warning(f"七牛云认证验证时出现网络错误,跳过验证: {str(api_error)}")

except ToolProviderCredentialValidationError:
raise
except Exception as e:
logger.exception("七牛云认证验证过程中发生未知错误")
raise ToolProviderCredentialValidationError(f"认证验证失败: {str(e)}")
48 changes: 48 additions & 0 deletions provider/qiniu_tools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
identity:
author: qiniu
name: qiniu
label:
en_US: Qiniu Cloud
zh_Hans: 七牛云
description:
en_US: Official Qiniu Cloud Storage plugin providing file upload services
zh_Hans: 七牛云官方存储插件,提供文件上传服务
icon: icon_s_en.svg
tags:
- utilities
- productivity
credentials_for_provider:
qiniu_access_key:
type: secret-input
required: true
label:
en_US: Qiniu Access Key
zh_Hans: 七牛云 Access Key
placeholder:
en_US: Enter your Qiniu Access Key
zh_Hans: 在此输入您的七牛云 Access Key
help:
en_US: Get your Access Key from Qiniu Cloud Console
zh_Hans: 从七牛云控制台获取 Access Key
url: https://portal.qiniu.com/user/key
qiniu_secret_key:
type: secret-input
required: true
label:
en_US: Qiniu Secret Key
zh_Hans: 七牛云 Secret Key
placeholder:
en_US: Enter your Qiniu Secret Key
zh_Hans: 在此输入您的七牛云 Secret Key
help:
en_US: Get your Secret Key from Qiniu Cloud Console
zh_Hans: 从七牛云控制台获取 Secret Key
url: https://portal.qiniu.com/user/key
tools:
- tools/list_buckets.yaml
- tools/file_upload.yaml
- tools/list_bucket_files.yaml
- tools/get_file_content.yaml
extra:
python:
source: provider/qiniu_tools.py
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dify_plugin>=0.3.0,<0.5.0
dify_plugin>=0.0.1b22
requests>=2.25.0
qiniu>=7.12.0
Empty file removed test_plugin.py
Empty file.
Loading