零度API 文档
POST

gpt-3.5-turbo-instruct

POST /v1/completions — 旧版指令完成接口(Instruct 格式)

gpt-3.5-turbo-instruct

旧版 Completions API(非 Chat 格式),适用于单轮指令补全场景。与 Chat Completions 不同,此接口接受单个 prompt 字符串而非消息数组。

POST https://api000.com/v1/completions

请求参数

参数 类型 必填 说明
model string 模型 ID,如 gpt-3.5-turbo-instruct
prompt string / array 输入提示词(字符串或字符串数组)
max_tokens integer 可选 最大生成 Token 数,默认 16
temperature number 可选 采样温度 0-2,默认 1
top_p number 可选 核采样,默认 1
n integer 可选 生成候选数量,默认 1
stream boolean 可选 是否流式返回,默认 false
stop string / array 可选 最多 4 个停止词
presence_penalty number 可选 存在惩罚 -2.0 到 2.0
frequency_penalty number 可选 频率惩罚 -2.0 到 2.0
suffix string 可选 插入补全后的后缀文本
echo boolean 可选 是否在响应中回显提示词,默认 false
logprobs integer 可选 返回每个位置的 top-N 对数概率

请求示例

cURL

curl https://api000.com/v1/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxxxxxxxx" \
  -d '{
    "model": "gpt-3.5-turbo-instruct",
    "prompt": "Say this is a test",
    "max_tokens": 7,
    "temperature": 0
  }'

Python

from openai import OpenAI

client = OpenAI(base_url="https://api000.com/v1", api_key="sk-xxxxxxxxxxxxxxxx")

response = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt="Translate to Chinese: Hello, world!",
    max_tokens=50,
    temperature=0.7
)
print(response.choices[0].text)

批量 Prompt

response = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt=[
        "Write a tagline for an ice cream shop: ",
        "Write a tagline for a coffee shop: ",
    ],
    max_tokens=30
)
for choice in response.choices:
    print(choice.text.strip())

响应示例

{
  "id": "cmpl-abc123",
  "object": "text_completion",
  "created": 1677652288,
  "model": "gpt-3.5-turbo-instruct",
  "choices": [
    {
      "text": " This is indeed a test",
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 5,
    "total_tokens": 10
  }
}

响应字段说明

字段 类型 说明
object string 固定为 "text_completion"
choices[].text string 生成的补全文本
choices[].finish_reason string 结束原因:stop / length

注意: 与 Chat Completions 响应的区别:此接口返回 choices[].text,而 Chat 接口返回 choices[].message.content


与 Chat 接口对比

gpt-3.5-turbo-instruct Chat Completions
端点 /v1/completions /v1/chat/completions
输入格式 prompt 字符串 messages 数组
输出字段 choices[].text choices[].message.content
适用场景 单轮指令补全 多轮对话
零度API 文档