助理
试用版

构建可以调用模型并使用工具执行任务的助手。source

开始使用 Assistants APIsource

创建助手
试用版

POST https://api.openai.com/v1/assistants

创建包含模型和说明的助手。source

请求正文

要使用的模型的 ID。您可以使用 List models API 查看所有可用模型,或查看我们的 Model overview 了解它们的描述。source

助手的姓名。最大长度为 256 个字符。source

助手的描述。最大长度为 512 个字符。source

助手使用的系统指令。最大长度为 256,000 个字符。source

在 Assistant 上启用的工具列表。每个助手最多可以有 128 个工具。工具可以是多种类型code_interpreter,file_searchfunction.source

助手的工具使用的一组资源。这些资源特定于工具类型。例如,code_interpreter工具需要文件 ID 列表,而file_search工具需要矢量存储 ID 列表。source

一组 16 个可附加到对象的键值对。这对于以结构化格式存储有关对象的其他信息非常有用。键的长度最大为 64 个字符,值的长度最大为 512 个字符。source

要使用的采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使其更加集中和确定。source

使用温度进行采样的替代方法,称为核抽样,其中模型考虑具有top_p概率质量的标记的结果。所以 0.1 意味着只考虑包含前 10% 概率质量的 token。source

我们通常建议更改此温度或温度,但不能同时更改两者。source

指定模型必须输出的格式。兼容 GPT-4oGPT-4 Turbo 和所有 GPT-3.5 Turbo 型号gpt-3.5-turbo-1106.source

设置为{ "type": "json_schema", "json_schema": {...} }启用结构化输出,以确保模型与您提供的 JSON 架构匹配。在结构化输出指南中了解更多信息。source

设置为{ "type": "json_object" }启用 JSON 模式,以确保模型生成的消息是有效的 JSON。source

重要提示:使用 JSON 模式时,还必须通过系统或用户消息指示模型自行生成 JSON。否则,模型可能会生成无休止的空格流,直到生成达到令牌限制,从而导致长时间运行且似乎“卡住”的请求。另请注意,如果出现以下情况,消息内容可能会被部分截断finish_reason="length",这表示已超过代数max_tokens或对话超过了最大上下文长度。source

返回

辅助对象。source

示例请求
1
2
3
4
5
6
7
8
9
10
curl "https://api.openai.com/v1/assistants" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
    "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
    "name": "Math Tutor",
    "tools": [{"type": "code_interpreter"}],
    "model": "gpt-4o"
  }'
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
  "id": "asst_abc123",
  "object": "assistant",
  "created_at": 1698984975,
  "name": "Math Tutor",
  "description": null,
  "model": "gpt-4o",
  "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
  "tools": [
    {
      "type": "code_interpreter"
    }
  ],
  "metadata": {},
  "top_p": 1.0,
  "temperature": 1.0,
  "response_format": "auto"
}

列出助理
试用版

获取 https://api.openai.com/v1/assistants

返回助手列表。source

查询参数

要返回的对象数量限制。Limit 的范围可以介于 1 和 100 之间,默认值为 20。source

created_at对象的时间戳。asc对于升序和desc以降序排列。source

用于分页的游标。after是定义您在列表中的位置的对象 ID。例如,如果您发出列表请求并收到 100 个对象,以 obj_foo 结尾,则您的后续调用可以包含 after=obj_foo 以便获取列表的下一页。source

用于分页的游标。before是定义您在列表中的位置的对象 ID。例如,如果您发出一个列表请求并收到 100 个对象,以 obj_foo 开头,则您的后续调用可以包含 before=obj_foo 以便获取列表的上一页。source

返回

辅助对象列表。source

