6. 结构化输出(Structured Outputs)


功能介绍

结构化输出功能允许用户指定模型以严格的 JSON Schema 格式返回数据,确保输出结果的格式完全可预测、可解析。这对于将 AI 集成到自动化流程中至关重要——当用户的程序需要解析 AI 的回答时,结构化输出能保证数据格式的一致性和可靠性。

在右侧「Run settings(运行设置)」面板的「Tools(工具)」区域中,开启「Structured outputs(结构化输出)」开关,然后点击「Edit(编辑)」定义输出的 JSON Schema。

如何使用

image-20260330173214002

在「Tools(工具)」中打开「Structured outputs(结构化输出)」,选中后对话框下方会显示蓝色的标签。

image-20260330173325499

点击「Edit(编辑)」。

image-20260330175330912

定义 JSON Schema,指定字段名称、类型和描述。

image-20260330175403251

模型的回答将严格按照定义的 Schema 格式返回。

适用场景

场景Schema 设计思路
产品数据提取定义 name、price、category 等字段
情感分析定义 sentiment(正面/中立/负面)和 score 字段
实体识别定义 entities 数组,包含 name、type、context
内容分类定义 category、confidence、tags 字段
多语言翻译定义 original、translated、language 字段

示例

示例一:产品信息提取

请从以下商品描述中提取结构化信息:
“全新 iPhone 16 Pro Max 256GB 深空黑色,A18 Pro 芯片,6.9英寸超视网膜XDR显示屏,支持Apple Intelligence,售价 9999 元。”

{
  "type": "object",
  "properties": {
    "product_name": { "type": "string" },
    "storage": { "type": "string" },
    "color": { "type": "string" },
    "price": { "type": "number" },
    "key_features": {
      "type": "array",
      "items": { "type": "string" }
    }
  }
}

示例二:评论情感分析

分析以下用户评论的情感倾向:

“这家餐厅的环境很好,服务也不错,但是菜品味道一般,价格偏贵,整体性价比不高。”


{
  "type": "object",
  "properties": {
    "overall_sentiment": { "type": "string" },
    "score": { "type": "number" },
    "positive_aspects": {
      "type": "array",
      "items": { "type": "string" }
    },
    "negative_aspects": {
      "type": "array",
      "items": { "type": "string" }
    }
  }
}

示例三:简历信息解析

“张三,男,1995年出生,硕士学历,毕业于北京大学计算机科学专业。5年Python开发经验,擅长机器学习和数据分析。现就职于某互联网大厂,担任高级工程师。”


{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "gender": { "type": "string" },
    "birth_year": { "type": "number" },
    "education": { "type": "string" },
    "university": { "type": "string" },
    "major": { "type": "string" },
    "experience_years": { "type": "number" },
    "skills": {
      "type": "array",
      "items": { "type": "string" }
    },
    "current_position": { "type": "string" }
  }
}

示例四:文章关键词提取

提取以下文章的元数据:

[粘贴文章内容]


{
  "type": "object",
  "properties": {
    "title": { "type": "string" },
    "summary": { "type": "string" },
    "keywords": {
      "type": "array",
      "items": { "type": "string" }
    },
    "category": { "type": "string" },
    "reading_time_minutes": { "type": "number" },
    "difficulty_level": { "type": "string" }
  }
}

示例五:多语言翻译

将以下句子翻译成英语、日语和韩语:

“人工智能正在深刻改变我们的生活方式。”


{
  "type": "object",
  "properties": {
    "original": { "type": "string" },
    "translations": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "language": { "type": "string" },
          "text": { "type": "string" },
          "romanization": { "type": "string" }
        }
      }
    }
  }
}

评论

0
还没有评论,来写第一条吧