Streaming version of o3-mini

This commit is contained in:
Matt Rubens
2025-01-31 17:50:29 -05:00
parent e8f0b35860
commit 7d28ff516c
2 changed files with 34 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"roo-cline": patch
---
Streaming version of o3-mini

View File

@@ -27,8 +27,7 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
switch (modelId) { switch (modelId) {
case "o1": case "o1":
case "o1-preview": case "o1-preview":
case "o1-mini": case "o1-mini": {
case "o3-mini": {
// o1-preview and o1-mini don't support streaming, non-1 temp, or system prompt // o1-preview and o1-mini don't support streaming, non-1 temp, or system prompt
// o1 doesnt support streaming or non-1 temp but does support a developer prompt // o1 doesnt support streaming or non-1 temp but does support a developer prompt
const response = await this.client.chat.completions.create({ const response = await this.client.chat.completions.create({
@@ -49,6 +48,34 @@ export class OpenAiNativeHandler implements ApiHandler, SingleCompletionHandler
} }
break break
} }
case "o3-mini": {
const stream = await this.client.chat.completions.create({
model: this.getModel().id,
messages: [{ role: "developer", content: systemPrompt }, ...convertToOpenAiMessages(messages)],
stream: true,
stream_options: { include_usage: true },
})
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta
if (delta?.content) {
yield {
type: "text",
text: delta.content,
}
}
// contains a null value except for the last chunk which contains the token usage statistics for the entire request
if (chunk.usage) {
yield {
type: "usage",
inputTokens: chunk.usage.prompt_tokens || 0,
outputTokens: chunk.usage.completion_tokens || 0,
}
}
}
break
}
default: { default: {
const stream = await this.client.chat.completions.create({ const stream = await this.client.chat.completions.create({
model: this.getModel().id, model: this.getModel().id,