Messages
Create
from dashscope import Messages
msg = Messages.create('the_thread_id',
content='The message content.',
role='user',
file_ids=['file_id1'],
metadata={'key': 'value'})
返回结果
结果为Message对象,json化内容为:
{
"account_id": "sk-6bddfc116de744c3aa1d66893cc87b20",
"assistant_id": "",
"content": [
{
"text": {
"value": "sdhafjdasf"
},
"type": "text"
}
],
"created_at": 1711345341301,
"display": true,
"file_ids": [
"file_id1"
],
"from": "",
"gmt_crete": "2024-03-25 13:42:21",
"gmt_update": "2024-03-25 13:42:21",
"id": "message_05494921-a646-484e-85fc-76329acba842",
"metadata": {
"key": "value"
},
"name": "",
"object": "thread.message",
"plugin_call": {},
"request_id": "631de0b3-7e50-9c9e-8444-0924d1b7e7a5",
"role": "user",
"run_id": "",
"status": {},
"status_code": 200,
"thread_id": "thread_f1e7737e-b045-479f-99d1-510db49d535b",
"tool_calls": []
}
输入参数配置
参数 | 类型 | 默认值 | 说明 |
thread_id | str | - | Thread id |
content | str | - | 消息内容 |
role | str | 'user' | Message的role,默认user |
metadata | Dict | None | 与该Message关联的key/value信息 |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope API key,可以通过环境变量等方法设置。 |
输出Message对象字段说明
字段名 | 字段类型 | 字段描述 |
status_code | int | 为调用http status code,200表示调用成功,其他表示调用出错 |
id | str | Message id,为uuid字符串 |
content | List[dict] | 消息内容 |
content.type | str | content内容类型,如text |
content.text | dict | content内容 |
content.text.value | str | content text value |
file_ids | List[str] | Message关联的文件id列表 |
metadata | Dict | 和这个Message关联的key/value信息 |
tool_calls | Dcit | 调用tool信息 |
plugin_call | Dict | 调用plugin 信息 |
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 |
retrieve
调用方法
from dashscope import Messages
message = Messages.retrieve('message_id',
thread_id='thread_id')
输入参数
参数 | 类型 | 默认值 | 说明 |
message_id | str | - | 指定要查询的Message id |
thread_id | str | - | 指定要查询的Message所属Thread id |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope API key,可以通过环境变量等方法设置。 |
输出参数
参考create结果
update
from dashscope import Messages
thread = Messages.update('message_id',
thread_id='the_message_thread_id',
metadata={'key': 'value'})
请求参数
参数 | 类型 | 默认值 | 说明 |
message_id | str | - | 指定要更新的Message id |
thread_id | str | - | 指定要更新的Message所属Thread id |
metadata | Dict | None | Thread关联信息 |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
返回参数
同create,参考create
list
from dashscope import Messages
messages = Messages.list('thread_id',
limit=1,
order='desc',
after='',
before='')
请求参数
参数 | 类型 | 默认值 | 说明 |
thread_id | str | - | 指定要查询的thread id |
limit | str | - | |
order | |||
after | |||
before | |||
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope API key,可以通过环境变量等方法设置。 |
返回参数
输出MessageList对象字段说明
字段名 | 字段类型 | 字段描述 |
his_more | bool | |
last_id | str | |
first_id | str | |
data | list[Message] | Message对象列表 |
- 本页导读 (1)