Skip to content

Commit b8f0f1b

Browse files
authored
Merge branch 'main' into dwigg/temporal-agents-fixes
2 parents 92a5441 + 2fa591f commit b8f0f1b

File tree

173 files changed

+20130
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+20130
-10
lines changed

articles/gpt-oss/fine-tune-transfomers.ipynb

Lines changed: 673 additions & 0 deletions
Large diffs are not rendered by default.

articles/gpt-oss/handle-raw-cot.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# How to handle the raw chain of thought in gpt-oss
2+
3+
The [gpt-oss models](https://openai.com/open-models) provide access to a raw chain of thought (CoT) meant for analysis and safety research by model implementors, but it’s also crucial for the performance of tool calling, as tool calls can be performed as part of the CoT. At the same time, the raw CoT might contain potentially harmful content or could reveal information to users that the person implementing the model might not intend (like rules specified in the instructions given to the model). You therefore should not show raw CoT to end users.
4+
5+
## Harmony / chat template handling
6+
7+
The model encodes its raw CoT as part of our [harmony response format](https://cookbook.openai.com/articles/openai-harmony). If you are authoring your own chat templates or are handling tokens directly, make sure to [check out harmony guide first](https://cookbook.openai.com/articles/openai-harmony).
8+
9+
To summarize a couple of things:
10+
11+
1. CoT will be issued to the `analysis` channel
12+
2. After a message to the `final` channel in a subsequent sampling turn all `analysis` messages should be dropped. Function calls to the `commentary` channel can remain
13+
3. If the last message by the assistant was a tool call of any type, the analysis messages until the previous `final` message should be preserved on subsequent sampling until a `final` message gets issued
14+
15+
## Chat Completions API
16+
17+
If you are implementing a Chat Completions API, there is no official spec for handling chain of thought in the published OpenAI specs, as our hosted models will not offer this feature for the time being. We ask you to follow [the following convention from OpenRouter instead](https://openrouter.ai/docs/use-cases/reasoning-tokens). Including:
18+
19+
1. Raw CoT will be returned as part of the response unless `reasoning: { exclude: true }` is specified as part of the request. [See details here](https://openrouter.ai/docs/use-cases/reasoning-tokens#legacy-parameters)
20+
2. The raw CoT is exposed as a `reasoning` property on the message in the output
21+
3. For delta events the delta has a `reasoning` property
22+
4. On subsequent turns you should be able to receive the previous reasoning (as `reasoning`) and handle it in accordance with the behavior specified in the chat template section above.
23+
24+
When in doubt, please follow the convention / behavior of the OpenRouter implementation.
25+
26+
## Responses API
27+
28+
For the Responses API we augmented our Responses API spec to cover this case. Below are the changes to the spec as type definitions. At a high level we are:
29+
30+
1. Introducing a new `content` property on `reasoning`. This allows a reasoning `summary` that could be displayed to the end user to be returned at the same time as the raw CoT (which should not be shown to the end user, but which might be helpful for interpretability research).
31+
2. Introducing a new content type called `reasoning_text`
32+
3. Introducing two new events `response.reasoning_text.delta` to stream the deltas of the raw CoT and `response.reasoning_text.done` to indicate a turn of CoT to be completed
33+
4. On subsequent turns you should be able to receive the previous reasoning and handle it in accordance with the behavior specified in the chat template section above.
34+
35+
**Item type changes**
36+
37+
```typescript
38+
type ReasoningItem = {
39+
id: string;
40+
type: "reasoning";
41+
summary: SummaryContent[];
42+
// new
43+
content: ReasoningTextContent[];
44+
};
45+
46+
type ReasoningTextContent = {
47+
type: "reasoning_text";
48+
text: string;
49+
};
50+
51+
type ReasoningTextDeltaEvent = {
52+
type: "response.reasoning_text.delta";
53+
sequence_number: number;
54+
item_id: string;
55+
output_index: number;
56+
content_index: number;
57+
delta: string;
58+
};
59+
60+
type ReasoningTextDoneEvent = {
61+
type: "response.reasoning_text.done";
62+
sequence_number: number;
63+
item_id: string;
64+
output_index: number;
65+
content_index: number;
66+
text: string;
67+
};
68+
```
69+
70+
**Event changes**
71+
72+
```typescript
73+
...
74+
{
75+
type: "response.content_part.added"
76+
...
77+
}
78+
{
79+
type: "response.reasoning_text.delta",
80+
sequence_number: 14,
81+
item_id: "rs_67f47a642e788191aec9b5c1a35ab3c3016f2c95937d6e91",
82+
output_index: 0,
83+
content_index: 0,
84+
delta: "The "
85+
}
86+
...
87+
{
88+
type: "response.reasoning_text.done",
89+
sequence_number: 18,
90+
item_id: "rs_67f47a642e788191aec9b5c1a35ab3c3016f2c95937d6e91",
91+
output_index: 0,
92+
content_index: 0,
93+
text: "The user asked me to think"
94+
}
95+
```
96+
97+
**Example responses output**
98+
99+
```typescript
100+
"output": [
101+
{
102+
"type": "reasoning",
103+
"id": "rs_67f47a642e788191aec9b5c1a35ab3c3016f2c95937d6e91",
104+
"summary": [
105+
{
106+
"type": "summary_text",
107+
"text": "**Calculating volume of gold for Pluto layer**\n\nStarting with the approximation..."
108+
}
109+
],
110+
"content": [
111+
{
112+
"type": "reasoning_text",
113+
"text": "The user asked me to think..."
114+
}
115+
]
116+
}
117+
]
118+
119+
```
120+
121+
## Displaying raw CoT to end-users
122+
123+
If you are providing a chat interface to users, you should not show the raw CoT because it might contain potentially harmful content or other information that you might not intend to show to users (like, for example, instructions in the developer message). Instead, we recommend showing a summarized CoT, similar to our production implementations in the API or ChatGPT, where a summarizer model reviews and blocks harmful content from being shown.

0 commit comments

Comments
 (0)