结构化输出
结构化输出是一项高级功能,能够让 AI 模型生成格式化的、可预测的响应内容。通过使用结构化输出,您可以更好地控制 AI 输出的格式,使其更适合程序处理和数据分析。
ConsoleX AI提供了结构化输出的调试功能,目前仅支持OpenAI模型。
使用方法
1. 启用JSON Mode
在选择OpenAI支持结构化输出的模型时,点击右上角的更多选项图标,可以找到Enable JSON Mode的开关。打开之后,您还可以选择附加特定的JSON Schema。
- 如果附加,大模型会依据附加的JSON Schema提供生成结果;
- 如果不附加,大模型会依据用户的问题指令生成相应的生成结果。这时在用户的指令中应尽量明确告知模型输出JSON结构的结果(否则模型可能会报错)。
2. 定义JSON Schema(可选)
您还可以定义并在对话中使用JSON Schema描述,更精确的指示模型生成特定结构的JSON结果。
JSON Schema的定义和使用方式参见OpenAI关于JSON schemas的文档说明。
例如:以下是一段用于描述数学问题推理过程的JSON schema描述示例:
{
"name": "math_response",
"strict": true,
"schema":
{
"type": "object",
"properties":
{
"steps":
{
"type": "array",
"items":
{
"type": "object",
"properties":
{
"explanation":
{
"type": "string"
},
"output":
{
"type": "string"
}
},
"required": ["explanation", "output"],
"additionalProperties": false
}
},
"final_answer":
{
"type": "string"
}
},
"required": ["steps", "final_answer"],
"additionalProperties": false
}
}
3. 向大模型提问
假设刚才的JSON Schema已经附加到了对话中,以下是一个示例问题:
Solve the linear equations (2x + 3y = 6) and (x - y = 3)
大模型会依据您提供的JSON schema提供生成结果,以下是一个示例回答:
{
"steps": [
{
"explanation": "Step 1: Use substitution or elimination method to solve the system of equations.",
"output": "First step"
},
{
"explanation": "Step 2: From the second equation, solve for x: x = y + 3",
"output": "x = y + 3"
},
{
"explanation": "Step 3: Substitute x = y + 3 into the first equation: 2(y + 3) + 3y = 6",
"output": "2y + 6 + 3y = 6"
},
{
"explanation": "Step 4: Combine like terms: 5y + 6 = 6",
"output": "5y + 6 = 6"
},
{
"explanation": "Step 5: Solve for y by isolating the variable: 5y = 0",
"output": "y = 0"
},
{
"explanation": "Step 6: Substitute y = 0 into x = y + 3 to solve for x: x = 0 + 3",
"output": "x = 3"
}
],
"final_answer": "x = 3, y = 0"
}