Skip to content

Commit cd29243

Browse files
authored
fix(openai-compatible): add max reasoning effort option (Zoo-Code-Org#882) (Zoo-Code-Org#1051)
1 parent 569b43d commit cd29243

3 files changed

Lines changed: 65 additions & 4 deletions

File tree

src/api/providers/__tests__/openai.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,27 @@ describe("OpenAiHandler", () => {
453453
expect(callArgs.reasoning_effort).toBe("high")
454454
})
455455

456+
it("should pass through max reasoning_effort when configured by an OpenAI-compatible model", async () => {
457+
const reasoningOptions: ApiHandlerOptions = {
458+
...mockOptions,
459+
enableReasoningEffort: true,
460+
openAiCustomModelInfo: {
461+
contextWindow: 128_000,
462+
supportsPromptCache: false,
463+
supportsReasoningEffort: ["low", "medium", "high", "xhigh", "max"],
464+
reasoningEffort: "max",
465+
},
466+
}
467+
const reasoningHandler = new OpenAiHandler(reasoningOptions)
468+
const stream = reasoningHandler.createMessage(systemPrompt, messages)
469+
for await (const _chunk of stream) {
470+
}
471+
472+
expect(mockCreate).toHaveBeenCalled()
473+
const callArgs = mockCreate.mock.calls[0][0]
474+
expect(callArgs.reasoning_effort).toBe("max")
475+
})
476+
456477
it("should not include reasoning_effort when reasoning effort is disabled", async () => {
457478
const noReasoningOptions: ApiHandlerOptions = {
458479
...mockOptions,

webview-ui/src/components/settings/providers/OpenAICompatible.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { VSCodeButton, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
66
import {
77
type ProviderSettings,
88
type ModelInfo,
9-
type ReasoningEffort,
9+
type ReasoningEffortExtended,
1010
type OrganizationAllowList,
1111
type ExtensionMessage,
1212
azureOpenAiDefaultApiVersion,
@@ -266,13 +266,13 @@ export const OpenAICompatible = ({
266266

267267
setApiConfigurationField("openAiCustomModelInfo", {
268268
...openAiCustomModelInfo,
269-
reasoningEffort: value as ReasoningEffort,
269+
reasoningEffort: value as ReasoningEffortExtended,
270270
})
271271
}
272272
}}
273273
modelInfo={{
274274
...(apiConfiguration.openAiCustomModelInfo || openAiModelInfoSaneDefaults),
275-
supportsReasoningEffort: ["low", "medium", "high", "xhigh"],
275+
supportsReasoningEffort: ["low", "medium", "high", "xhigh", "max"],
276276
}}
277277
/>
278278
)}

webview-ui/src/components/settings/providers/__tests__/OpenAICompatible.spec.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ vi.mock("../../R1FormatSetting", () => ({
7676
R1FormatSetting: () => <div data-testid="r1-format-setting">R1 Format Setting</div>,
7777
}))
7878

79+
const { mockThinkingBudget } = vi.hoisted(() => ({ mockThinkingBudget: vi.fn() }))
80+
7981
vi.mock("../../ThinkingBudget", () => ({
80-
ThinkingBudget: () => <div data-testid="thinking-budget">Thinking Budget</div>,
82+
ThinkingBudget: (props: any) => {
83+
mockThinkingBudget(props)
84+
return <div data-testid="thinking-budget">Thinking Budget</div>
85+
},
8186
}))
8287

8388
// Mock react-use
@@ -312,4 +317,39 @@ describe("OpenAICompatible Component - includeMaxTokens checkbox", () => {
312317
expect(description).toHaveClass("text-sm", "text-vscode-descriptionForeground", "ml-6")
313318
})
314319
})
320+
describe("reasoning effort", () => {
321+
it("should expose and persist the max reasoning-effort value", () => {
322+
const apiConfiguration: Partial<ProviderSettings> = {
323+
enableReasoningEffort: true,
324+
openAiCustomModelInfo: {
325+
contextWindow: 128_000,
326+
supportsPromptCache: false,
327+
},
328+
}
329+
330+
render(
331+
<OpenAICompatible
332+
apiConfiguration={apiConfiguration as ProviderSettings}
333+
setApiConfigurationField={mockSetApiConfigurationField}
334+
organizationAllowList={mockOrganizationAllowList}
335+
/>,
336+
)
337+
338+
const thinkingBudgetProps = mockThinkingBudget.mock.calls[0][0]
339+
expect(thinkingBudgetProps.modelInfo.supportsReasoningEffort).toEqual([
340+
"low",
341+
"medium",
342+
"high",
343+
"xhigh",
344+
"max",
345+
])
346+
347+
thinkingBudgetProps.setApiConfigurationField("reasoningEffort", "max")
348+
349+
expect(mockSetApiConfigurationField).toHaveBeenCalledWith("openAiCustomModelInfo", {
350+
...apiConfiguration.openAiCustomModelInfo,
351+
reasoningEffort: "max",
352+
})
353+
})
354+
})
315355
})

0 commit comments

Comments
 (0)