gpt-oss 中如何处理原始思维链
gpt-oss 模型 提供了一个原始思维链(CoT),供模型实现者进行分析和安全研究,但它对于工具调用的性能也至关重要,因为工具调用可以作为 CoT 的一部分执行。同时,原始 CoT 可能包含潜在的有害内容,或者向用户透露模型实现者可能不打算透露的信息(例如模型指令中指定的规则)。因此,您不应向最终用户展示原始 CoT。
Harmony / 聊天模板处理
模型将原始 CoT 编码为我们 harmony 响应格式 的一部分。如果您正在编写自己的聊天模板或直接处理 token,请务必先查看 harmony 指南。
总结几点:
- CoT 将在
analysis
通道中发出 - 在后续采样轮次中,
final
通道中的消息之后,所有analysis
消息都应被删除。commentary
通道中的函数调用可以保留 - 如果助手的最后一条消息是任何类型的工具调用,则应在后续采样中保留直到上一条
final
消息之前的分析消息,直到发出final
消息
Chat Completions API
如果您正在实现 Chat Completions API,在 OpenAI 已发布的规范中没有处理思维链的官方规范,因为我们托管的模型目前不会提供此功能。我们要求您遵循OpenRouter 的以下约定。包括:
- 除非在请求中指定了
reasoning: { exclude: true }
,否则原始 CoT 将作为响应的一部分返回。在此处查看详细信息 - 原始 CoT 作为输出消息中的
reasoning
属性公开 - 对于增量事件,增量具有
reasoning
属性 - 在后续轮次中,您应该能够接收先前的推理(作为
reasoning
)并根据聊天模板部分中指定的行为进行处理。
如有疑问,请遵循 OpenRouter 实现的约定/行为。
Responses API
对于 Responses API,我们已扩展我们的 Responses API 规范以涵盖此情况。以下是规范的类型定义更改。总的来说,我们正在:
- 在
reasoning
上引入新的content
属性。这允许在返回原始 CoT(不应向最终用户显示,但可能有助于可解释性研究)的同时返回一个可以显示给最终用户的推理summary
。 - 引入一种名为
reasoning_text
的新内容类型 - 引入两个新事件
response.reasoning_text.delta
来流式传输原始 CoT 的增量,以及response.reasoning_text.done
来指示要完成的 CoT 轮次 - 在后续轮次中,您应该能够接收先前的推理并根据聊天模板部分中指定的行为进行处理。
项目类型更改
type ReasoningItem = {
id: string;
type: "reasoning";
summary: SummaryContent[];
// new
content: ReasoningTextContent[];
};
type ReasoningTextContent = {
type: "reasoning_text";
text: string;
};
type ReasoningTextDeltaEvent = {
type: "response.reasoning_text.delta";
sequence_number: number;
item_id: string;
output_index: number;
content_index: number;
delta: string;
};
type ReasoningTextDoneEvent = {
type: "response.reasoning_text.done";
sequence_number: number;
item_id: string;
output_index: number;
content_index: number;
text: string;
};
事件更改
...
{
type: "response.content_part.added"
...
}
{
type: "response.reasoning_text.delta",
sequence_number: 14,
item_id: "rs_67f47a642e788191aec9b5c1a35ab3c3016f2c95937d6e91",
output_index: 0,
content_index: 0,
delta: "The "
}
...
{
type: "response.reasoning_text.done",
sequence_number: 18,
item_id: "rs_67f47a642e788191aec9b5c1a35ab3c3016f2c95937d6e91",
output_index: 0,
content_index: 0,
text: "The user asked me to think"
}
示例响应输出
"output": [
{
"type": "reasoning",
"id": "rs_67f47a642e788191aec9b5c1a35ab3c3016f2c95937d6e91",
"summary": [
{
"type": "summary_text",
"text": "**Calculating volume of gold for Pluto layer**\n\nStarting with the approximation..."
}
],
"content": [
{
"type": "reasoning_text",
"text": "The user asked me to think..."
}
]
}
]
向最终用户显示原始 CoT
如果您向用户提供聊天界面,则不应显示原始 CoT,因为它可能包含潜在的有害内容或其他您可能不打算向用户显示的信息(例如,开发者消息中的说明)。相反,我们建议显示一个摘要 CoT,类似于我们在 API 或 ChatGPT 中的生产实现,其中摘要模型会进行审查并阻止有害内容显示。