示例请求
1
2
3
4
curl "https://api.openai.com/v1/assistants?order=desc&limit=20" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2"
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
  "object": "list",
  "data": [
    {
      "id": "asst_abc123",
      "object": "assistant",
      "created_at": 1698982736,
      "name": "Coding Tutor",
      "description": null,
      "model": "gpt-4o",
      "instructions": "You are a helpful assistant designed to make me better at coding!",
      "tools": [],
      "tool_resources": {},
      "metadata": {},
      "top_p": 1.0,
      "temperature": 1.0,
      "response_format": "auto"
    },
    {
      "id": "asst_abc456",
      "object": "assistant",
      "created_at": 1698982718,
      "name": "My Assistant",
      "description": null,
      "model": "gpt-4o",
      "instructions": "You are a helpful assistant designed to make me better at coding!",
      "tools": [],
      "tool_resources": {},
      "metadata": {},
      "top_p": 1.0,
      "temperature": 1.0,
      "response_format": "auto"
    },
    {
      "id": "asst_abc789",
      "object": "assistant",
      "created_at": 1698982643,
      "name": null,
      "description": null,
      "model": "gpt-4o",
      "instructions": null,
      "tools": [],
      "tool_resources": {},
      "metadata": {},
      "top_p": 1.0,
      "temperature": 1.0,
      "response_format": "auto"
    }
  ],
  "first_id": "asst_abc123",
  "last_id": "asst_abc789",
  "has_more": false
}

检索助手
试用版

获取 https://api.openai.com/v1/assistants/{assistant_id}

检索助手。source

路径参数

要检索的助手的 ID。source

返回

与指定 ID 匹配的 assistant 对象。source

示例请求
1
2
3
4
curl https://api.openai.com/v1/assistants/asst_abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2"
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
  "id": "asst_abc123",
  "object": "assistant",
  "created_at": 1699009709,
  "name": "HR Helper",
  "description": null,
  "model": "gpt-4o",
  "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies.",
  "tools": [
    {
      "type": "file_search"
    }
  ],
  "metadata": {},
  "top_p": 1.0,
  "temperature": 1.0,
  "response_format": "auto"
}

修改助手
试用版

POST https://api.openai.com/v1/assistants/{assistant_id}

修改助手。source

路径参数

要修改的助手的 ID。source

请求正文

要使用的模型的 ID。您可以使用 List models API 查看所有可用模型,或查看我们的 Model overview 了解它们的描述。source

助手的姓名。最大长度为 256 个字符。source

助手的描述。最大长度为 512 个字符。source

助手使用的系统指令。最大长度为 256,000 个字符。source

在 Assistant 上启用的工具列表。每个助手最多可以有 128 个工具。工具可以是多种类型code_interpreter,file_searchfunction.source

助手的工具使用的一组资源。这些资源特定于工具类型。例如,code_interpreter工具需要文件 ID 列表,而file_search工具需要矢量存储 ID 列表。source

一组 16 个可附加到对象的键值对。这对于以结构化格式存储有关对象的其他信息非常有用。键的长度最大为 64 个字符,值的长度最大为 512 个字符。source

要使用的采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使其更加集中和确定。source

使用温度进行采样的替代方法,称为核抽样,其中模型考虑具有top_p概率质量的标记的结果。所以 0.1 意味着只考虑包含前 10% 概率质量的 token。source

我们通常建议更改此温度或温度,但不能同时更改两者。source

指定模型必须输出的格式。兼容 GPT-4oGPT-4 Turbo 和所有 GPT-3.5 Turbo 型号gpt-3.5-turbo-1106.source

设置为{ "type": "json_schema", "json_schema": {...} }启用结构化输出,以确保模型与您提供的 JSON 架构匹配。在结构化输出指南中了解更多信息。source

设置为{ "type": "json_object" }启用 JSON 模式,以确保模型生成的消息是有效的 JSON。source

重要提示:使用 JSON 模式时,还必须通过系统或用户消息指示模型自行生成 JSON。否则,模型可能会生成无休止的空格流,直到生成达到令牌限制,从而导致长时间运行且似乎“卡住”的请求。另请注意,如果出现以下情况,消息内容可能会被部分截断finish_reason="length",这表示已超过代数max_tokens或对话超过了最大上下文长度。source

