Runs 表示智能體在一個線程上執行的運行。
建立運行任務
建立一個運行。
HTTP
非流式
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"metadata": {}
}'流式
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"metadata": {},
"stream": true
}'
輸入參數
輸入參數名字 | 輸入參數的描述 | 參數類型 | 是否必須 |
thread id | 所需要啟動並執行thread id | string | 是 |
assistant id | 所需要啟動並執行assistant id | string | 是 |
model | 所需要調用的model名字。如果在此傳入,會替換掉assistant中定義的model | string | 否 |
instructions | 替換assistant中定義的instruction | string | 否 |
tools | 替換assistant中定義的tool 列表, 說明 自訂tool鑒權資訊傳遞 { "type": "plugin_type", "auth": {"type": "user_http","user_token": "bearer-token", } } assistant在請求外掛程式時會將bearer放在{"plugin_type":{"user_token": "bearer-token"}}'添加到調用plugin的header裡. | string | 否 |
metadata | 其他相關參數說明 | string | 否 |
stream | 是否流式返回 | boolean | 否 |
temperature | 用於控制隨機性和多樣性的程度。 | float | 否 |
top_p | 產生時,核採樣方法的機率閾值。 | float | 否 |
top_k | 產生時,採樣候選集的大小。 | integer | 否 |
返回結果
非流式
{
"id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"object": "thread.run",
"created_at": 1711517598169,
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"status": "in_progress",
"model": "qwen-max",
"instructions": "你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。",
"tools": [
{
"type": "search"
},
{
"type": "text_to_image"
}
],
"metadata": {},
"request_id": "225292ff-9843-95d4-8591-b1377c33e2be"
}流式
event:thread.created
data:{"id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","object":"thread","created_at":1714448101977,"metadata":{},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.created
data:{"id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","object":"thread.run","created_at":1714448101996,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"queued","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.queued
data:{"id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","object":"thread.run","created_at":1714448101996,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"queued","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.in_progress
data:{"id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","object":"thread.run","created_at":1714448101996,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"in_progress","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.step.created
data:{"id":"step_52c42910-4993-496d-a7f3-ecd4cf007839","object":"thread.run.step","created_at":1714448102574,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_f4f68f6b-6003-4115-8f20-3ea590137502"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.step.in_progress
data:{"id":"step_52c42910-4993-496d-a7f3-ecd4cf007839","object":"thread.run.step","created_at":1714448102574,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_f4f68f6b-6003-4115-8f20-3ea590137502"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.created
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message","created_at":1714448102574,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","file_ids":[],"metadata":{},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.in_progress
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message","created_at":1714448102574,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","file_ids":[],"metadata":{},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"9","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"9","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"9","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"乘以998","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"等於997002。","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.delta
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"","annotations":[]}}],"file_ids":[]},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.message.completed
data:{"id":"message_f4f68f6b-6003-4115-8f20-3ea590137502","object":"thread.message","created_at":1714448102574,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","incomplete_details":null,"completed_at":1714448104154,"incomplete_at":null,"role":"assistant","content":[{"type":"text","text":{"value":"999乘以998等於997002。","annotations":[]}}],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","file_ids":[],"metadata":{},"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.step.completed
data:{"id":"step_52c42910-4993-496d-a7f3-ecd4cf007839","object":"thread.run.step","created_at":1714448102574,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","run_id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","type":"message_creation","status":"completed","step_details":{"type":"message_creation","message_creation":{"message_id":"message_f4f68f6b-6003-4115-8f20-3ea590137502"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1714448104154,"metadata":{},"usage":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:thread.run.completed
data:{"id":"run_04fba6a3-3ac9-42e8-ba2b-9b5c889a8d58","object":"thread.run","created_at":1714448101996,"thread_id":"thread_5b7824dc-dbf9-4538-b214-624ee199caa4","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"completed","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":{"input_tokens":419,"output_tokens":16,"total_tokens":435},"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"f38314af-21c4-945e-acdc-cb9765d1d48f"}
event:done
data:[DONE]輸出參數
一個運行對象。
SDK
流式
import dashscope
import os
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
stream_iterator = dashscope.Runs.create(
'thread_id', # 請替換為實際的 thread_id
# 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
assistant_id='assistant_id', # 請替換為實際的 assistant_id
stream=True
)
for event, msg in stream_iterator:
print(event)
print(msg)import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.AssistantStreamMessage;
import com.alibaba.dashscope.threads.runs.RunParam;
import com.alibaba.dashscope.threads.runs.Runs;
import io.reactivex.Flowable;
import com.alibaba.dashscope.utils.Constants;
public class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
// 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey("sk-xxx")
RunParam runParam = RunParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.assistantId("assistantId")
.stream(true)
.build();
Flowable<AssistantStreamMessage> run = runs.createStream("threadId", runParam);
}
}輸入參數
參數 | 類型 | 預設值 | 說明 |
thread_id | string | - | 期望在那個Thread run |
assistant_id | string | - | assistant id |
model | string | - | 指定使用的模型 |
instructions | string | None | 指定本次run所用的指令 |
tools | List[Dict] | [] | assistant使用的tools 說明 自訂tool鑒權資訊傳遞 { "type": "plugin_type", "auth": {"type": "user_http","user_token": "bearer-token", } } assistant在請求外掛程式時會將bearer放在{"plugin_type":{"user_token": "bearer-token"}}'添加到調用plugin的header裡. |
stream | boolean | False | 用於控制是否是流式輸出。 |
metadata | Dict | None | assistant關聯資訊 |
temperature | 用於控制隨機性和多樣性的程度。 | float | 否 |
top_p | 產生時,核採樣方法的機率閾值。 | float | 否 |
top_k | 產生時,採樣候選集的大小。 | integer | 否 |
metadata | 其他相關參數說明 | string | 否 |
truncation_strategy | Dict | None | 設定thread中訊息截斷策略, 目前只支援last_messages,預設為: "truncation_strategy": { "type": "last_messages", "last_messages": 10 } |
workspace | string | None | 阿里雲百鍊的Workspace ID,僅當 api_key 為子業務空間 API Key 時才需要傳入。 |
api_key | string | None | 阿里雲百鍊的API Key,建議您配置API Key到環境變數(準備下線,併入配置 API Key)。 |
返回結果
流式輸出將輸出event和event 資料,如下
thread.run.created
{'tools': [{'type': 'quark_search'}], 'required_action': None, 'id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'object': 'thread.run', 'created_at': 1714460227904, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'status': 'queued', 'last_error': None, 'expires_at': None, 'started_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'model': 'qwen-max', 'instructions': 'You are a helpful assistant. When asked a question, use tools wherever possible.', 'file_ids': [], 'metadata': {}, 'usage': None, 'temperature': None, 'top_p': None, 'top_k': None, 'max_tokens': None, 'truncation_strategy': None, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.queued
{'tools': [{'type': 'quark_search'}], 'required_action': None, 'id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'object': 'thread.run', 'created_at': 1714460227904, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'status': 'queued', 'last_error': None, 'expires_at': None, 'started_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'model': 'qwen-max', 'instructions': 'You are a helpful assistant. When asked a question, use tools wherever possible.', 'file_ids': [], 'metadata': {}, 'usage': None, 'temperature': None, 'top_p': None, 'top_k': None, 'max_tokens': None, 'truncation_strategy': None, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.in_progress
{'tools': [{'type': 'quark_search'}], 'required_action': None, 'id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'object': 'thread.run', 'created_at': 1714460227904, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'status': 'in_progress', 'last_error': None, 'expires_at': None, 'started_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'model': 'qwen-max', 'instructions': 'You are a helpful assistant. When asked a question, use tools wherever possible.', 'file_ids': [], 'metadata': {}, 'usage': None, 'temperature': None, 'top_p': None, 'top_k': None, 'max_tokens': None, 'truncation_strategy': None, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.created
{'step_details': {'tool_calls': [], 'type': 'tool_calls'}, 'usage': None, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step', 'created_at': 1714460228960, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'tool_calls', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.step.in_progress
{'step_details': {'tool_calls': [], 'type': 'tool_calls'}, 'usage': None, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step', 'created_at': 1714460228960, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'tool_calls', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': '{"query": "'}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': '今天 北京 天氣"}'}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'quark_search': {'arguments': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'type': 'quark_search', 'plugin_name': {'output': '{"success": true, "errorCode": null, "errorMsg": null, "data": [{"title": "中國北京市天氣情況", "url": null, "desc": "即時天氣情況,晴,氣溫24度,體感溫度:23度,西風1級,冷熱適宜,感覺很舒適。查看未來15天氣預報,請點擊這裡", "type": "weather_moji", "original": null, "query": null, "source": null}, {"title": "北京市氣象局", "url": "http://bj.cma.gov.cn/fzlm/index.html", "desc": "36小時天氣預報(2024-01-25 05:24:58北京市氣象台發布) 今天白天 最高氣溫5℃ 晴間多雲 3級,陣風5級轉2級 偏北風 今天夜間 最低氣溫-5℃ 晴 2級轉3級 偏北風 明天白天 最高氣溫5℃ 晴 3級轉1...", "type": "structure_web_info", "original": null, "query": null, "source": "北京市氣象局"}, {"title": "北京", "url": "https://m.weather.com.cn/mweather/101010100.shtml?_t=1480291523052", "desc": "北京天氣預報,及時準確發布中央氣象台天氣資訊,便捷查詢北京今日天氣,北京周末天氣,北京一周天氣預報,北京藍天預報,北京天氣預報,北京40日天氣預報,還提供北京的生活指數、健康指數、...", "type": "normal", "original": null, "query": null, "source": "中國天氣"}, {"title": "墨跡天氣中文官方網站", "url": "https://m.moji.com/", "desc": "墨跡天氣預報app,全球約6.5億人在使用的天氣app,支援199個國家20多萬個城市及地區的天氣預報查詢,下載墨跡天氣預報app,即時監測陰晴雨雪,即時空氣品質及空氣品質等級預報。", "type": "structure_web_info", "original": null, "query": null, "source": "墨跡天氣手機版"}, {"title": "北京", "url": "http://sq.weather.com.cn/mweather15d/101010100.shtml?from=singlemessage", "desc": "北京天氣預報,及時準確發布中央氣象台天氣資訊,便捷查詢北京今日天氣,北京周末天氣,北京一周天氣預報,北京藍天預報,北京天氣預報,北京40日天氣預報,還提供北京的生活指數、健康指數、...", "type": "structure_web_info", "original": null, "query": null, "source": "中國天氣網"}, {"title": "頭條新聞", "url": null, "desc": "中國天氣網於1天前報道:預報 預警 雷達 雲圖 天氣地圖 專業產品 資訊 視頻 節氣 我的天空 ...恭王府 北京奧林匹克公園 奧林匹克森林公園 北京石景山遊樂園 金海湖 京東大溶洞旅遊區 明十三陵 銀山塔林風景區 中國航空博物館 北京歡樂穀 北京中華...", "type": "news_uchq", "original": null, "query": null, "source": null}, {"title": "北京", "url": "http://www.weather.com.cn/weather1d/101010100.shtml", "desc": "北京天氣預報,及時準確發布中央氣象台天氣資訊,便捷查詢北京今日天氣,北京周末天氣,北京一周天氣預報,北京15日...", "type": "structure_web_info", "original": null, "query": null, "source": "中國天氣網"}, {"title": "北京24小時天氣查詢_北京今日天氣預報查詢_2345天氣王", "url": "http://waptianqi.2345.com/24hour-54511.htm", "desc": "2345天氣預報為你及時提供最新的北京天氣,今天24小時天氣情況等資訊,同時還提供當日北京氣象指數等資訊", "type": "structure_web_info", "original": null, "query": null, "source": "2345天氣王"}, {"title": "北京15日天氣詳情", "url": "http://waptianqi.2345.com/beijing-54511.htm", "desc": "2345天氣預報提供北京天氣預報,未來北京15日天氣,通過2345天氣預報詳細瞭解北京天氣預報以及北京周邊各地區未來15天、30日天氣情況,溫度,空氣品質,降水,風力,氣壓,紫外線強度等!", "type": "structure_web_info", "original": null, "query": null, "source": "2345天氣王"}, {"title": "北京天氣預報15天", "url": "https://m.tianqi.com/beijing/15/", "desc": "北京天氣預報15天詳情 12/11 今天 小雪-2~2 ℃ 12/12 明天 多雲轉小雪-2~2 ℃ 12/13 後天 小雪-5~0 ℃ 12/14 周四 小雪-5~-1 ℃ 12/15 周五 陰轉多雲-10~-2 ℃ 12/16 周六 晴-10~-3 ℃ 12/17 ...", "type": "structure_web_info", "original": null, "query": null, "source": "天氣網"}, {"title": "北京天氣", "url": "https://t.8684.com/beijing_beijing", "desc": "北京天氣預報一周15天,北京天氣預報,北京天氣預報一周,北京天氣預報15天,北京本周天氣預報,北京下周天氣預報,北京天氣預報15天查詢,北京天氣預報10天", "type": "structure_web_info", "original": null, "query": null, "source": "8684天氣"}], "requestId": null, "failed": false}'}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'quark_search': {'output': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.delta
{'delta': {'step_details': {'tool_calls': [{'quark_search': {'output': ''}}], 'type': 'tool_calls'}}, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.completed
{'step_details': {'tool_calls': [{'type': 'quark_search', 'plugin_name': {'arguments': '{"query": "今天 北京 天氣"}', 'output': '{"success": true, "errorCode": null, "errorMsg": null, "data": [{"title": "中國北京市天氣情況", "url": null, "desc": "即時天氣情況,晴,氣溫24度,體感溫度:23度,西風1級,冷熱適宜,感覺很舒適。查看未來15日天氣預報,請點擊這裡", "type": "weather_moji", "original": null, "query": null, "source": null}, {"title": "北京市氣象局", "url": "http://bj.cma.gov.cn/fzlm/index.html", "desc": "36小時天氣預報(2024-01-25 05:24:58北京市氣象台發布) 今天白天 最高氣溫5℃ 晴間多雲 3級,陣風5級轉2級 偏北風 今天夜間 最低氣溫-5℃ 晴 2級轉3級 偏北風 明天白天 最高氣溫5℃ 晴 3級轉1...", "type": "structure_web_info", "original": null, "query": null, "source": "北京市氣象局"}, {"title": "北京", "url": "https://m.weather.com.cn/mweather/101010100.shtml?_t=1480291523052", "desc": "北京天氣預報,及時準確發布中央氣象台天氣資訊,便捷查詢北京今日天氣,北京周末天氣,北京一周天氣預報,北京藍天預報,北京天氣預報,北京40日天氣預報,還提供北京的生活指數、健康指數、...", "type": "normal", "original": null, "query": null, "source": "中國天氣"}, {"title": "墨跡天氣中文官方網站", "url": "https://m.moji.com/", "desc": "墨跡天氣預報app,全球約6.5億人在使用的天氣app,支援199個國家20多萬個城市及地區的天氣預報查詢,下載墨跡天氣預報app,即時監測陰晴雨雪,即時空氣品質及空氣品質等級預報。", "type": "structure_web_info", "original": null, "query": null, "source": "墨跡天氣手機版"}, {"title": "北京", "url": "http://sq.weather.com.cn/mweather15d/101010100.shtml?from=singlemessage", "desc": "北京天氣預報,及時準確發布中央氣象台天氣資訊,便捷查詢北京今日天氣,北京周末天氣,北京一周天氣預報,北京藍天預報,北京天氣預報,北京40日天氣預報,還提供北京的生活指數、健康指數、...", "type": "structure_web_info", "original": null, "query": null, "source": "中國天氣網"}, {"title": "頭條新聞", "url": null, "desc": "中國天氣網於1天前報道:預報 預警 雷達 雲圖 天氣地圖 專業產品 資訊 視頻 節氣 我的天空 ...恭王府 北京奧林匹克公園 奧林匹克森林公園 北京石景山遊樂園 金海湖 京東大溶洞旅遊區 明十三陵 銀山塔林風景區 中國航空博物館 北京歡樂穀 北京中華...", "type": "news_uchq", "original": null, "query": null, "source": null}, {"title": "北京", "url": "http://www.weather.com.cn/weather1d/101010100.shtml", "desc": "北京天氣預報,及時準確發布中央氣象台天氣資訊,便捷查詢北京今日天氣,北京周末天氣,北京一周天氣預報,北京15日...", "type": "structure_web_info", "original": null, "query": null, "source": "中國天氣網"}, {"title": "北京24小時天氣查詢_北京今日天氣預報查詢_2345天氣王", "url": "http://waptianqi.2345.com/24hour-54511.htm", "desc": "2345天氣預報為你及時提供最新的北京今天天氣,今天24小時天氣情況等資訊,同時還提供當日北京氣象指數等資訊", "type": "structure_web_info", "original": null, "query": null, "source": "2345天氣王"}, {"title": "北京15日天氣詳情", "url": "http://waptianqi.2345.com/beijing-54511.htm", "desc": "2345天氣預報提供北京天氣預報,未來北京15日天氣,通過2345天氣預報詳細瞭解北京天氣預報以及北京周邊各地區未來15天、30日天氣情況,溫度,空氣品質,降水,風力,氣壓,紫外線強度等!", "type": "structure_web_info", "original": null, "query": null, "source": "2345天氣王"}, {"title": "北京天氣預報15天", "url": "https://m.tianqi.com/beijing/15/", "desc": "北京天氣預報15天詳情 12/11 今天 小雪-2~2 ℃ 12/12 明天 多雲轉小雪-2~2 ℃ 12/13 後天 小雪-5~0 ℃ 12/14 周四 小雪-5~-1 ℃ 12/15 周五 陰轉多雲-10~-2 ℃ 12/16 周六 晴-10~-3 ℃ 12/17 ...", "type": "structure_web_info", "original": null, "query": null, "source": "天氣網"}, {"title": "北京天氣", "url": "https://t.8684.com/beijing_beijing", "desc": "北京天氣預報一周15天,北京天氣預報,北京天氣預報一周,北京天氣預報15天,北京本周天氣預報,北京下周天氣預報,北京天氣預報15天查詢,北京天氣預報10天", "type": "structure_web_info", "original": null, "query": null, "source": "8684天氣"}], "requestId": null, "failed": false}'}}], 'type': 'tool_calls'}, 'usage': None, 'id': 'step_f923bd08-1e22-40d9-bf54-373b21fde378', 'object': 'thread.run.step', 'created_at': 1714460228960, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'tool_calls', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.step.created
{'step_details': {'message_creation': {'message_id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d'}, 'type': 'message_creation'}, 'usage': None, 'id': 'step_89e631c7-491a-4bff-b1f5-1298f88db531', 'object': 'thread.run.step', 'created_at': 1714460234236, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'message_creation', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.step.in_progress
{'step_details': {'message_creation': {'message_id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d'}, 'type': 'message_creation'}, 'usage': None, 'id': 'step_89e631c7-491a-4bff-b1f5-1298f88db531', 'object': 'thread.run.step', 'created_at': 1714460234236, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'message_creation', 'status': 'in_progress', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.message.created
{'content': [], 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message', 'created_at': 1714460234235, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'incomplete_details': None, 'completed_at': None, 'incomplete_at': None, 'role': 'assistant', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'file_ids': [], 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.in_progress
{'content': [], 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message', 'created_at': 1714460234235, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'incomplete_details': None, 'completed_at': None, 'incomplete_at': None, 'role': 'assistant', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'file_ids': [], 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '今天'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '北京的天氣情況是'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '晴朗的,氣溫約為24'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '度,體感溫度為23'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '度,西風1級,天氣'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '較為舒適。不過,我也找到了北京市'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '氣象局發布的更詳細資料,提到'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '今天白天最高氣溫為5℃,'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '天氣晴間多雲,有3'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '級偏北風,陣風可達'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '5級,夜間最低氣溫降至-'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '5℃,依舊保持晴朗,'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '風向轉為偏北風,'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '風力2級轉3級。'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '請根據即時天氣調整著裝,'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': '注意保暖。'}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.delta
{'delta': {'content': {'text': {'annotations': [], 'value': ''}, 'type': 'text'}, 'role': 'assistant'}, 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message.delta', 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.message.completed
{'content': [{'text': {'annotations': [], 'value': '今天北京的天氣情況是晴朗的,氣溫約為24度,體感溫度為23度,西風1級,天氣較為舒適。不過,我也找到了北京市氣象局發布的更詳細資料,提到今天白天最高氣溫為5℃,天氣晴間多雲,有3級偏北風,陣風可達5級,夜間最低氣溫降至-5℃,依舊保持晴朗,風向轉為偏北風,風力2級轉3級。請根據即時天氣調整著裝,注意保暖。'}, 'type': 'text'}], 'id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d', 'object': 'thread.message', 'created_at': 1714460234235, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'incomplete_details': None, 'completed_at': 1714460245637, 'incomplete_at': None, 'role': 'assistant', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'file_ids': [], 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}
thread.run.step.completed
{'step_details': {'message_creation': {'message_id': 'message_93605cd7-fb74-468b-b6fb-4975cd253f8d'}, 'type': 'message_creation'}, 'usage': None, 'id': 'step_89e631c7-491a-4bff-b1f5-1298f88db531', 'object': 'thread.run.step', 'created_at': 1714460234236, 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'run_id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'type': 'message_creation', 'status': 'completed', 'expired_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': 1714460245637, 'metadata': {}, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200, 'last_error': None}
thread.run.completed
{'tools': [{'type': 'quark_search'}], 'required_action': None, 'id': 'run_0f314675-06a4-4379-929c-d29cd351a446', 'object': 'thread.run', 'created_at': 1714460227904, 'thread_id': 'thread_28f0b00b-d825-48f5-bb27-f3b171a64d33', 'assistant_id': 'asst_9453fe59-d6eb-498e-aeca-9abecd492e51', 'status': 'completed', 'last_error': None, 'expires_at': None, 'started_at': None, 'cancelled_at': None, 'failed_at': None, 'completed_at': None, 'model': 'qwen-max', 'instructions': 'You are a helpful assistant. When asked a question, use tools wherever possible.', 'file_ids': [], 'metadata': {}, 'usage': {'input_tokens': 1865, 'output_tokens': 139, 'total_tokens': 2004}, 'temperature': None, 'top_p': None, 'top_k': None, 'max_tokens': None, 'truncation_strategy': None, 'request_id': '38fb88b8-196a-9919-8815-f7ed9aa0891f', 'status_code': 200}輸出參數
欄位名 | 欄位類型 | 欄位描述 |
status_code | integer | 為調用http status code,200表示調用成功,其他表示調用出錯 |
id | string | Run id,為uuid字串 |
model | string | Run 使用的模型名稱 |
instructions | string | assistant instruction資訊,指定assisiant功能資訊。 |
metadata | object | key,value對資訊,描述assistant資訊 |
status | string | Run的狀態,包含'in_progress, 等 |
thread_id | string | Run所屬Thread id |
tools | List[Tool] | Run使用的tool列表 |
created_at | timestamp | assistant建立時間 |
gmt_created | datetime | 2024-03-22 17:12:31 |
gmt_modified | datetime | 2024-03-22 17:12:31 |
code | string | 表示請求失敗,表示錯誤碼,成功忽略。 python only |
message | string | 失敗,表示失敗詳細資料,成功忽略。 python only |
列出運行任務
返回屬於線程的運行列表。
HTTP
程式碼範例
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs?limit=20&order=asc' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"輸入參數
輸入參數名字 | 輸入參數的描述 | 參數類型 | 是否必須 |
thread id | run list 所隸屬的thread id | string | 是 |
limit | 本次查詢的任務數 | integer | 否 |
order | 按照建立時間升序或降序排列 | string | 否(預設為“desc“) |
返回結果
{
"object": "list",
"data": [
{
"id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"object": "thread.run",
"created_at": 1711517598169,
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"status": "completed",
"required_action": {},
"last_error": {},
"expires_at": 0,
"started_at": 0,
"cancelled_at": 0,
"failed_at": 0,
"completed_at": 0,
"model": "qwen-max",
"instructions": "你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。",
"tools": [
{
"type": "search"
},
{
"type": "text_to_image"
}
],
"metadata": {},
"usage": {
"input_tokens": 66,
"output_tokens": 9,
"total_tokens": 75
}
}
],
"first_id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"last_id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"has_more": false,
"request_id": "ff3d2aea-555c-9825-80ca-24029a636641"
}輸出參數
一個運行對象列表。
SDK
程式碼範例
import dashscope
from dashscope import Runs
import os
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
runs = Runs.list(
'thread_id',
# 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
limit=1,
order='desc'
)
import com.alibaba.dashscope.common.GeneralListParam;
import com.alibaba.dashscope.common.ListResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.Run;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;
public class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
// 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey("sk-xxx")
GeneralListParam listRuns = GeneralListParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.build();
ListResult<Run> run = runs.list("threadId", listRuns);
}
}輸入參數
參數 | 類型 | 預設值 | 說明 |
thread_id | str | - | 指定要list的Thread id |
limit | int | None | 本次查詢的任務數 |
order | str | None | 按照建立時間升序或降序排列,預設值根據伺服器配置確定
|
workspace | str | None | 阿里雲百鍊的Workspace ID,僅當 api_key 為子業務空間 API Key 時才需要傳入。 |
api_key | str | None | 阿里雲百鍊的API Key,建議您配置API Key到環境變數(準備下線,併入配置 API Key)。 |
輸出參數
欄位名 | 欄位類型 | 欄位描述 |
has_more | bool | 是否有更多的資料可供擷取
|
last_id | str | 返回結果中的最後一個任務ID |
first_id | str | 返回結果中的第一個任務ID |
data | list[Run] | Run對象列表 |
檢索運行任務
檢索運行。
HTTP
程式碼範例
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs/run_3de634fa-75d4-4370-adcf-92ba2a60c396' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"輸入參數
輸入參數名字 | 輸入參數的描述 | 參數類型 | 是否必須 |
thread id | 待檢索的run id 所傳入的thread id | string | 是 |
run_id | 待檢索的run_id | string | 是 |
返回結果
{
"id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"object": "thread.run",
"created_at": 1711517598169,
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"status": "completed",
"required_action": {},
"last_error": {},
"expires_at": 0,
"started_at": 0,
"cancelled_at": 0,
"failed_at": 0,
"completed_at": 0,
"model": "qwen-max",
"instructions": "你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。",
"tools": [
{
"type": "search"
},
{
"type": "text_to_image"
}
],
"metadata": {},
"usage": {
"input_tokens": 66,
"output_tokens": 9,
"total_tokens": 75
},
"request_id": "05c5f4ea-5e6b-9901-9849-7a0943a0db43"
}輸出參數
與指定 ID 匹配的修改後的運行對象。
SDK
程式碼範例
import dashscope
from dashscope import Runs
import os
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'import os
run = Runs.retrieve(
'run_id',
# 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
thread_id='thread_id'
)
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.Run;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;
public class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
// 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey("sk-xxx")
String apiKey = System.getenv("DASHSCOPE_API_KEY");
Run run = runs.retrieve("threadId", "runId", apiKey);
}
}輸入參數
參數 | 類型 | 預設值 | 說明 |
run_id | str | - | 指定要查詢的Run id |
thread_id | str | - | 指定Run所屬Thread id |
workspace | str | None | 阿里雲百鍊的Workspace ID,僅當 api_key 為子業務空間 API Key 時才需要傳入。 |
api_key | str | None | 阿里雲百鍊的API Key,建議您配置API Key到環境變數(準備下線,併入配置 API Key)。 |
輸出參數
參考create結果
修改運行任務
修改運行。
HTTP
程式碼範例
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_cc2a3e9d-436b-482b-91c5-377e0f376506/runs/run_3de634fa-75d4-4370-adcf-92ba2a60c396' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"metadata": {
"user": "abc123"
}
}'輸入參數
輸入參數名字 | 輸入參數的描述 | 參數類型 | 是否必須 |
thread_id | 待修改的thread_id | string | 是 |
run_id | 待修改的run_id | string | 是 |
* | 其他可選的輸入參數 | string | 否 |
返回結果
{
"id": "run_3de634fa-75d4-4370-adcf-92ba2a60c396",
"object": "thread.run",
"created_at": 1711517598169,
"thread_id": "thread_cc2a3e9d-436b-482b-91c5-377e0f376506",
"assistant_id": "asst_46e95014-ccac-435d-b884-c97ac44a94d9",
"status": "completed",
"required_action": {},
"last_error": {},
"expires_at": 0,
"started_at": 0,
"cancelled_at": 0,
"failed_at": 0,
"completed_at": 0,
"model": "qwen-max",
"instructions": "你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。",
"tools": [
{
"type": "search"
},
{
"type": "text_to_image"
}
],
"metadata": {
"user": "abc123"
},
"usage": {
"input_tokens": 66,
"output_tokens": 9,
"total_tokens": 75
},
"request_id": "bb6a5c5c-146f-95b8-bafa-e6c467e4f2d3"
}輸出參數
與指定 ID 匹配的修改後的運行對象。
SDK
程式碼範例
import dashscope
from dashscope import Runs
import os
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
run = Runs.update(
'run_id',
# 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
thread_id='thread_id',
metadata={'newkey': 'newvalue'}
)
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dashscope.common.UpdateMetadataParam;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.Run;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;
public class Main {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
Map<String, String> metadata = new HashMap<>();
metadata.put("key", "value");
// 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey("sk-xxx")
UpdateMetadataParam updateParam = UpdateMetadataParam.builder()
.metadata(metadata)
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.build();
Run run = runs.update("threadId", "runId", updateParam);
}
}
輸入參數
參數 | 類型 | 預設值 | 說明 |
run_id | str | - | 要更新的Run id |
thread_id | str | - | Run所屬的Thread id |
metadata | Dict | None | assistant關聯資訊 |
workspace | str | None | 阿里雲百鍊的Workspace ID,僅當 api_key 為子業務空間 API Key 時才需要傳入。 |
api_key | str | None | 阿里雲百鍊的API Key,建議您配置API Key到環境變數(準備下線,併入配置 API Key)。 |
輸出參數
同create,參考create
提交工具輸出並繼續執行任務
當運行具有status: "requires_action"且required_action.type是submit_tool_outputs時,可以使用此端點在所有工具調用完成後提交工具輸出。所有輸出必須在單個請求中提交。
HTTP
程式碼範例
在使用Function call過程中,需要把中間function運行結果返回給run,並將run的狀態從“require_action" 切換回正常狀態。此時,“required_action.type” 的值為“submit_tool_outputs”。
非流式
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_9157dfad-71fd-4add-b7a9-1afa452d2d67/runs/run_99935dbd-e731-4bad-b450-60d9d6bf9a44/submit_tool_outputs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"tool_outputs": [
{
"tool_call_id": "",
"output": "rain"
}
]
}'流式
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/threads/thread_9157dfad-71fd-4add-b7a9-1afa452d2d67/runs/run_99935dbd-e731-4bad-b450-60d9d6bf9a44/submit_tool_outputs' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
"tool_outputs": [
{
"tool_call_id": "",
"output": "rain"
}
],
"stream": true
}'輸入參數
輸入參數名字 | 輸入參數的描述 | 參數類型 | 是否必須 |
thread_id | 待修改的thread_id | string | 是 |
run_id | 待修改的run_id | string | 是 |
tool_outputs | 待返回給 Assistant 的工具調用結果清單 | array | 是 |
tool_outputs[].tool_call_id | 工具調用id | string | 否 |
tool_outputs[].output | 待返回的結果 | string | 是 |
stream | 是否流式返回 | boolean | 否 |
返回結果
非流式
{
"id": "run_99935dbd-e731-4bad-b450-60d9d6bf9a44",
"object": "thread.run",
"created_at": 1711519089921,
"thread_id": "thread_9157dfad-71fd-4add-b7a9-1afa452d2d67",
"assistant_id": "asst_ce66cfa8-b2f8-4e4c-8e17-2c335145be42",
"status": "in_progress",
"required_action": {
"type": "submit_tool_outputs",
"submit_tool_outputs": {
"tool_calls": [
{
"function": {
"name": "get_current_weather",
"arguments": "{\"location\": \"西安\"}"
},
"id": "",
"type": "function"
}
]
}
},
"last_error": {},
"expires_at": 0,
"started_at": 0,
"cancelled_at": 0,
"failed_at": 0,
"completed_at": 0,
"model": "qwen-max",
"instructions": "你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。",
"tools": [
{
"type": "text_to_image"
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
]
}
},
"required": [
"location"
]
}
}
}
],
"metadata": {},
"usage": null,
"request_id": "792c29a2-e771-9840-9d99-df4f892badd0"
}流式
event:thread.run.step.completed
data:{"id":"step_74a8b5e2-3d23-41d9-b5c8-9bf3ba3839d0","object":"thread.run.step","created_at":1714448906129,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","type":"tool_calls","status":"completed","step_details":{"type":"tool_calls","tool_calls":[{"id":"","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\": \"Xi'an\"}","output":"rain"}}]},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.queued
data:{"id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","object":"thread.run","created_at":1714448903737,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"queued","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.in_progress
data:{"id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","object":"thread.run","created_at":1714448903737,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"in_progress","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":null,"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.step.created
data:{"id":"step_d74df5eb-dcb8-4fc2-a943-d06ccda0e2e3","object":"thread.run.step","created_at":1714449008828,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.step.in_progress
data:{"id":"step_d74df5eb-dcb8-4fc2-a943-d06ccda0e2e3","object":"thread.run.step","created_at":1714449008828,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","type":"message_creation","status":"in_progress","step_details":{"type":"message_creation","message_creation":{"message_id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"metadata":{},"usage":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.created
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message","created_at":1714449008828,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","file_ids":[],"metadata":{},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.in_progress
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message","created_at":1714449008828,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","incomplete_details":null,"completed_at":null,"incomplete_at":null,"role":"assistant","content":[],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","file_ids":[],"metadata":{},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.delta
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"西","annotations":[]}}],"file_ids":[]},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.delta
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"安目前的天氣是","annotations":[]}}],"file_ids":[]},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.delta
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"雨天。","annotations":[]}}],"file_ids":[]},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.delta
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message.delta","delta":{"role":"assistant","content":[{"type":"text","text":{"value":"","annotations":[]}}],"file_ids":[]},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.message.completed
data:{"id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360","object":"thread.message","created_at":1714449008828,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","incomplete_details":null,"completed_at":1714449009919,"incomplete_at":null,"role":"assistant","content":[{"type":"text","text":{"value":"西安目前的天氣是雨天。","annotations":[]}}],"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","file_ids":[],"metadata":{},"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.step.completed
data:{"id":"step_d74df5eb-dcb8-4fc2-a943-d06ccda0e2e3","object":"thread.run.step","created_at":1714449008828,"assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","run_id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","type":"message_creation","status":"completed","step_details":{"type":"message_creation","message_creation":{"message_id":"message_965b3bb5-dbe2-434a-a36e-f7cda3845360"}},"last_error":null,"expired_at":null,"cancelled_at":null,"failed_at":null,"completed_at":1714449009919,"metadata":{},"usage":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:thread.run.completed
data:{"id":"run_36d6fba9-0bf1-47f5-8e7b-f8c8140beda9","object":"thread.run","created_at":1714448903737,"thread_id":"thread_c6ac2eb0-ed95-4834-befb-ea66eba85b9f","assistant_id":"asst_5378d83a-f612-4fc1-9034-915351d67d98","status":"completed","required_action":null,"last_error":null,"expires_at":null,"started_at":null,"cancelled_at":null,"failed_at":null,"completed_at":null,"model":"qwen-max","instructions":"你是一個智能小助手,你可以根據使用者的需求去調用不同的工具,進而給出回答。請酌情使用工具。","tools":[{"type":"text_to_image"},{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}],"file_ids":[],"metadata":{},"usage":{"input_tokens":439,"output_tokens":11,"total_tokens":450},"temperature":null,"top_p":null,"top_k":null,"max_tokens":null,"truncation_strategy":null,"request_id":"6d1573a4-3cbb-9066-99cc-7247ec17cb30"}
event:done
data:[DONE]輸出參數
與指定 ID 匹配的修改後的運行對象。
SDK
import json
import sys
from http import HTTPStatus
import dashscope
from dashscope import Assistants, Messages, Runs, Steps, Threads
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
def create_assistant():
# create assistant with information
assistant = Assistants.create(
model='qwen-max',
name='smart helper',
description='A tool helper.',
instructions='You are a helpful assistant. When asked a question, use tools wherever possible.', # noqa E501
tools=[{
'type': 'function',
'function': {
'name': 'big_add',
'description': 'Add to number',
'parameters': {
'type': 'object',
'properties': {
'left': {
'type': 'integer',
'description': 'The left operator'
},
'right': {
'type': 'integer',
'description': 'The right operator.'
}
},
'required': ['left', 'right']
}
}
}],
)
return assistant
def verify_status_code(res):
if res.status_code != HTTPStatus.OK:
sys.exit(res.status_code)
if __name__ == '__main__':
# create assistant
assistant = create_assistant()
print(assistant)
verify_status_code(assistant)
# create thread.
thread = Threads.create()
print(thread)
verify_status_code(thread)
# create a message.
message = Messages.create(thread.id, content='bigAdd 87787 to 788988737.')
print(message)
verify_status_code(message)
# create run to run message
message_run = Runs.create(thread.id, assistant_id=assistant.id)
print(message_run)
verify_status_code(message_run)
# get run statue
run_status = Runs.get(message_run.id, thread_id=thread.id)
print(run_status)
verify_status_code(run_status)
# wait for run completed or requires_action
run_status = Runs.wait(message_run.id, thread_id=thread.id)
print(run_status)
# if prompt input tool result, submit tool result.
# should call big_add
if run_status.required_action:
tool_outputs = [{
'tool_call_id':
run_status.required_action.submit_tool_outputs.tool_calls[0].id,
'output':
'789076524'
}]
run = Runs.submit_tool_outputs(message_run.id,
thread_id=thread.id,
tool_outputs=tool_outputs)
print(run)
verify_status_code(run)
# wait for run completed or requires_action
run_status = Runs.wait(message_run.id, thread_id=thread.id)
print(run_status)
verify_status_code(run_status)
run_status = Runs.get(run.id, thread_id=thread.id)
print(run_status)
verify_status_code(run_status)
run_steps = Steps.list(run.id, thread_id=thread.id)
print(run_steps)
verify_status_code(run_steps)
# get the thread messages.
msgs = Messages.list(thread.id)
print(msgs)
print(json.dumps(msgs, default=lambda o: o.__dict__, sort_keys=True, indent=4))
import com.alibaba.dashscope.assistants.Assistant;
import com.alibaba.dashscope.assistants.AssistantParam;
import com.alibaba.dashscope.tools.ToolFunction;
import com.alibaba.dashscope.assistants.Assistants;
import com.alibaba.dashscope.common.GeneralListParam;
import com.alibaba.dashscope.common.ListResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.AssistantThread;
import com.alibaba.dashscope.threads.ThreadParam;
import com.alibaba.dashscope.threads.Threads;
import com.alibaba.dashscope.threads.messages.Messages;
import com.alibaba.dashscope.threads.messages.TextMessageParam;
import com.alibaba.dashscope.threads.messages.ThreadMessage;
import com.alibaba.dashscope.threads.runs.RequiredAction;
import com.alibaba.dashscope.threads.runs.Run;
import com.alibaba.dashscope.threads.runs.RunParam;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.threads.runs.SubmitToolOutputsParam;
import com.alibaba.dashscope.threads.runs.ToolOutput;
import com.alibaba.dashscope.tools.FunctionDefinition;
import com.alibaba.dashscope.tools.ToolCallBase;
import com.alibaba.dashscope.utils.JsonUtils;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.victools.jsonschema.generator.Option;
import com.github.victools.jsonschema.generator.OptionPreset;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.generator.SchemaVersion;
import com.alibaba.dashscope.tools.ToolCallFunction;
import com.alibaba.dashscope.utils.Constants;
public class AssistantFunctionCall {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public class AddFunctionTool {
private int left;
private int right;
public AddFunctionTool(int left, int right) {
this.left = left;
this.right = right;
}
public int call() {
return left + right;
}
}
static ToolFunction buildFunction() {
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12,
OptionPreset.PLAIN_JSON);
SchemaGeneratorConfig config = configBuilder.with(Option.EXTRA_OPEN_API_FORMAT_VALUES)
.without(Option.FLATTENED_ENUMS_FROM_TOSTRING).build();
SchemaGenerator generator = new SchemaGenerator(config);
// generate jsonSchema of function.
ObjectNode jsonSchema = generator.generateSchema(AddFunctionTool.class);
// call with tools of function call, jsonSchema.toString() is jsonschema String.
FunctionDefinition fd = FunctionDefinition.builder().name("add").description("add two number")
.parameters(JsonUtils.parseString(jsonSchema.toString()).getAsJsonObject()).build();
return ToolFunction.builder().function(fd).build();
}
static public Assistant createAssistant() throws ApiException, NoApiKeyException{
AssistantParam assistantParam = AssistantParam.builder()
.model("qwen-max") // model must be set.
.description("a helper assistant")
.name("system") // name必須填寫
.instructions("You are a helpful assistant. When asked a question, use tools wherever possible.")
.tool(buildFunction())
.build();
Assistants assistants = new Assistants();
return assistants.create(assistantParam);
}
static public void run(String assistantId) throws ApiException, NoApiKeyException, InvalidateParameter, InputRequiredException, InterruptedException{
// create a thread
Threads threads = new Threads();
AssistantThread assistantThread = threads.create(ThreadParam.builder().build());
Runs runs = new Runs();
// create a new message
TextMessageParam textMessageParam = TextMessageParam.builder().role("user").content("Add 87787 to 788988737.").build();
Messages messages = new Messages();
ThreadMessage threadMessage = messages.create(assistantThread.getId(), textMessageParam);
System.out.println(threadMessage);
RunParam runParam = RunParam.builder().assistantId(assistantId).build();
Run run = runs.create(assistantThread.getId(), runParam);
while(true){
if(run.getStatus().equals(Run.Status.CANCELLED) ||
run.getStatus().equals(Run.Status.COMPLETED) ||
run.getStatus().equals(Run.Status.FAILED) ||
run.getStatus().equals(Run.Status.REQUIRES_ACTION)||
run.getStatus().equals(Run.Status.EXPIRED)){
break;
}else{
Thread.sleep(1000);
}
run = runs.retrieve(assistantThread.getId(), run.getId());
}
if(run.getStatus().equals(Run.Status.REQUIRES_ACTION)){
// submit action output.
RequiredAction requiredAction = run.getRequiredAction();
if(requiredAction.getType().equals("submit_tool_outputs")){
ToolCallBase toolCall = requiredAction.getSubmitToolOutputs().getToolCalls().get(0);
if (toolCall.getType().equals("function")) {
// get function call name and argument, both String.
String functionName = ((ToolCallFunction) toolCall).getFunction().getName();
String functionId = ((ToolCallFunction)toolCall).getId();
String functionArgument = ((ToolCallFunction) toolCall).getFunction().getArguments();
if (functionName.equals("add")) {
// Create the function object.
AddFunctionTool addFunction =
JsonUtils.fromJson(functionArgument, AddFunctionTool.class);
// call function.
int sum = addFunction.call();
System.out.println(sum);
SubmitToolOutputsParam submitToolOutputsParam = SubmitToolOutputsParam.builder()
.toolOutput(ToolOutput.builder().toolCallId(functionId).output(String.valueOf(sum)).build())
.build();
run = runs.submitToolOutputs(assistantThread.getId(), run.getId(), submitToolOutputsParam);
}
}
}
}
while(true){
if(run.getStatus().equals(Run.Status.CANCELLED) ||
run.getStatus().equals(Run.Status.COMPLETED) ||
run.getStatus().equals(Run.Status.FAILED) ||
run.getStatus().equals(Run.Status.REQUIRES_ACTION)||
run.getStatus().equals(Run.Status.EXPIRED)){
break;
}else{
Thread.sleep(1000);
}
run = runs.retrieve(assistantThread.getId(), run.getId());
}
GeneralListParam listParam = GeneralListParam.builder().limit(100l).build();
ListResult<ThreadMessage> threadMessages = messages.list(assistantThread.getId(), listParam);
for(ThreadMessage threadMessage2: threadMessages.getData()){
System.out.println(threadMessage2);
}
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Assistant assistant = createAssistant();
run(assistant.getId());
}
}等待運行任務結束
等待run執行,run為終態返回,終止狀態包含['cancelled', 'failed', 'completed', 'expired', 'requires_action']
SDK
程式碼範例
import dashscope
from dashscope import Runs
import os
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
run = Runs.wait(
'run_id',
# 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"
api_key=os.getenv("DASHSCOPE_API_KEY"),
thread_id='thread_id'
)
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.InvalidateParameter;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.threads.runs.Run;
import com.alibaba.dashscope.threads.runs.Runs;
import com.alibaba.dashscope.utils.Constants;
public class AssistantFunctionCall {
static {
Constants.baseHttpApiUrl="https://dashscope-intl.aliyuncs.com/api/v1";
}
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
// 建議您優先配置環境變數。若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey("sk-xxx")
String apiKey = System.getenv("DASHSCOPE_API_KEY");
Run run = runs.retrieve("thread_id", "run_id", apiKey);
while(true){
if(run.getStatus().equals(Run.Status.CANCELLED) ||
run.getStatus().equals(Run.Status.COMPLETED) ||
run.getStatus().equals(Run.Status.FAILED) ||
run.getStatus().equals(Run.Status.REQUIRES_ACTION)||
run.getStatus().equals(Run.Status.EXPIRED)){
break;
}else{
Thread.sleep(1000);
}
run = runs.retrieve("thread_id", run.getId());
}
}
}輸入參數
參數 | 類型 | 預設值 | 說明 |
run_id | string | - | 指定要取消的Run id |
thread_id | string | - | Run所屬Thread id |
workspace | string | None | 阿里雲百鍊的Workspace ID,僅當 api_key 為子業務空間 API Key 時才需要傳入。 |
api_key | string | None | 阿里雲百鍊的API Key,建議您配置API Key到環境變數(準備下線,併入配置 API Key)。 |
輸出參數
與指定 ID 匹配的修改後的運行對象。
運行對象
表示在一個線程上執行的運行。
對象樣本
{
"assistant_id": "[REDACTED]",
"cancelled_at": null,
"completed_at": null,
"created_at": 1735026246751,
"enable_search": null,
"expires_at": null,
"failed_at": null,
"file_ids": [],
"id": "[REDACTED]",
"instructions": "you are a helpful assistant",
"last_error": null,
"max_tokens": null,
"metadata": {},
"model": "qwen-plus",
"object": "thread.run",
"request_id": "[REDACTED]",
"required_action": null,
"started_at": null,
"status": "in_progress",
"status_code": 200,
"stop": "",
"temperature": null,
"thread_id": "[REDACTED]",
"tool_choice": "auto",
"tools": [],
"top_k": null,
"top_p": null,
"truncation_strategy": null,
"usage": null
}對象屬性
參數名稱 | 參數類型 | 參數描述 |
id | string | 運行 (Run) 的唯一識別碼。 |
assistant_id | string | 與此運行關聯的助手 (Assistant) 的 ID。 |
cancelled_at | integer | 運行被取消的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
completed_at | integer | 運行完成的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
created_at | integer | 運行建立的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
expires_at | integer | 運行到期的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
failed_at | integer | 運行失敗的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
instructions | string | 啟動並執行指令。 |
metadata | map | 一組最多包含 16 個索引值對,可以附加到對象上。用於以結構化格式儲存有關對象的附加資訊。鍵的最大長度為 64 個字元,值的最大長度為 512 個字元。 |
last_error | string | 與此運行相關的最後一個錯誤。如果沒有錯誤,則為null。 |
model | string | 用於啟動並執行模型名稱。 |
object | string | 物件類型,始終為thread.run。 |
required_action | object | 表示運行需要執行的操作,例如提交工具輸出。 |
started_at | integer | 運行開始的時間戳記(Unix 13位時間戳記,單位:毫秒)。 |
status | string | 啟動並執行狀態,可以是queued(已排隊)、in_progress(進行中)、requires_action(需要操作)、cancelling(取消中)、cancelled(已取消)、failed(已失敗)、completed(已完成)或expired(已到期)。 |
thread_id | string | 此運行所屬的線程 (Thread) 的 ID。 |
tools | array | 運行使用的工具列表。 |
usage | object | 資源使用方式統計資訊。 |
status_code | integer | HTTP 狀態代碼。注意:此參數主要用於內部處理,通常情況下,您無需關注此參數。 |
常見問題
Q:如何取消正在執行中的 Run 任務?
A:Assistant API 尚未提供“取消 Run 任務”的介面,建議您使用其他代碼邏輯作為替代。
錯誤碼
如果模型調用失敗並返回報錯資訊,請參見錯誤資訊進行解決。