Skip to content

Commit 6a4653a

Browse files
committed
fix: ensure OpenAI-compatible providers use custom max tokens setting
The issue was that OpenAI-compatible providers (Chutes, Groq) were directly using model.info.maxTokens instead of calling getModelMaxOutputTokens(). This meant that the user's custom modelMaxTokens setting was being ignored. Fixed by: - Updating BaseOpenAiCompatibleProvider to use getModelMaxOutputTokens() - Updating ChutesHandler's getCompletionParams to use getModelMaxOutputTokens() This ensures that when users set a custom max output tokens value in the settings, it will be properly applied to API requests for all OpenAI-compatible providers.
1 parent 83522e2 commit 6a4653a

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/api/providers/base-openai-compatible-provider.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import OpenAI from "openai"
44
import type { ModelInfo } from "@roo-code/types"
55

66
import type { ApiHandlerOptions } from "../../shared/api"
7+
import { getModelMaxOutputTokens } from "../../shared/api"
78
import { ApiStream } from "../transform/stream"
89
import { convertToOpenAiMessages } from "../transform/openai-format"
910

@@ -67,15 +68,17 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
6768
messages: Anthropic.Messages.MessageParam[],
6869
metadata?: ApiHandlerCreateMessageMetadata,
6970
): ApiStream {
70-
const {
71-
id: model,
72-
info: { maxTokens: max_tokens },
73-
} = this.getModel()
71+
const model = this.getModel()
72+
const max_tokens = getModelMaxOutputTokens({
73+
modelId: model.id,
74+
model: model.info,
75+
settings: this.options as any,
76+
})
7477

7578
const temperature = this.options.modelTemperature ?? this.defaultTemperature
7679

7780
const params: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {
78-
model,
81+
model: model.id,
7982
max_tokens,
8083
temperature,
8184
messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],

src/api/providers/chutes.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Anthropic } from "@anthropic-ai/sdk"
33
import OpenAI from "openai"
44

55
import type { ApiHandlerOptions } from "../../shared/api"
6+
import { getModelMaxOutputTokens } from "../../shared/api"
67
import { XmlMatcher } from "../../utils/xml-matcher"
78
import { convertToR1Format } from "../transform/r1-format"
89
import { convertToOpenAiMessages } from "../transform/openai-format"
@@ -27,15 +28,17 @@ export class ChutesHandler extends BaseOpenAiCompatibleProvider<ChutesModelId> {
2728
systemPrompt: string,
2829
messages: Anthropic.Messages.MessageParam[],
2930
): OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming {
30-
const {
31-
id: model,
32-
info: { maxTokens: max_tokens },
33-
} = this.getModel()
31+
const model = this.getModel()
32+
const max_tokens = getModelMaxOutputTokens({
33+
modelId: model.id,
34+
model: model.info,
35+
settings: this.options as any,
36+
})
3437

35-
const temperature = this.options.modelTemperature ?? this.getModel().info.temperature
38+
const temperature = this.options.modelTemperature ?? model.info.temperature
3639

3740
return {
38-
model,
41+
model: model.id,
3942
max_tokens,
4043
temperature,
4144
messages: [{ role: "system", content: systemPrompt }, ...convertToOpenAiMessages(messages)],

0 commit comments

Comments
 (0)