Skip to content

结构化输出(JSON Mode) ​

  • 接口:POST https://api.olddog.shop/v1/chat/completions
  • 用途:要求模型输出严格 JSON,便于程序解析与落库(兼容 OpenAI JSON Mode 思路)。

提示:使用 JSON Mode 时,建议在 system 或 user 提示词中明确“只输出 JSON,不要输出额外文本”。

请求参数(常用组合) ​

参数名类型是否必填说明
modelstring是模型 ID。
messagesarray是对话消息。
response_formatobject否结构化输出格式,例如 { "type": "json_object" }。
temperaturenumber否建议设置较低(如 0)以提升稳定性。

cURL 示例(只输出 JSON) ​

bash
curl --request POST "https://api.olddog.shop/v1/chat/completions" \
  --header "Authorization: Bearer $OLD_DOG_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "model": "gpt-4o-mini",
    "response_format": { "type": "json_object" },
    "messages": [
      {
        "role": "system",
        "content": "你是数据提取器。只输出 JSON,不要输出任何解释性文字。"
      },
      {
        "role": "user",
        "content": "从这段话里提取姓名和手机号:张三的电话是 13800138000。"
      }
    ],
    "temperature": 0
  }'