Assistants
Create
from dashscope import Assistants
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': 'search'
}, {
'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']
}
}
}],
)
返回结果
结果为Assistant对象,json化内容为:
{
"account_id": "sk-450bfd9582664946b8c42244fce43fcc",
"created_at": 1711098751346,
"description": "A tool helper.",
"file_ids": [],
"id": "asst_5da58c10-c86a-4014-b91c-57a091bcf5f9",
"instructions": "You are a helpful assistant. When asked a question, use tools wherever possible.",
"is_deleted": false,
"metadata": {},
"model": "qwen-max",
"name": "smart helper",
"object": "assistant",
"request_id": "dd1f5cf5-b997-9940-b1ef-0b8bc7f153d1",
"status_code": 200,
"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"
}
]
}
输入参数配置
参数 | 类型 | 默认值 | 说明 |
model | str | - | 指定用于assistant所使用的模型 |
name | str | None | 指定assistant名称 |
description | str | None | assistant描述 |
tools | List[Dict] | [] | assistant使用的tools |
file_ids | List[str] | [] | assistant使用的文件id |
metadata | Dict | None | assistant关联信息 |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
输出Assistant对象字段说明
字段名 | 字段类型 | 字段描述 |
status_code | int | 为调用http status code,200表示调用成功,其他表示调用出错 |
name | str | assistant名称 |
id | str | assistant id,为uuid字符串 |
model | str | assistant 使用的模型名称 |
description | str | assistant描述信息 |
instructions | str | assistant instruction信息,指定assisiant功能信息。 |
metadata | object | key,value对对象信息,描述assistant信息 |
tools | List[Tool] | assistant可以是用的tool列表 |
file_ids | List[str] | assistant 关联file id,file可以通过file命令和Files接口上传。 |
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 Assistants
assistant = Assistants.retrieve('assistant_id')
输入参数
参数 | 类型 | 默认值 | 说明 |
assistant_id | str | - | 指定要查询的assistant id |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
输出参数
参考create结果
list
from dashscope import Assistants
assistants = Assistants.list(limit=1,
order='desc',
after='',
before='')
请求参数
参数 | 类型 | 默认值 | 说明 |
limit | str | - | 指定要查询的assistant id |
order | |||
after | |||
before | |||
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
返回参数
输出AssistantList对象字段说明
字段名 | 字段类型 | 字段描述 |
his_more | bool | |
last_id | str | |
first_id | str | |
data | list[Assistant] | Assistant对象列表 |
update
from dashscope import Assistants
assistants = Assistants.update('assistant_id', model='new_model_name')
请求参数
参数 | 类型 | 默认值 | 说明 |
assistant_id | str | - | 指定需要update的assisaant id |
model | str | - | 指定用于assistant所使用的模型 |
name | str | None | 指定assistant名称 |
description | str | None | assistant描述 |
tools | List[Dict] | [] | assistant使用的tools |
file_ids | List[str] | [] | assistant使用的文件id |
metadata | Dict | None | assistant关联信息 |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
返回参数
同create,参考create
delete
from dashscope import Assistants
assistants = Assistants.delete(assistant_id)
请求参数
参数 | 类型 | 默认值 | 说明 |
assistant_id | str | - | 指定要删除的assistant id |
workspace | str | None | DashScope workspace id |
api_key | str | None | DashScope api key,可以通过环境变量等方法设置。 |
返回参数
字段名 | 字段类型 | 字段描述 |
id | str | 删除的对象的id |
deleted | bool | 是否删除 |
- 本页导读 (1)