Skip to content

Commit aae03f2

Browse files
committed
build and test
1 parent b73cb6e commit aae03f2

File tree

12 files changed

+92
-207
lines changed

12 files changed

+92
-207
lines changed

build_and_test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ echo "=== 检查包 ==="
2424
pip install twine
2525
twine check dist/*
2626

27+
git add -A
28+
git commit -m "build and test"
29+
git push
30+
2731
echo "=== 完成! ==="
2832
echo "如果要发布到PyPI,请运行:"
2933
echo "twine upload dist/*"

examples/test_examples.py

Lines changed: 0 additions & 126 deletions
This file was deleted.

pydify/README.md

Whitespace-only changes.

pydify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def create_client(type: str, base_url: str, api_key: str) -> DifyBaseClient:
2828
raise ValueError(f"Invalid client type: {type}")
2929

3030

31-
__version__ = "2.0.0"
31+
__version__ = "2.1.0"
3232
__all__ = [
3333
"WorkflowClient",
3434
"ChatbotClient",

pydify/agent.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
import os
1111
from typing import Any, BinaryIO, Dict, Generator, List, Optional, Tuple, Union
1212

13-
from .common import DifyBaseClient, DifyType
1413
from .chatbot import ChatbotClient
14+
from .common import DifyBaseClient, DifyType
15+
16+
1517
class AgentEvent:
1618
"""事件类型枚举
1719
@@ -28,7 +30,7 @@ class AgentEvent:
2830
MESSAGE_REPLACE = "message_replace" # 消息内容替换事件,用于内容审查后的替换
2931
ERROR = "error" # 流式输出过程中出现的异常事件
3032
PING = "ping" # 保持连接存活的ping事件,每10秒一次
31-
33+
3234

3335
class AgentClient(ChatbotClient):
3436
"""Dify Agent应用客户端类。
@@ -38,11 +40,11 @@ class AgentClient(ChatbotClient):
3840
"""
3941

4042
type = DifyType.Agent
41-
43+
4244
def __init__(self, *args, **kwargs):
4345
super().__init__(*args, **kwargs)
4446
self.task_id = None
45-
47+
4648
def send_message(
4749
self,
4850
query: str,
@@ -53,7 +55,7 @@ def send_message(
5355
files: List[Dict[str, Any]] = None,
5456
auto_generate_name: bool = True,
5557
**kwargs, # 添加kwargs参数,用于接收额外的请求参数
56-
) -> Generator[Dict[str, Any], None, None] | Dict[str, Any]:
58+
) -> Union[Generator[Dict[str, Any], None, None], Dict[str, Any]]:
5759
"""
5860
发送对话消息,创建会话消息。在Agent模式下,只支持streaming流式模式。
5961
@@ -76,7 +78,7 @@ def send_message(
7678
"""
7779
if response_mode != "streaming":
7880
raise ValueError("Agent mode only supports streaming response mode")
79-
81+
8082
payload = {
8183
"query": query,
8284
"user": user,
@@ -116,7 +118,7 @@ def stop_task(self, task_id: str, user: str) -> Dict[str, Any]:
116118
endpoint = f"chat-messages/{task_id}/stop"
117119
payload = {"user": user}
118120
return self.post(endpoint, json_data=payload)
119-
121+
120122
def get_meta(self) -> Dict[str, Any]:
121123
"""
122124
获取应用Meta信息,用于获取工具icon等。
@@ -128,4 +130,3 @@ def get_meta(self) -> Dict[str, Any]:
128130
requests.HTTPError: 当API请求失败时
129131
"""
130132
return self.get("meta")
131-

pydify/chatbot.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from .common import DifyBaseClient, DifyType
1313

14+
1415
class ChatbotEvent:
1516
"""事件类型枚举
1617
@@ -98,7 +99,7 @@ class ChatbotEvent:
9899
"event": "ping",
99100
}
100101
"""
101-
102+
102103
MESSAGE = "message" # LLM返回文本块事件
103104
AGENT_MESSAGE = "agent_message" # Agent模式下返回文本块事件
104105
AGENT_THOUGHT = "agent_thought" # Agent思考步骤相关内容
@@ -109,7 +110,6 @@ class ChatbotEvent:
109110
MESSAGE_REPLACE = "message_replace" # 消息内容替换事件
110111
ERROR = "error" # 异常事件
111112
PING = "ping" # 保持连接存活的ping事件
112-
113113

114114

115115
class ChatbotClient(DifyBaseClient):
@@ -172,18 +172,18 @@ def send_message(
172172

173173
if files:
174174
payload["files"] = files
175-
175+
176176
endpoint = "chat-messages"
177-
177+
178178
# 打印请求信息,便于调试
179179
print(f"请求URL: {self.base_url}{endpoint}")
180180
print(f"请求参数: {json.dumps(payload)}")
181-
181+
182182
if response_mode == "streaming":
183183
return self.post_stream(endpoint, json_data=payload, **kwargs)
184184
else:
185185
return self.post(endpoint, json_data=payload, **kwargs)
186-
186+
187187
def stop_task(self, task_id: str, user: str) -> Dict[str, Any]:
188188
"""
189189
停止正在进行的响应,仅支持流式模式。
@@ -282,11 +282,13 @@ def audio_to_text_obj(self, file_obj, filename: str, user: str) -> Dict[str, Any
282282
"POST", endpoint, headers=headers, files=files, data=data
283283
)
284284
return response.json()
285-
286-
def get_messages(self, conversation_id: str, user: str, first_id: str = None, limit: int = 20) -> Dict[str, Any]:
285+
286+
def get_messages(
287+
self, conversation_id: str, user: str, first_id: str = None, limit: int = 20
288+
) -> Dict[str, Any]:
287289
"""
288290
获取会话消息列表,支持分页加载历史聊天记录。
289-
291+
290292
Args:
291293
conversation_id (str): 会话ID,用于标识特定的对话会话
292294
user (str): 用户标识,由开发者定义规则,需保证用户标识在应用内唯一
@@ -335,7 +337,7 @@ def get_messages(self, conversation_id: str, user: str, first_id: str = None, li
335337
DifyAPIError: 当API请求失败时
336338
"""
337339
endpoint = "messages"
338-
340+
339341
params = {
340342
"conversation_id": conversation_id,
341343
"user": user,
@@ -345,4 +347,4 @@ def get_messages(self, conversation_id: str, user: str, first_id: str = None, li
345347
if first_id:
346348
params["first_id"] = first_id
347349

348-
return self.get(endpoint, params=params)
350+
return self.get(endpoint, params=params)

pydify/chatflow.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import mimetypes
1010
import os
1111
from typing import Any, BinaryIO, Dict, Generator, List, Optional, Tuple, Union
12-
from .common import DifyBaseClient, DifyType
12+
1313
from .chatbot import ChatbotClient
14+
from .common import DifyBaseClient, DifyType
15+
1416

1517
class ChatflowEvent:
1618
"""事件类型枚举
@@ -30,7 +32,6 @@ class ChatflowEvent:
3032
WORKFLOW_FINISHED = "workflow_finished" # workflow执行结束事件(包含成功/失败状态)
3133
ERROR = "error" # 流式输出过程中出现的异常事件
3234
PING = "ping" # 保持连接存活的ping事件,每10秒一次
33-
3435

3536

3637
class ChatflowClient(ChatbotClient):
@@ -118,7 +119,7 @@ def stop_task(self, task_id: str, user: str) -> Dict[str, Any]:
118119
endpoint = f"chat-messages/{task_id}/stop"
119120
payload = {"user": user}
120121
return self.post(endpoint, json_data=payload)
121-
122+
122123
def get_suggested_questions(
123124
self, message_id: str, user: str, **kwargs
124125
) -> Dict[str, Any]:
@@ -132,7 +133,7 @@ def get_suggested_questions(
132133
133134
Returns:
134135
Dict[str, Any]: 建议问题列表
135-
136+
136137
Raises:
137138
DifyAPIError: 当API请求失败时
138139
"""
@@ -419,4 +420,3 @@ def get_meta(self) -> Dict[str, Any]:
419420
requests.HTTPError: 当API请求失败时
420421
"""
421422
return self.get("meta")
422-

0 commit comments

Comments
 (0)