返回

修改后的 assistant 对象。source

示例请求
1
2
3
4
5
6
7
8
9
curl https://api.openai.com/v1/assistants/asst_abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
      "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.",
      "tools": [{"type": "file_search"}],
      "model": "gpt-4o"
    }'
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
  "id": "asst_123",
  "object": "assistant",
  "created_at": 1699009709,
  "name": "HR Helper",
  "description": null,
  "model": "gpt-4o",
  "instructions": "You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.",
  "tools": [
    {
      "type": "file_search"
    }
  ],
  "tool_resources": {
    "file_search": {
      "vector_store_ids": []
    }
  },
  "metadata": {},
  "top_p": 1.0,
  "temperature": 1.0,
  "response_format": "auto"
}

删除助手
试用版

删除 https://api.openai.com/v1/assistants/{assistant_id}

删除助手。source

路径参数

要删除的助手的 ID。source

返回

删除状态source

示例请求
1
2
3
4
5
curl https://api.openai.com/v1/assistants/asst_abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -X DELETE
响应
1
2
3
4
5
{
  "id": "asst_abc123",
  "object": "assistant.deleted",
  "deleted": true
}

辅助对象
试用版

表示assistant可以调用模型并使用工具。source

标识符,可在 API 终端节点中引用。source

对象类型,始终为assistant.source

创建 Assistant 时的 Unix 时间戳(以秒为单位)。source

助手的姓名。最大长度为 256 个字符。source

助手的描述。最大长度为 512 个字符。source

要使用的模型的 ID。您可以使用 List models API 查看所有可用模型,或查看我们的 Model overview 了解它们的描述。source

助手使用的系统指令。最大长度为 256,000 个字符。source

在 Assistant 上启用的工具列表。每个助手最多可以有 128 个工具。工具可以是多种类型code_interpreter,file_searchfunction.source

助手的工具使用的一组资源。这些资源特定于工具类型。例如,code_interpreter工具需要文件 ID 列表,而file_search工具需要矢量存储 ID 列表。source

一组 16 个可附加到对象的键值对。这对于以结构化格式存储有关对象的其他信息非常有用。键的长度最大为 64 个字符,值的长度最大为 512 个字符。source

要使用的采样温度,介于 0 和 2 之间。较高的值(如 0.8)将使输出更加随机,而较低的值(如 0.2)将使其更加集中和确定。source

使用温度进行采样的替代方法,称为核抽样,其中模型考虑具有top_p概率质量的标记的结果。所以 0.1 意味着只考虑包含前 10% 概率质量的 token。source

我们通常建议更改此温度或温度,但不能同时更改两者。source

指定模型必须输出的格式。兼容 GPT-4oGPT-4 Turbo 和所有 GPT-3.5 Turbo 型号gpt-3.5-turbo-1106.source

设置为{ "type": "json_schema", "json_schema": {...} }启用结构化输出,以确保模型与您提供的 JSON 架构匹配。在结构化输出指南中了解更多信息。source

设置为{ "type": "json_object" }启用 JSON 模式,以确保模型生成的消息是有效的 JSON。source

重要提示:使用 JSON 模式时,还必须通过系统或用户消息指示模型自行生成 JSON。否则,模型可能会生成无休止的空格流,直到生成达到令牌限制,从而导致长时间运行且似乎“卡住”的请求。另请注意,如果出现以下情况,消息内容可能会被部分截断finish_reason="length",这表示已超过代数max_tokens或对话超过了最大上下文长度。source

OBJECT 辅助对象
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
  "id": "asst_abc123",
  "object": "assistant",
  "created_at": 1698984975,
  "name": "Math Tutor",
  "description": null,
  "model": "gpt-4o",
  "instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
  "tools": [
    {
      "type": "code_interpreter"
    }
  ],
  "metadata": {},
  "top_p": 1.0,
  "temperature": 1.0,
  "response_format": "auto"
}