消息 (v1)Legacy
Legacy
在话题中创建消息
相关指南: 助手
创建消息 (v1)Legacy
Legacy
发布 https://api.openai.com/v1/threads/{thread_id}/messages
创建消息。
路径参数
要为其创建消息的线程的 ID。
请求正文
创建消息的实体的角色。允许的值包括:
user
:表示消息是由实际用户发送的,在大多数情况下应该用于表示用户生成的消息。assistant
:表示消息由助手生成。使用此值可将来自助手的消息插入到对话中。
消息应使用的文件 ID 列表。一条消息最多可以附加 10 个文件。适用于以下工具retrieval
和code_interpreter
可以访问和使用文件。
返回
消息对象。
示例请求
1
2
3
4
5
6
7
8
curl https://api.openai.com/v1/threads/thread_abc123/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v1" \
-d '{
"role": "user",
"content": "How does AI work? Explain it in simple terms."
}'
响应
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": 1699017614,
"thread_id": "thread_abc123",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "How does AI work? Explain it in simple terms.",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}
列出消息 (v1)Legacy
Legacy
获取 https://api.openai.com/v1/threads/{thread_id}/messages
返回给定线程的消息列表。
路径参数
消息所属线程的 ID。
查询参数
用于分页的游标。after
是定义您在列表中的位置的对象 ID。例如,如果您发出列表请求并收到 100 个对象,以 obj_foo 结尾,则您的后续调用可以包含 after=obj_foo 以便获取列表的下一页。
用于分页的游标。before
是定义您在列表中的位置的对象 ID。例如,如果您发出一个列表请求并收到 100 个对象,以 obj_foo 结尾,则您的后续调用可以包含 before=obj_foo 以便获取列表的上一页。
返回
消息对象列表。
示例请求
1
2
3
4
curl https://api.openai.com/v1/threads/thread_abc123/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v1"
响应
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
{
"object": "list",
"data": [
{
"id": "msg_abc123",
"object": "thread.message",
"created_at": 1699016383,
"thread_id": "thread_abc123",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "How does AI work? Explain it in simple terms.",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
},
{
"id": "msg_abc456",
"object": "thread.message",
"created_at": 1699016383,
"thread_id": "thread_abc123",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "Hello, what is AI?",
"annotations": []
}
}
],
"file_ids": [
"file-abc123"
],
"assistant_id": null,
"run_id": null,
"metadata": {}
}
],
"first_id": "msg_abc123",
"last_id": "msg_abc456",
"has_more": false
}
列出消息文件 (v1)Legacy
Legacy
获取 https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files
返回消息文件列表。
查询参数
用于分页的游标。after
是定义您在列表中的位置的对象 ID。例如,如果您发出列表请求并收到 100 个对象,以 obj_foo 结尾,则您的后续调用可以包含 after=obj_foo 以便获取列表的下一页。
返回
消息文件对象列表。
示例请求
1
2
3
4
curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123/files \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-H "OpenAI-Beta: assistants=v1"
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"object": "list",
"data": [
{
"id": "file-abc123",
"object": "thread.message.file",
"created_at": 1699061776,
"message_id": "msg_abc123"
},
{
"id": "file-abc123",
"object": "thread.message.file",
"created_at": 1699061776,
"message_id": "msg_abc123"
}
],
"first_id": "file-abc123",
"last_id": "file-abc123",
"has_more": false
}
检索消息 (v1)Legacy
Legacy
获取 https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}
检索消息。
路径参数
此消息所属的线程的 ID。
返回
与指定 ID 匹配的 message 对象。
示例请求
1
2
3
4
curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v1"
响应
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": 1699017614,
"thread_id": "thread_abc123",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "How does AI work? Explain it in simple terms.",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {}
}
检索消息文件 (v1)Legacy
Legacy
获取 https://api.openai.com/v1/threads/{thread_id}/messages/{message_id}/files/{file_id}
检索消息文件。
返回
消息文件对象。
示例请求
1
2
3
4
curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123/files/file-abc123 \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-H "OpenAI-Beta: assistants=v1"
响应
1
2
3
4
5
6
{
"id": "file-abc123",
"object": "thread.message.file",
"created_at": 1699061776,
"message_id": "msg_abc123"
}
修改消息 (v1)Legacy
Legacy
示例请求
1
2
3
4
5
6
7
8
9
10
curl https://api.openai.com/v1/threads/thread_abc123/messages/msg_abc123 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v1" \
-d '{
"metadata": {
"modified": "true",
"user": "abc123"
}
}'
响应
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
"id": "msg_abc123",
"object": "thread.message",
"created_at": 1699017614,
"thread_id": "thread_abc123",
"role": "user",
"content": [
{
"type": "text",
"text": {
"value": "How does AI work? Explain it in simple terms.",
"annotations": []
}
}
],
"file_ids": [],
"assistant_id": null,
"run_id": null,
"metadata": {
"modified": "true",
"user": "abc123"
}
}
消息对象 (v1)Legacy
Legacy
表示线程中的消息。
OBJECT 消息对象 (v1)
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": []
}
}
],
"file_ids": [],
"assistant_id": "asst_abc123",
"run_id": "run_abc123",
"metadata": {}
}
消息文件对象 (v1)Legacy
Legacy
附加到message
.
OBJECT 消息文件对象 (v1)
1
2
3
4
5
6
7
{
"id": "file-abc123",
"object": "thread.message.file",
"created_at": 1698107661,
"message_id": "message_QLoItBbqwyAJEzlTy4y9kOMM",
"file_id": "file-abc123"
}