Skip to content

Commit 94e3b90

Browse files
committed
feat(workflow): support message format
1 parent e14b9ad commit 94e3b90

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

dashscope/app/application_response.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
from dataclasses import dataclass
88
from http import HTTPStatus
9-
from typing import Dict, List
9+
from typing import Dict, List, Optional
1010

1111
from dashscope.api_entities.dashscope_response import (DashScopeAPIResponse,
1212
DictMixin)
@@ -105,6 +105,50 @@ def __init__(self,
105105
page_number=page_number,
106106
**kwargs)
107107

108+
@dataclass(init=False)
109+
class WorkflowMessage(DictMixin):
110+
node_id: str
111+
node_name: str
112+
node_type: str
113+
node_status: str
114+
node_is_completed: str
115+
node_msg_seq_id: int
116+
message: str
117+
118+
class Message(DictMixin):
119+
role: str
120+
content: str
121+
122+
def __init__(self,
123+
node_id: str = None,
124+
node_name: str = None,
125+
node_type: str = None,
126+
node_status: str = None,
127+
node_is_completed: str = None,
128+
node_msg_seq_id: int = None,
129+
message: Message = None,
130+
**kwargs):
131+
""" Workflow message.
132+
133+
Args:
134+
node_id (str, optional): .
135+
node_name (str, optional): .
136+
node_type (str, optional): .
137+
node_status (str, optional): .
138+
node_is_completed (str, optional): .
139+
node_msg_seq_id (int, optional): .
140+
message (Message, optional): .
141+
"""
142+
143+
super().__init__(node_id=node_id,
144+
node_name=node_name,
145+
node_type=node_type,
146+
node_status=node_status,
147+
node_is_completed=node_is_completed,
148+
node_msg_seq_id=node_msg_seq_id,
149+
message=message,
150+
**kwargs)
151+
108152

109153
@dataclass(init=False)
110154
class ApplicationOutput(DictMixin):
@@ -113,13 +157,15 @@ class ApplicationOutput(DictMixin):
113157
session_id: str
114158
thoughts: List[ApplicationThought]
115159
doc_references: List[ApplicationDocReference]
160+
workflow_message: WorkflowMessage
116161

117162
def __init__(self,
118163
text: str = None,
119164
finish_reason: str = None,
120165
session_id: str = None,
121166
thoughts: List[ApplicationThought] = None,
122167
doc_references: List[ApplicationDocReference] = None,
168+
workflow_message: WorkflowMessage = None,
123169
**kwargs):
124170

125171
ths = None
@@ -139,6 +185,7 @@ def __init__(self,
139185
session_id=session_id,
140186
thoughts=ths,
141187
doc_references=refs,
188+
workflow_message=workflow_message,
142189
**kwargs)
143190

144191

samples/test_application.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
from http import HTTPStatus
3+
from dashscope import Application
4+
responses = Application.call(
5+
api_key=os.getenv("DASHSCOPE_API_KEY"),
6+
app_id=os.getenv("DASHSCOPE_APP_ID"),
7+
prompt='你是谁?',
8+
stream=True, # 流式输出
9+
has_thoughts=True, # 输出节点内容
10+
incremental_output=True,
11+
flow_stream_mode='agent_format') # 设置为Agent模式,透出指定节点的输出
12+
13+
for response in responses:
14+
if response.status_code != HTTPStatus.OK:
15+
print(f'request_id={response.request_id}')
16+
print(f'code={response.status_code}')
17+
print(f'message={response.message}')
18+
print(f'请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code')
19+
else:
20+
print(f'response: {response}\n')

0 commit comments

Comments
 (0)