Skip to content

Commit 918fb62

Browse files
committed
get_parameters增加了raw参数
1 parent 982529e commit 918fb62

File tree

5 files changed

+68
-42
lines changed

5 files changed

+68
-42
lines changed

examples/workflow_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def example_get_app_info():
7272

7373
traceback.print_exc()
7474
return None
75-
75+
76+
7677
def example_get_app_parameters():
7778
"""获取应用参数示例"""
7879
print("\n==== 获取应用参数 ====")
@@ -81,6 +82,7 @@ def example_get_app_parameters():
8182
pprint(params)
8283
return params
8384

85+
8486
def example_run_workflow_blocking():
8587
"""以阻塞模式运行工作流示例"""
8688
print("\n==== 以阻塞模式运行工作流 ====")

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.2"
14+
__version__ = "0.1.3"
1515
__all__ = [
1616
"WorkflowClient",
1717
"ChatbotClient",

pydify/common.py

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

518-
519518
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']
519+
"image": [".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg"],
520+
"document": [
521+
".txt",
522+
".md",
523+
".markdown",
524+
".pdf",
525+
".html",
526+
".xlsx",
527+
".xls",
528+
".docx",
529+
".csv",
530+
".eml",
531+
".msg",
532+
".pptx",
533+
".ppt",
534+
".xml",
535+
".epub",
536+
],
537+
"audio": [".mp3", ".m4a", ".wav", ".webm", ".amr"],
538+
"video": [".mp4", ".mov", ".mpeg", ".mpga"],
524539
}
525-
526-
def get_parameters(self, **kwargs) -> Dict[str, Any]:
540+
541+
def get_parameters(self, raw: bool = False, **kwargs) -> Dict[str, Any]:
527542
"""
528543
获取应用参数,包括功能开关、输入参数配置、文件上传限制等。
529-
544+
530545
此方法通常用于应用初始化阶段,获取应用的各种配置参数和功能开关状态。
531-
546+
532547
Args:
548+
raw (bool): 是否返回原始数据,默认返回处理后的数据
533549
**kwargs: 额外的请求参数,如timeout、max_retries等
534-
550+
535551
Returns:
536552
Dict[str, Any]: 包含应用参数的字典,可能包含以下字段:
537553
- opening_statement (str): 应用开场白文本
@@ -567,7 +583,7 @@ def get_parameters(self, **kwargs) -> Dict[str, Any]:
567583
- custom: 自定义文件类型
568584
- allowed_file_extensions (List[str]): 允许的文件后缀列表
569585
(仅当allowed_file_types为custom时需要配置)
570-
- document类型包含: 'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX',
586+
- document类型包含: 'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX',
571587
'XLS', 'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
572588
- image类型包含: 'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
573589
- audio类型包含: 'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
@@ -582,18 +598,18 @@ def get_parameters(self, **kwargs) -> Dict[str, Any]:
582598
- video_file_size_limit (int): 视频上传大小限制(MB)
583599
Raises:
584600
DifyAPIError: 当API请求失败时
585-
601+
586602
Example:
587603
```python
588604
# 获取应用参数
589605
params = client.get_parameters()
590-
606+
591607
# 示例返回数据:
592608
{
593609
"user_input_form": [
594610
{
595611
"label": "Query",
596-
"variable": "query",
612+
"variable": "query",
597613
"required": true,
598614
"max_length": 1000, # 最大长度限制
599615
"type": "paragraph"
@@ -649,24 +665,29 @@ def get_parameters(self, **kwargs) -> Dict[str, Any]:
649665
```
650666
"""
651667
params = self.get("parameters", **kwargs)
668+
669+
if raw:
670+
return params
652671

653672
# 对user_input_form进行处理,使其变成一个列表
654673
user_input_form = []
655674
for item in params["user_input_form"]:
656675
for form_type in item:
657676
type_item = item[form_type]
658-
type_item['type'] = form_type
659-
if form_type in ['file', 'file-list']:
677+
type_item["type"] = form_type
678+
if form_type in ["file", "file-list"]:
660679
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])
680+
if "custom" not in type_item["allowed_file_types"]:
681+
for allowed_file_type in type_item["allowed_file_types"]:
682+
allowed_file_extensions.extend(
683+
self.ALLOWED_FILE_EXTENSIONS[allowed_file_type]
684+
)
664685
else:
665-
allowed_file_extensions = type_item['allowed_file_extensions']
666-
type_item['allowed_file_extensions'] = allowed_file_extensions
686+
allowed_file_extensions = type_item["allowed_file_extensions"]
687+
type_item["allowed_file_extensions"] = allowed_file_extensions
667688
user_input_form.append(type_item)
668689
params["user_input_form"] = user_input_form
669-
690+
670691
return params
671692

