线程试用版
试用版
创建助理可以与之交互的线程。
相关指南: 助手
创建线程试用版
试用版
POST https://api.openai.com/v1/threads
创建线程。
请求正文
要开始线程的消息列表。
在此线程中可供 Assistant 工具使用的一组资源。这些资源特定于工具类型。例如,code_interpreter
工具需要文件 ID 列表,而file_search
工具需要矢量存储 ID 列表。
返回
线程对象。
示例请求
1
2
3
4
5
curl https://api.openai.com/v1/threads \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2" \
-d ''
响应
1
2
3
4
5
6
7
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699012949,
"metadata": {},
"tool_resources": {}
}
检索线程试用版
试用版
示例请求
1
2
3
4
curl https://api.openai.com/v1/threads/thread_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
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699014083,
"metadata": {},
"tool_resources": {
"code_interpreter": {
"file_ids": []
}
}
}
修改线程试用版
试用版
示例请求
1
2
3
4
5
6
7
8
9
10
curl https://api.openai.com/v1/threads/thread_abc123 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2" \
-d '{
"metadata": {
"modified": "true",
"user": "abc123"
}
}'
响应
1
2
3
4
5
6
7
8
9
10
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1699014083,
"metadata": {
"modified": "true",
"user": "abc123"
},
"tool_resources": {}
}
删除线程试用版
试用版
示例请求
1
2
3
4
5
curl https://api.openai.com/v1/threads/thread_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": "thread_abc123",
"object": "thread.deleted",
"deleted": true
}
thread 对象试用版
试用版
表示包含消息的线程。
OBJECT 线程对象
1
2
3
4
5
6
{
"id": "thread_abc123",
"object": "thread",
"created_at": 1698107661,
"metadata": {}
}