外观
文本补全(旧版)
POST
https://vip.zen-ai.top/v1/completions旧版的 Completions 接口:输入一段提示词,模型返回续写的文本。仅少数模型(如 gpt-3.5-turbo-instruct)支持,新项目请使用 创建聊天补全。
请求体
modelstring必填模型名称,如 gpt-3.5-turbo-instruct。
promptstring | array必填提示词,可以是字符串或字符串数组。
max_tokensinteger默认 16生成的最大 token 数。
temperaturenumber默认 1采样温度,0–2。
top_pnumber默认 1核采样。
ninteger默认 1生成几条结果。
streamboolean默认 false是否流式返回。
stopstring | array停止序列,最多 4 个。
suffixstring插入文本之后的后缀。
echoboolean默认 false是否在结果中回显提示词。
presence_penaltynumber取值 -2.0–2.0。
frequency_penaltynumber取值 -2.0–2.0。
响应
idstring请求 ID。
objectstring固定为 text_completion。
choicesarray每项包含 text(续写文本)、index、finish_reason。
usageobjecttoken 用量。
请求示例
bash
curl https://vip.zen-ai.top/v1/completions \
-H "Authorization: Bearer $VIP_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "床前明月光,",
"max_tokens": 64
}'python
from openai import OpenAI
client = OpenAI(base_url="https://vip.zen-ai.top/v1", api_key="sk-xxxxxxxx")
resp = client.completions.create(
model="gpt-3.5-turbo-instruct",
prompt="床前明月光,",
max_tokens=64,
)
print(resp.choices[0].text)响应示例
json
{
"id": "cmpl-9f2c3b1a",
"object": "text_completion",
"created": 1790684800,
"model": "gpt-3.5-turbo-instruct",
"choices": [
{ "text": "疑是地上霜。举头望明月,低头思故乡。", "index": 0, "logprobs": null, "finish_reason": "stop" }
],
"usage": { "prompt_tokens": 7, "completion_tokens": 21, "total_tokens": 28 }
}