Assistants 迁移指南试用版
我们更改了工具和文件在 Assistants API 中的工作方式,从v1
和v2
beta 版本。目前,两个版本的测试版都可以继续通过 API 访问,但我们建议您尽快迁移到最新版本的 API。我们将弃用v1
到 2024 年底测试版。
更改的内容
这v2
版本的 Assistants API 包含以下更改:
- 工具重命名:这
retrieval
工具已重命名为file_search
工具 -
文件属于 tools:文件现在与工具关联,而不是 Assistants 和 Messages。这意味着:
AssistantFile
和MessageFile
对象不再存在。- 而不是
AssistantFile
和MessageFile
,文件使用新的tool_resources
对象。- 这
tool_resources
对于 Code Interpreter 工具,有一个file_ids
. - 这
tool_resources
对于file_search
工具是一个名为vector_stores
.
- 这
- 消息现在具有
attachments
,而不是file_ids
参数。消息附件是将文件添加到 Thread 的tool_resources
.
1
2
3
4
5
6
7
8
9
10
11
12
{
"id": "asst_abc123",
"object": "assistant",
"created_at": 1698984975,
"name": "Math Tutor",
"description": null,
"model": "gpt-4-turbo",
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
"tools": [{ "type": "code_interpreter" }],
"file_ids": [],
"metadata": {}
}
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
{
"id": "asst_abc123",
"object": "assistant",
"created_at": 1698984975,
"name": "Math Tutor",
"description": null,
"model": "gpt-4-turbo",
"instructions": "You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
"tools": [
{
"type": "code_interpreter"
},
{
"type": "file_search"
}
],
"tool_resources": {
"file_search": {
"vector_store_ids": ["vs_abc"]
},
"code_interpreter": {
"file_ids": ["file-123", "file-456"]
}
}
}
助手有tools
和tool_resources
而不是file_ids
.这retrieval
工具现在是file_search
工具。这tool_resource
对于file_search
tool 是一个vector_store
.
1
2
3
4
5
6
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699012949,
"metadata": {}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699012949,
"metadata": {},
"tools": [
{
"type": "file_search"
},
{
"type": "code_interpreter"
}
],
"tool_resources": {
"file_search": {
"vector_store_ids": ["vs_abc"]
},
"code_interpreter": {
"file_ids": ["file-123", "file-456"]
}
}
}
线程可以自带tool_resources
进入对话。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"id": "msg_abc123",
"object": "thread.message",
"created_at": 1698983503,
"thread_id": "thread_abc123",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "Hi! How can I help you today?",
"annotations": []
}
}
],
"assistant_id": "asst_abc123",
"run_id": "run_abc123",
"metadata": {},
"file_ids": []
}
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
{
"id": "msg_abc123",
"object": "thread.message",
"created_at": 1698983503,
"thread_id": "thread_abc123",
"role": "assistant",
"content": [
{
"type": "text",
"text": {
"value": "Hi! How can I help you today?",
"annotations": []
}
}
],
"assistant_id": "asst_abc123",
"run_id": "run_abc123",
"metadata": {},
"attachments": [
{
"file_id": "file-123",
"tools": [
{ "type": "file_search" },
{ "type": "code_interpreter" }
]
}
]
}
消息有attachments
而不是file_ids
.attachments
是将文件添加到线程的tool_resources
.
都v1
Assistants API 的端点和对象可以在 API 参考的 Legacy 部分下找到。
在 v2 中访问 v1 数据
为了简化您在v1
和v2
API,我们会自动映射AssistantFiles
和MessageFiles
到适当的tool_resources
根据在 Assistants 或 Runs 中启用的工具,这些文件是其中的一部分。
v1 版本 | v2 版本 | |
---|---|---|
的 AssistantFilescode_interpreter | file_ids 在 Google 助理上 | Assistant 的tool_resources.code_interpreter |
的 AssistantFilesretrieval | file_ids 在 Google 助理上 | 附加到 Assistant 的 vector_store 中的文件 (tool_resources.file_search ) |
的 MessageFilescode_interpreter | file_ids 在消息上 | 线程的tool_resources.code_interpreter |
的 MessageFilesretrieval | file_ids 在消息上 | 附加到线程 (vector_storetool_resources.file_search ) |
由于 Assistant Files 和 Message Files 已经映射到相应的tool_resources
在v2
,当您准备好迁移到v2
您不必担心数据迁移。相反,您只需:
- 更新您的集成以反映新的 API 和对象。您可能需要执行以下作:
- 升级到最新版本的 SDK
更改 beta 版本
不带 SDK
可以通过在 API 请求中传递正确的 API 版本标头来访问这两个 beta 版本:
v1
:OpenAI-Beta: assistants=v1
v2
:OpenAI-Beta: assistants=v2
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-4-turbo"
}'
使用 SDK
在v2
beta 将具有openai.beta
Namespace
指向v2
版本。您仍然可以访问v1
版本的API,使用较旧的
SDK 版本(Python 为 1.20.0 或更早版本,Node 为 4.36.0 或更早版本)或覆盖版本标头。
要安装旧版本的 SDK,您可以使用以下命令:
pip install openai==1.20.0
您也可以在较新的 SDK 版本中覆盖此标头,但我们不建议使用此方法,因为这些较新的 SDK 版本中的对象类型将与v1
对象。
1
2
3
from openai import OpenAI
client = OpenAI(default_headers={"OpenAI-Beta": "assistants=v1"})
计费
在v2
API(2024 年 4 月 17 日)将免费使用至 2024 年底。这意味着,由于我们将v1
data 到v2
,在v2
Launch 将是免费的。2024 年底之后,他们将按照届时载体商店的任何费用收费。有关最新的定价信息,请参阅我们的定价页面。
在发布v2
API(2024 年 4 月 17 日),但在该发布日期至 2024 年底之间未在单次运行中使用过的 API 将被删除。这是为了避免我们开始向您收取您在 Beta 版期间创建但从未使用过的内容的费用。
在v2
API 将按定价页面上指定的当前费率计费。
删除文件
通过 删除 Assistant 文件 / 消息文件v1
API 还会将它们从v2
应用程序接口。但是,反之则不然 - 删除v2
版本的 API 不会传播到v1
.如果您在v1
并希望从您的帐户中“完全”删除文件v1
和v2
您应该:
- 删除您使用创建的 Assistant 文件 / 消息文件
v1
使用v1
endpoints 或 - delete the underlying file object (删除底层文件对象) — 这可确保将其从 API 的所有版本中的所有对象中完全删除。
操场
默认 Playground 体验已迁移为使用v2
版本(您仍将拥有v1
版本,但无法编辑它们)。您通过 Playground 对工具和文件所做的任何更改都只能在v2
API 的版本。
要更改v1
版本,则需要直接使用 API。