使用样例
单轮对话:
单模态模型:
{
"model": "DeepSeek-R1",
"messages": [{
"role": "user",
"content": "You are a helpful assistant."
}],
"stream": false,
"presence_penalty": 1.03,
"frequency_penalty": 1.0,
"repetition_penalty": 1.0,
"temperature": 0.5,
"top_p": 0.95,
"top_k": 0,
"seed": null,
"stop": ["stop1", "stop2"],
"stop_token_ids": [2, 13],
"include_stop_str_in_output": false,
"skip_special_tokens": true,
"ignore_eos": false,
"max_tokens": 20
}
多模态模型:
说明: “image_url”参数的取值请根据实际情况进行修改。
{
"model": "DeepSeek-R1",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "My name is Olivier and I"},
{"type": "image_url", "image_url": "/xxxx/test.png"}
]
}],
"stream": false,
"presence_penalty": 1.03,
"frequency_penalty": 1.0,
"repetition_penalty": 1.0,
"temperature": 0.5,
"top_p": 0.95,
"top_k": 0,
"seed": null,
"stop": ["stop1", "stop2"],
"stop_token_ids": [2, 13],
"include_stop_str_in_output": false,
"skip_special_tokens": true,
"ignore_eos": false,
"max_tokens": 20
}
多轮对话
请求样例1:
{
"model": "DeepSeek-R1",
"messages": [{
"role": "system",
"content": "You are a helpful customer support assistant. Use the supplied tools to assist the user."
},
{
"role": "user",
"content": "Hi, can you tell me the delivery date for my order? my order id is 12345."
}
],
"stream": false,
"presence_penalty": 1.03,
"frequency_penalty": 1.0,
"repetition_penalty": 1.0,
"temperature": 0.5,
"top_p": 0.95,
"top_k": 0,
"seed": null,
"stop": ["stop1", "stop2"],
"stop_token_ids": [2],
"ignore_eos": false,
"max_tokens": 1024,
"tools": [
{
"type": "function",
"function": {
"name": "get_delivery_date",
"strict": true,
"description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'",
"parameters": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The customer's order ID."
}
},
"required": [
"order_id"
],
"additionalProperties": false
}
}
}
],
"tool_choice": "auto"
}
请求样例2:
{
"model": "DeepSeek-R1",
"messages": [
{
"role": "system",
"content": "You are a helpful customer support assistant. Use the supplied tools to assist the user."
},
{
"role": "user",
"content": "Hi, can you tell me the delivery date for my order? my order id is 12345."
},
{
"role": "assistant",
"tool_calls": [
{
"function": {
"arguments": "{\"order_id\": \"12345\"}",
"name": "get_delivery_date"
},
"id": "tool_call_8p2Nk",
"type": "function"
}
]
},
{
"role": "tool",
"content": "the delivery date is 2024.09.10.",
"tool_call_id": "tool_call_8p2Nk"
}
],
"stream": false,
"repetition_penalty": 1.1,
"temperature": 0.9,
"top_p": 1,
"max_tokens": 1024,
"tools": [
{
"type": "function",
"function": {
"name": "get_delivery_date",
"strict": true,
"description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'",
"parameters": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The customer's order ID."
}
},
"required": [
"order_id"
],
"additionalProperties": false
}
}
}
],
"tool_choice": "auto"
}
响应样例:
文本推理(“stream”=false):
单轮对话:
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "DeepSeek-R1",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
},
"prefill_time": 200,
"decode_time_arr": [56, 28, 28]
}
多轮对话:
响应样例1:
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "DeepSeek-R1",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "",
"tool_calls": [
{
"function": {
"arguments": "{\"order_id\": \"12345\"}",
"name": "get_delivery_date"
},
"id": "call_JwmTNF3O",
"type": "function"
}
]
},
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": 226,
"completion_tokens": 122,
"total_tokens": 348
},
"prefill_time": 200,
"decode_time_arr": [56, 28, 28]
}
响应样例2:
{
"id": "endpoint_common_25",
"object": "chat.completion",
"created": 1728959154,
"model": "DeepSeek-R1",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "\n Your order with ID 12345 is scheduled for delivery on September 10th, 2024.",
"tool_calls": null
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 265,
"completion_tokens": 30,
"total_tokens": 295
},
"prefill_time": 200,
"decode_time_arr": [56, 28, 28]
}
流式推理:
流式推理1
(“stream”=true,使用sse格式返回):
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"\t"},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"\t"},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"endpoint_common_8","object":"chat.completion.chunk","created":1729614610,"model":"DeepSeek-R1","usage":{"prompt_tokens":54,"completion_tokens":17,"total_tokens":71},"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}]}
data: [DONE]
流式推理2
(“stream”=true,配置项“fullTextEnabled”=true,使用sse格式返回):
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello!"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How can"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How can I"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How can I assist"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How can I assist you"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How can I assist you today"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How can I assist you today?"},"finish_reason":null}]}
data: {"id":"endpoint_common_11","object":"chat.completion.chunk","created":1730184192,"model":"DeepSeek-R1","full_text":"Hello! How can I assist you today?","usage":{"prompt_tokens":31,"completion_tokens":10,"total_tokens":41},"choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How can I assist you today?"},"finish_reason":"length"}]}
data: [DONE]
输出说明
表1
文本推理结果说明
参数名 | 类型 | 说明 | ||||
---|---|---|---|---|---|---|
id | string | 请求ID。 | ||||
object | string | 返回结果类型目前都返回”chat.completion”。 | ||||
created | integer | 推理请求时间戳,精确到秒。 | ||||
model | string | 使用的推理模型。 | ||||
choices | list | 推理结果列表。 | ||||
- | index | integer | choices消息index,当前只能为0。 | |||
message | object | 推理消息。 | ||||
- | role | string | 角色,目前都返回”assistant”。 | |||
content | string | 推理文本结果。 | ||||
tool_calls | list | 模型工具调用输出。 | ||||
- | function | dict | 函数调用说明。 | |||
- | arguments | string | 调用函数的参数,JSON格式的字符串。 | |||
name | string | 调用的函数名。 | ||||
id | string | 模型调用工具的ID。 | ||||
type | string | 工具的类型,目前仅支持function。 | ||||
finish_reason | string | 结束原因。
| ||||
usage | object | 推理结果统计数据。 | ||||
- | prompt_tokens | int | 用户输入的prompt文本对应的token长度。 | |||
completion_tokens | int | 推理结果token数量。PD场景下统计P和D推理结果的总token数量。当一个请求的推理长度上限取maxIterTimes的值时,D节点响应中completion_tokens数量为maxIterTimes+1,即增加了P推理结果的首token数量。 | ||||
total_tokens | int | 请求和推理的总token数。 | ||||
prefill_time | float | 推理首token时延。 | ||||
decode_time_arr | list | 推理Decode时延数组。 |
表2
流式推理结果说明
参数名 | 类型 | 说明 | |||
---|---|---|---|---|---|
data | object | 一次推理返回的结果。 | |||
- | id | string | 请求ID。 | ||
object | string | 目前都返回”chat.completion.chunk”。 | |||
created | integer | 推理请求时间戳,精确到秒。 | |||
model | string | 使用的推理模型。 | |||
full_text | string | 全量文本结果,配置项“fullTextEnabled”=true时才有此返回值。 | |||
usage | object | 推理结果统计数据。 | |||
- | prompt_tokens | int | 用户输入的prompt文本对应的token长度。 | ||
completion_tokens | int | 推理结果token数量。PD场景下统计P和D推理结果的总token数量。当一个请求的推理长度上限取maxIterTimes的值时,D节点响应中completion_tokens数量为maxIterTimes+1,即增加了P推理结果的首token数量。 | |||
total_tokens | int | 请求和推理的总token数。 | |||
choices | list | 流式推理结果。 | |||
- | index | integer | choices消息index,当前只能为0。 | ||
delta | object | 推理返回结果,最后一个响应为空。 | |||
- | role | string | 角色,目前都返回”assistant”。 | ||
content | string | 推理文本结果。 | |||
finish_reason | string | 结束原因,只在最后一次推理结果返回。
|