Skip to content

Commit 7d28ff5

Browse files
committed
Streaming version of o3-mini
1 parent e8f0b35 commit 7d28ff5

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

.changeset/gold-pillows-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Streaming version of o3-mini

src/api/providers/openai-native.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
2727
switch (modelId) {
2828
case "o1":
2929
case "o1-preview":
30-
case "o1-mini":
31-
case "o3-mini": {
30+
case "o1-mini": {
3231
// o1-preview and o1-mini don't support streaming, non-1 temp, or system prompt
3332
// o1 doesnt support streaming or non-1 temp but does support a developer prompt
3433
const response = await this.client.chat.completions.create({
@@ -49,6 +48,34 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
4948
}
5049
break
5150
}
51+
case "o3-mini": {
52+
const stream = await this.client.chat.completions.create({
53+
model: this.getModel().id,
54+
messages: [{ role: "developer", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
55+
stream: true,
56+
stream_options: { include_usage: true },
57+
})
58+
59+
for await (const chunk of stream) {
60+
const delta = chunk.choices[0]?.delta
61+
if (delta?.content) {
62+
yield {
63+
type: "text",
64+
text: delta.content,
65+
}
66+
}
67+
68+
// contains a null value except for the last chunk which contains the token usage statistics for the entire request
69+
if (chunk.usage) {
70+
yield {
71+
type: "usage",
72+
inputTokens: chunk.usage.prompt_tokens || 0,
73+
outputTokens: chunk.usage.completion_tokens || 0,
74+
}
75+
}
76+
}
77+
break
78+
}
5279
default: {
5380
const stream = await this.client.chat.completions.create({
5481
model: this.getModel().id,

0 commit comments

Comments
 (0)