Skip to content

Commit 9542b2c

Browse files
feat(openai): added support for o1 reasoning models (#1618)
* fix(openai): systemRoleSupported model configuration for openai endpoints * feat(openai): max_completion_tokens now used over max_tokens for chat_completeions endpoint. * fix: lint * feat(docs): add o1 example * fix: make parameter default to false and fix type checks --------- Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
1 parent 408c3a9 commit 9542b2c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

docs/source/configuration/models/providers/openai.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ MODELS=`[{
5353
}]`
5454
```
5555

56+
We also support models in the `o1` family. You need to add a few more options ot the config: Here is an example for `o1-mini`:
57+
58+
```ini
59+
MODELS=`[
60+
{
61+
"name": "o1-mini",
62+
"description": "ChatGPT o1-mini",
63+
"systemRoleSupported": false,
64+
"parameters": {
65+
"max_new_tokens": 2048,
66+
},
67+
"endpoints" : [{
68+
"type": "openai",
69+
"useCompletionTokens": true,
70+
}]
71+
}
72+
]
73+
```
74+
5675
You may also consume any model provider that provides compatible OpenAI API endpoint. For example, you may self-host [Portkey](https://github.com/Portkey-AI/gateway) gateway and experiment with Claude or GPTs offered by Azure OpenAI. Example for Claude from Anthropic:
5776

5877
```ini

src/lib/server/endpoints/openai/endpointOai.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export const endpointOAIParametersSchema = z.object({
111111
}),
112112
})
113113
.default({}),
114+
/* enable use of max_completion_tokens in place of max_tokens */
115+
useCompletionTokens: z.boolean().default(false),
114116
});
115117

116118
export async function endpointOai(
@@ -125,6 +127,7 @@ export async function endpointOai(
125127
defaultQuery,
126128
multimodal,
127129
extraBody,
130+
useCompletionTokens,
128131
} = endpointOAIParametersSchema.parse(input);
129132

130133
let OpenAI;
@@ -199,6 +202,14 @@ export async function endpointOai(
199202
messagesOpenAI[0].content = preprompt ?? "";
200203
}
201204

205+
// if system role is not supported, convert first message to a user message.
206+
if (!model.systemRoleSupported && messagesOpenAI?.[0]?.role === "system") {
207+
messagesOpenAI[0] = {
208+
...messagesOpenAI[0],
209+
role: "user",
210+
};
211+
}
212+
202213
if (toolResults && toolResults.length > 0) {
203214
const toolCallRequests: OpenAI.Chat.Completions.ChatCompletionAssistantMessageParam = {
204215
role: "assistant",
@@ -241,7 +252,9 @@ export async function endpointOai(
241252
model: model.id ?? model.name,
242253
messages: messagesOpenAI,
243254
stream: true,
244-
max_tokens: parameters?.max_new_tokens,
255+
...(useCompletionTokens
256+
? { max_completion_tokens: parameters?.max_new_tokens }
257+
: { max_tokens: parameters?.max_new_tokens }),
245258
stop: parameters?.stop,
246259
temperature: parameters?.temperature,
247260
top_p: parameters?.top_p,

0 commit comments

Comments
 (0)