Skip to content

Commit 982529e

Browse files
committed
v0.1.2
1 parent 0d4a41b commit 982529e

File tree

4 files changed

+129
-27
lines changed

4 files changed

+129
-27
lines changed

examples/workflow_example.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ def example_get_app_info():
7272

7373
traceback.print_exc()
7474
return None
75-
75+
76+
def example_get_app_parameters():
77+
"""获取应用参数示例"""
78+
print("\n==== 获取应用参数 ====")
79+
request_kwargs = get_request_kwargs()
80+
params = client.get_parameters(**request_kwargs)
81+
pprint(params)
82+
return params
7683

7784
def example_run_workflow_blocking():
7885
"""以阻塞模式运行工作流示例"""
@@ -374,7 +381,7 @@ def validate_workflow_app():
374381
try:
375382
# 运行基本示例
376383
example_get_app_info()
377-
384+
example_get_app_parameters()
378385
# 如果是Workflow应用,或者用户选择继续运行,则执行以下示例
379386
example_run_workflow_blocking()
380387
example_run_workflow_streaming()

pydify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .text_generation import TextGenerationClient
1212
from .workflow import WorkflowClient
1313

14-
__version__ = "0.1.0"
14+
__version__ = "0.1.2"
1515
__all__ = [
1616
"WorkflowClient",
1717
"ChatbotClient",

pydify/common.py

Lines changed: 118 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,14 @@ def get_app_info(self) -> Dict[str, Any]:
515515
"""
516516
return self.get("info")
517517

518+
519+
ALLOWED_FILE_EXTENSIONS = {
520+
'image': ['.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg'],
521+
'document': ['.txt', '.md', '.markdown', '.pdf', '.html', '.xlsx', '.xls', '.docx', '.csv', '.eml', '.msg', '.pptx', '.ppt', '.xml', '.epub'],
522+
'audio': ['.mp3', '.m4a', '.wav', '.webm', '.amr'],
523+
'video': ['.mp4', '.mov', '.mpeg', '.mpga']
524+
}
525+
518526
def get_parameters(self, **kwargs) -> Dict[str, Any]:
519527
"""
520528
获取应用参数,包括功能开关、输入参数配置、文件上传限制等。
@@ -536,21 +544,42 @@ def get_parameters(self, **kwargs) -> Dict[str, Any]:
536544
- enabled (bool): 是否启用此功能
537545
- annotation_reply (Dict): 标记回复功能配置
538546
- enabled (bool): 是否启用此功能
539-
- user_input_form (List[Dict]): 用户输入表单配置列表,每项可能包含:
540-
- text-input: 文本输入控件配置
541-
- paragraph: 段落文本输入控件配置
542-
- select: 下拉选择控件配置
543-
- file_upload (Dict): 文件上传相关配置
544-
- image (Dict): 图片上传配置
545-
- enabled (bool): 是否启用图片上传
546-
- number_limits (int): 图片数量限制
547-
- transfer_methods (List[str]): 支持的传输方式
547+
- user_input_form (List[Dict]): 用户输入表单配置列表,每项包含一个控件配置:
548+
通用配置:
549+
- type: 控件类型
550+
- text-input: 单行文本输入
551+
- paragraph: 多行文本输入
552+
- select: 下拉选择框,需配置options选项列表
553+
- number: 数字输入框
554+
- file: 单文件上传,可限制文件类型和上传方式
555+
- file-list: 多文件上传,可设置最大数量
556+
- label: 显示名称
557+
- variable: 变量标识
558+
- required: 是否必填
559+
- max_length: 最大长度限制/最大数量限制
560+
- options: 选项值列表(可选)
561+
file/file-list类型控件特殊配置:
562+
- allowed_file_types (str): 允许的文件类型,可选值:
563+
- image: 图片文件
564+
- document: 文档文件
565+
- audio: 音频文件
566+
- video: 视频文件
567+
- custom: 自定义文件类型
568+
- allowed_file_extensions (List[str]): 允许的文件后缀列表
569+
(仅当allowed_file_types为custom时需要配置)
570+
- document类型包含: 'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX',
571+
'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
572+
- image类型包含: 'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
573+
- audio类型包含: 'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
574+
- video类型包含: 'MP4', 'MOV', 'MPEG', 'MPGA'
575+
- allowed_file_upload_methods (List[str]): 允许的文件上传方式,可多选
576+
- remote_url: 远程URL上传
577+
- local_file: 本地文件上传
548578
- system_parameters (Dict): 系统级参数
549579
- file_size_limit (int): 文档上传大小限制(MB)
550580
- image_file_size_limit (int): 图片上传大小限制(MB)
551581
- audio_file_size_limit (int): 音频上传大小限制(MB)
552582
- video_file_size_limit (int): 视频上传大小限制(MB)
553-
554583
Raises:
555584
DifyAPIError: 当API请求失败时
556585
@@ -559,19 +588,86 @@ def get_parameters(self, **kwargs) -> Dict[str, Any]:
559588
# 获取应用参数
560589
params = client.get_parameters()
561590
562-
# 检查是否启用了图片上传
563-
if params.get('file_upload', {}).get('image', {}).get('enabled', False):
564-
print("此应用支持图片上传")
565-
print(f"图片数量限制: {params['file_upload']['image']['number_limits']}")
566-
567-
# 获取用户输入表单配置
568-
forms = params.get('user_input_form', [])
569-
for form in forms:
570-
for form_type, config in form.items():
571-
print(f"表单类型: {form_type}, 字段名: {config.get('label')}")
591+
# 示例返回数据:
592+
{
593+
"user_input_form": [
594+
{
595+
"label": "Query",
596+
"variable": "query",
597+
"required": true,
598+
"max_length": 1000, # 最大长度限制
599+
"type": "paragraph"
600+
},
601+
{
602+
'label': 'Input',
603+
'variable': 'input',
604+
'required': True,
605+
'max_length': 100, # 最大长度限制
606+
"type": "text-input"
607+
},
608+
{
609+
'label': 'Select',
610+
'variable': 'select',
611+
'required': True,
612+
'options': ['Option1', 'Option2', 'Option3'],
613+
"type": "select"
614+
},
615+
{
616+
'label': 'Number',
617+
'variable': 'number',
618+
'required': True,
619+
"type": "number"
620+
},
621+
{
622+
'label': 'Image',
623+
'variable': 'image',
624+
'required': True,
625+
"type": "file",
626+
'allowed_file_types': ['image'],
627+
'allowed_file_extensions': [...],
628+
'allowed_file_upload_methods': ['remote_url', 'local_file']
629+
}
630+
},
631+
{
632+
'label': 'Files',
633+
'variable': 'files',
634+
'required': True,
635+
'max_length': 3, # 最大数量限制
636+
'allowed_file_types': ['image', 'document', 'audio', 'video'],
637+
'allowed_file_extensions': [...]
638+
},
639+
"type": "file-list"
640+
}
641+
],
642+
"system_parameters": {
643+
"file_size_limit": 15,
644+
"image_file_size_limit": 10,
645+
"audio_file_size_limit": 50,
646+
"video_file_size_limit": 100
647+
}
648+
}
572649
```
573650
"""
574-
return self.get("parameters", **kwargs)
651+
params = self.get("parameters", **kwargs)
652+
653+
# 对user_input_form进行处理,使其变成一个列表
654+
user_input_form = []
655+
for item in params["user_input_form"]:
656+
for form_type in item:
657+
type_item = item[form_type]
658+
type_item['type'] = form_type
659+
if form_type in ['file', 'file-list']:
660+
allowed_file_extensions = []
661+
if 'custom' not in type_item['allowed_file_types']:
662+
for allowed_file_type in type_item['allowed_file_types']:
663+
allowed_file_extensions.extend(self.ALLOWED_FILE_EXTENSIONS[allowed_file_type])
664+
else:
665+
allowed_file_extensions = type_item['allowed_file_extensions']
666+
type_item['allowed_file_extensions'] = allowed_file_extensions
667+
user_input_form.append(type_item)
668+
params["user_input_form"] = user_input_form
669+
670+
return params
575671

576672
def get_conversations(
577673
self,
@@ -810,5 +906,4 @@ def analyze_app_capabilities(client):
810906

811907
return params
812908

813-
# 使用示例
814-
app_params = analyze_app_capabilities(client)
909+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
setuptools.setup(
3434
name="pydify",
35-
version="0.1.0",
35+
version="0.1.2",
3636
author="Dify SDK Team",
3737
author_email="[email protected]",
3838
description="A Python SDK for interacting with Dify API",

0 commit comments

Comments
 (0)