对话补全
POST/chat/completions
根据输入的上下文,来让模型补全对话内容。
Request
- application/json
Body
required
Array [
- System message
- User message
- Assistant message
]
- MOD1
- MOD2
Array [
]
messages
object[]
required
Possible values: >= 1
对话的消息列表。
oneOf
system 消息的内容。
Possible values: [system
]
该消息的发起角色,其值为 system
。
可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者。
user 消息的内容。
Possible values: [user
]
该消息的发起角色,其值为 user
。
可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者。
assistant 消息的内容。
Possible values: [assistant
]
该消息的发起角色,其值为 assistant
。
可以选填的参与者的名称,为模型提供信息以区分相同角色的参与者。
Possible values: [deepseek-chat
, deepseek-coder
]
使用的模型的 ID。您可以使用 deepseek-chat 或者 deepseek-coder。
Possible values: >= -2
and <= 2
Default value: 0
介于 -2.0 和 2.0 之间的数字。如果该值为正,那么新 token 会根据其在已有文本中的出现频率受到相应的惩罚,降低模型重复相同内容的可能性。
Possible values: > 1
限制一次请求中模型生成 completion 的最大 token 数。输入 token 和输出 token 的总长度受模型的上下文长度的限制。
Possible values: >= -2
and <= 2
Default value: 0
介于 -2.0 和 2.0 之间的数字。如果该值为正,那么新 token 会根据其是否已在已有文本中出现受到相应的惩罚,从而增加模型谈论新主题的可能性。
stop
object
一个 string 或最多包含 8 个 string 的 list,在遇到这些词时,API 将停止生成更多的 token。
oneOf
string
string
如果设置为 True,将会以 SSE(server-sent events)的形式以流式发送消息增量。消息流以 data: [DONE]
结尾。
Possible values: <= 2
Default value: 1
采样温度,介于 0 和 2 之间。更高的值,如 0.8,会使输出更随机,而更低的值,如 0.2,会使其更加集中和确定。 我们通常建议可以更改这个值或者更改 top_p
,但不建议同时对两者进行修改。
Possible values: <= 1
Default value: 1
作为调节采样温度的替代方案,模型会考虑前 top_p
概率的 token 的结果。所以 0.1 就意味着只有包括在最高 10% 概率中的 token 会被考虑。 我们通常建议修改这个值或者更改 temperature
,但不建议同时对两者进行修改。
是否返回所输出 token 的对数概率。如果为 true,则在 message
的 content
中返回每个输出 token 的对数概率。
Possible values: <= 20
一个介于 0 到 20 之间的整数 N,指定每个输出位置返回输出概率 top N 的 token,且返回这些 token 的对数概率。指定此参数时,logprobs 必须为 true。
Responses
- 200 (No streaming)
- 200 (Streaming)
OK, 返回一个 chat completion
对象。
- application/json
- Schema
- Example (from schema)
- Example
Schema
Array [
Array [
Array [
]
]
]
该对话的唯一标识符。
choices
object[]
required
模型生成的 completion 的选择列表。
Possible values: [stop
, length
, content_filter
]
模型停止生成 token 的原因。
stop
:模型自然停止生成,或遇到 stop
序列中列出的字符串。
length
:输出长度达到了模型上下文长度限制,或达到了 max_tokens
的限制。
content_filter
:输出内容因触发过滤策略而被过滤。
该 completion 在模型生成的 completion 的选择列表中的索引。
message
object
required
模型生成的 completion 消息。
该 completion 的内容。
Possible values: [assistant
]
生成这条消息的角色。
logprobs
object
nullable
required
该 choice 的对数概率信息。
content
object[]
nullable
required
一个包含输出 token 对数概率信息的列表。
输出的 token。
该 token 的对数概率。-9999.0
代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 null
。
top_logprobs
object[]
required
一个包含在该输出位置上,输出概率 top N 的 token 的列表,以及它们的对数概率。在罕见情况下,返回的 token 数量可能少于请求参数中指定的 top_logprobs
值。
输出的 token。
该 token 的对数概率。-9999.0
代表该 token 的输出概率极小,不在 top 20 最可能输出的 token 中。
一个包含该 token UTF-8 字节表示的整数列表。一般在一个 UTF-8 字符被拆分成多个 token 来表示时有用。如果 token 没有对应的字节表示,则该值为 null
。
创建聊天完成时的 Unix 时间戳(以秒为单位)。
生成该 completion 的模型名。
This fingerprint represents the backend configuration that the model runs with.
Possible values: [chat.completion
]
对象的类型, 其值为 chat.completion
。
usage
object
该对话补全请求的用量信息。
模型 completion 产生的 token 数。
用户 prompt 所包含的 token 数。
该请求中,所有 token 的数量(prompt + completion)。
{
"id": "string",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "string",
"role": "assistant"
},
"logprobs": {
"content": [
{
"token": "string",
"logprob": 0,
"bytes": [
0
],
"top_logprobs": [
{
"token": "string",
"logprob": 0,
"bytes": [
0
]
}
]
}
]
}
}
],
"created": 0,
"model": "string",
"system_fingerprint": "string",
"object": "chat.completion",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0
}
}
{
"id": "930c60df-bf64-41c9-a88e-3ec75f81e00e",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Hello! How can I help you today?",
"role": "assistant"
}
}
],
"created": 1705651092,
"model": "deepseek-chat",
"object": "chat.completion",
"usage": {
"completion_tokens": 10,
"prompt_tokens": 16,
"total_tokens": 26
}
}
OK, 返回包含一系列 chat completion chunk
对象的流式输出。
- text/event-stream
- Schema
- Example
Schema
Array [
Array [
]
]
该对话的唯一标识符。
choices
object[]
required
模型生成的 completion 的选择列表。
delta
object
required
流式返回的一个 completion 增量。
completion 增量的内容。
Possible values: [assistant
]
产生这条消息的角色。
Possible values: [stop
, length
, content_filter
]
模型停止生成 token 的原因。
stop
:模型自然停止生成,或遇到 stop
序列中列出的字符串。
length
:输出长度达到了模型上下文长度限制,或达到了 max_tokens
的限制。
content_filter
:输出内容因触发过滤策略而被过滤。
该 completion 在模型生成的 completion 的选择列表中的索引。
创建聊天完成时的 Unix 时间戳(以秒为单位)。流式响应的每个 chunk 的时间戳相同。
生成该 completion 的模型名。
This fingerprint represents the backend configuration that the model runs with.
Possible values: [chat.completion.chunk
]
对象的类型, 其值为 chat.completion.chunk
。
data: {"id": "1f633d8bfc032625086f14113c411638", "choices": [{"index": 0, "delta": {"content": "", "role": "assistant"}, "finish_reason": null, "logprobs": null}], "created": 1718345013, "model": "deepseek-chat", "system_fingerprint": "fp_a49d71b8a1", "object": "chat.completion.chunk", "usage": null}
data: {"choices": [{"delta": {"content": "Hello", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": "!", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": " How", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": " can", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": " I", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": " assist", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": " you", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": " today", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": "?", "role": "assistant"}, "finish_reason": null, "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1"}
data: {"choices": [{"delta": {"content": "", "role": null}, "finish_reason": "stop", "index": 0, "logprobs": null}], "created": 1718345013, "id": "1f633d8bfc032625086f14113c411638", "model": "deepseek-chat", "object": "chat.completion.chunk", "system_fingerprint": "fp_a49d71b8a1", "usage": {"completion_tokens": 9, "prompt_tokens": 17, "total_tokens": 26}}
data: [DONE]