跳到主要内容

文本生成

请求方法

POST

请求地址

https://api.lanrui.co/v1/chat/completions
CURL 示例
curl -X POST https://api.lanrui.co/v1/chat/completions \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {填入API Key,删除花括号}' \
--data '{
"stream": true,
"model": "{填入推理服务所对应的模型名称,具体格式为model_name/model_version,删除花括号}",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}'

请求 Body 参数(application/json)

参数名参数类型取值范围参数释义是否必填
modelstring要使用的模型的ID
messagelist<dict>调用语言模型时,将当前对话信息列表作为提示输入给模型。其中的元素按照 {"role": "user", "content": "Hello!"} 的形式传参,role可选择systemuserassistant其中之一; content为字符串类型
temperaturefloat默认值: 1
取值范围: [0.0, 2.0]
要使用的采样温度(temperature),介于 0 和 2 之间。较高的值(如 0.8)会使输出更随机,而较低的值(如 0.2)则会使其更加专注和确定。建议只修改此参数或 top_p 一个参数
top_pfloat默认值: 1
取值范围: (0.0, 1.0]
一种称为“核心采样”的采样替代方法,其中模型考虑概率质量值在前 top_p 的标记的结果。因此,0.1 意味着仅考虑概率质量值前 10% 的标记。
streamboolean默认值: false
如果设置为 true,则模型输出以流模式返回
max_tokensinteger默认值: inf
要生成的最大token数
presence_penaltyfloat默认值: 0
取值范围: [-2.0, 2.0]
正值会根据新标记在迄今为止的文本中出现的频率惩罚新标记,增加模型谈论新话题的可能性
frequency_penaltyfloat默认值: 0
取值范围: [-2.0, 2.0]
正值会根据其在文本中的现有频率惩罚新标记,从而减少模型重复同一行的可能性

非流式调用响应

{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "meta-llama/Llama-2-7b-chat-hf",
"system_fingerprint": "fp_44709d6fcb",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "\n\nHello there, how may I assist you today?",
},
"logprobs": null,
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 12,
"total_tokens": 21
}
}

流式调用响应

{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"meta-llama/Llama-2-7b-chat-hf", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}

{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"meta-llama/Llama-2-7b-chat-hf", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]}

....

{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"meta-llama/Llama-2-7b-chat-hf", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}