运行
创建线程运行
from dashscope import Runs
run = Runs.create('thread_id',
assistant_id='assistant_id',
model='the_model_to_use',
instructions='Instructions',
additional_instructions='additional_instructions',
tools=['list_of_tool_to_use'],
metadata={'key': 'value'})
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.RunParam;
import com.alibaba.dashscope.threads.runs.Runs;
public class Main {
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
RunParam runParam = RunParam.builder().assistantId("assistantId").build();
Run run = runs.create("threadId", runParam);
}
}
返回结果
结果为Run对象,json化内容为:
{
"account_id": "sk-450bfd9582664946b8c42244fce43fcc",
"assistant_id": "asst_8eeaedde-3f8b-41d2-9433-0e88a6042ecb",
"created_at": 1711347311426,
"file_ids": [],
"id": "run_f2c663e6-69f9-4494-9017-acf788db5a17",
"instructions": "You are a helpful assistant. When asked a question, use tools wherever possible.",
"metadata": {},
"model": "qwen-max-allinone",
"object": "thread.run",
"request_id": "53561cd0-350c-918d-b3f7-716a0e41bcfd",
"status": "in_progress",
"status_code": 200,
"thread_id": "thread_45ca9a78-2b1f-4172-b4cf-cf8c748c1c32",
"tools": [
{
"type": "search"
},
{
"function": {
"description": "Add to number",
"name": "big_add",
"parameters": {
"properties": {
"left": {
"description": "The left operator",
"type": "integer"
},
"right": {
"description": "The right operator.",
"type": "integer"
}
},
"required": [
"left",
"right"
],
"type": "object"
}
},
"type": "function"
}
]
}
创建流式运行任务
stream_iterator = dashscope.Runs.create(thread.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;
public class Main {
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
RunParam runParam = RunParam.builder().assistantId("assistantId").stream(true).build();
Flowable<AssistantStreamMessage> run = runs.createStream("threadId", runParam);
}
}
流式输出示例
流式输出将输出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}
输入参数配置
参数 | 类型 | 默认值 | 说明 |
thread_id | str | - | 期望在那个Thread run |
assistant_id | str | - | assistant id |
model | str | - | 指定使用的模型 |
instructions | str | None | 指定本次run所用的指令 |
additional_instructions | str | None | 指定附加的指令 |
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 | |||
top_p | |||
top_k | |||
max_tokens | |||
truncation_strategy | Dict | None | 设置thread中消息截断策略, 目前只支持last_messages,默认为: "truncation_strategy": { "type": "last_messages", "last_messages": 10 } |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
输出Run对象字段说明
字段名 | 字段类型 | 字段描述 |
status_code | int | 为调用http status code,200表示调用成功,其他表示调用出错 |
id | str | Run id,为uuid字符串 |
model | str | Run 使用的模型名称 |
instructions | str | assistant instruction信息,指定assisiant功能信息。 |
metadata | object | key,value对对象信息,描述assistant信息 |
status | str | Run的状态,包含'in_progress, 等 |
thread_id | str | Run所属Thread id |
tools | List[Tool] | Run使用的tool列表 |
file_ids | List[str] | Run 关联file id 列表 |
created_at | timestamp | assistant创建时间 |
gmt_created | datatime | 2024-03-22 17:12:31 |
gmt_modified | datatime | 2024-03-22 17:12:31 |
code | str | 表示请求失败,表示错误码,成功忽略。 python only |
message | str | 失败,表示失败详细信息,成功忽略。 python only |
检索运行任务
from dashscope import Runs
run = Runs.retrieve('run_id',
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;
public class Main {
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
Run run = runs.retrieve("threadId", "runId");
}
}
输入参数
参数 | 类型 | 默认值 | 说明 |
run_id | str | - | 指定要查询的Run id |
thread_id | str | - | 指定Run所属Thread id |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
输出参数
参考create结果
列出运行任务
from dashscope import Runs
runs = Runs.list('thread_id',
limit=1,
order='desc',
after='',
before='')
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;
public class Main {
public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
Runs runs = new Runs();
GeneralListParam listRuns = GeneralListParam.builder().build();
ListResult<Run> run = runs.list("threadId", listRuns);
}
}
请求参数
参数 | 类型 | 默认值 | 说明 |
thread_id | str | - | 指定要list的Thread id |
limit | str | - | |
order | |||
after | |||
before | |||
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope API key,可以通过环境变量等方法设置。 |
返回参数
输出RunList对象字段说明
字段名 | 字段类型 | 字段描述 |
his_more | bool | |
last_id | str | |
first_id | str | |
data | list[Run] | Run对象列表 |
修改线程运行
from dashscope import Runs
run = Runs.update('run_id',
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;
public class Main {
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");
UpdateMetadataParam updateParam = UpdateMetadataParam.builder().metadata(metadata).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 | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
返回参数
同create,参考create
等待运行任务
等待run执行,run为终态返回,终止状态包含['cancelled', 'failed', 'completed', 'expired',
'requires_action']
from dashscope import Runs
run = Runs.wait('run_id',
thread_id='thread_id')
请求参数
参数 | 类型 | 默认值 | 说明 |
run_id | str | - | 指定要取消的Run id |
thread_id | str | - | Run所属Thread id |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
返回参数
同Create