672693
def get_conversations(
@@ -844,14 +865,15 @@ def __str__(self) -> str:
844865
return f"[{self.status_code}] {self.message}"
845866
return self.message
846867

868+
847869
def analyze_app_capabilities(client):
848870
"""分析应用的功能和配置"""
849871
# 获取应用参数
850872
params = client.get_parameters()
851-
873+
852874
# 基本信息
853875
print("=== 应用功能配置分析 ===")
854-
876+
855877
# 检查基本功能
856878
features = []
857879
if "opening_statement" in params and params["opening_statement"]:
@@ -866,9 +888,9 @@ def analyze_app_capabilities(client):
866888
features.append("引用和归属")
867889
if params.get("annotation_reply", {}).get("enabled"):
868890
features.append("标记回复")
869-
891+
870892
print(f"启用的功能: {', '.join(features) if features else '无特殊功能'}")
871-
893+
872894
# 检查表单配置
873895
if "user_input_form" in params:
874896
form_types = []
@@ -877,33 +899,35 @@ def analyze_app_capabilities(client):
877899
for form_type in item:
878900
form_types.append(form_type)
879901
variables.append(item[form_type].get("variable"))
880-
902+
881903
print(f"\n表单配置: 共{len(params['user_input_form'])}个控件")
882904
print(f"控件类型: {', '.join(form_types)}")
883905
print(f"变量名列表: {', '.join(variables)}")
884-
906+
885907
# 检查文件上传能力
886908
if "file_upload" in params:
887909
upload_types = []
888910
for upload_type, config in params["file_upload"].items():
889911
if config.get("enabled"):
890912
upload_types.append(upload_type)
891-
913+
892914
if upload_types:
893915
print(f"\n支持上传文件类型: {', '.join(upload_types)}")
894-
916+
895917
# 详细的图片上传配置
896-
if "image" in params["file_upload"] and params["file_upload"]["image"].get("enabled"):
918+
if "image" in params["file_upload"] and params["file_upload"]["image"].get(
919+
"enabled"
920+
):
897921
img_config = params["file_upload"]["image"]
898922
print(f"图片上传限制: 最多{img_config.get('number_limits', 0)}张")
899-
print(f"支持的传输方式: {', '.join(img_config.get('transfer_methods', []))}")
900-
923+
print(
924+
f"支持的传输方式: {', '.join(img_config.get('transfer_methods', []))}"
925+
)
926+
901927
# 检查系统参数
902928
if "system_parameters" in params:
903929
print("\n系统参数限制:")
904930
for param, value in params["system_parameters"].items():
905931
print(f"- {param}: {value}MB")
906-
907-
return params
908-
909932

933+
return params

pydify/workflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def run(
2727
) -> Union[Dict[str, Any], Generator[Dict[str, Any], None, None]]:
2828
"""
2929
执行工作流。
30-
30+
3131
Args:
3232
inputs (Dict[str, Any]): 必需参数。包含工作流所需的输入变量键值对。
3333
每个键对应一个变量名称,值为该变量的具体内容。
@@ -37,7 +37,7 @@ def run(
3737
response_mode (str, optional): 响应模式,'streaming'(流式)或'blocking'(阻塞)。默认为'streaming'。
3838
files (List[Dict[str, Any]], optional): 文件列表,每个文件为一个字典,包含以下字段:
3939
- type (str): 文件类型,支持:
40-
- document: 支持'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS',
40+
- document: 支持'TXT', 'MD', 'MARKDOWN', 'PDF', 'HTML', 'XLSX', 'XLS',
4141
'DOCX', 'CSV', 'EML', 'MSG', 'PPTX', 'PPT', 'XML', 'EPUB'
4242
- image: 支持'JPG', 'JPEG', 'PNG', 'GIF', 'WEBP', 'SVG'
4343
- audio: 支持'MP3', 'M4A', 'WAV', 'WEBM', 'AMR'
@@ -69,7 +69,7 @@ def run(
6969
inputs = {
7070
"document": {
7171
"type": "document",
72-
"transfer_method": "remote_url",
72+
"transfer_method": "remote_url",
7373
"url": "https://example.com/doc.pdf"
7474
}
7575
}

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.2",
35+
version="0.1.3",
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)