Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
"@types/jest": "^29.5.14",
"@types/mocha": "^10.0.10",
"@types/node": "20.x",
"@types/node-cache": "^4.1.3",
"@types/node-ipc": "^9.2.3",
"@types/string-similarity": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^7.14.1",
Expand Down
35 changes: 35 additions & 0 deletions src/api/providers/__tests__/openai.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// npx jest src/api/providers/__tests__/openai.test.ts

import { OpenAiHandler } from "../openai"
import { ApiHandlerOptions } from "../../../shared/api"
import { Anthropic } from "@anthropic-ai/sdk"
Expand Down Expand Up @@ -155,6 +157,39 @@ describe("OpenAiHandler", () => {
expect(textChunks).toHaveLength(1)
expect(textChunks[0].text).toBe("Test response")
})
it("should include reasoning_effort when reasoning effort is enabled", async () => {
const reasoningOptions: ApiHandlerOptions = {
...mockOptions,
enableReasoningEffort: true,
openAiCustomModelInfo: { contextWindow: 128_000, supportsPromptCache: false, reasoningEffort: "high" },
}
const reasoningHandler = new OpenAiHandler(reasoningOptions)
const stream = reasoningHandler.createMessage(systemPrompt, messages)
// Consume the stream to trigger the API call
for await (const _chunk of stream) {
}
// Assert the mockCreate was called with reasoning_effort
expect(mockCreate).toHaveBeenCalled()
const callArgs = mockCreate.mock.calls[0][0]
expect(callArgs.reasoning_effort).toBe("high")
})

it("should not include reasoning_effort when reasoning effort is disabled", async () => {
const noReasoningOptions: ApiHandlerOptions = {
...mockOptions,
enableReasoningEffort: false,
openAiCustomModelInfo: { contextWindow: 128_000, supportsPromptCache: false },
}
const noReasoningHandler = new OpenAiHandler(noReasoningOptions)
const stream = noReasoningHandler.createMessage(systemPrompt, messages)
// Consume the stream to trigger the API call
for await (const _chunk of stream) {
}
// Assert the mockCreate was called without reasoning_effort
expect(mockCreate).toHaveBeenCalled()
const callArgs = mockCreate.mock.calls[0][0]
expect(callArgs.reasoning_effort).toBeUndefined()
})
})

describe("error handling", () => {
Expand Down
1 change: 1 addition & 0 deletions src/exports/roo-code.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type ProviderSettings = {
openAiUseAzure?: boolean | undefined
azureApiVersion?: string | undefined
openAiStreamingEnabled?: boolean | undefined
enableReasoningEffort?: boolean | undefined
ollamaModelId?: string | undefined
ollamaBaseUrl?: string | undefined
vsCodeLmModelSelector?:
Expand Down
1 change: 1 addition & 0 deletions src/exports/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type ProviderSettings = {
openAiUseAzure?: boolean | undefined
azureApiVersion?: string | undefined
openAiStreamingEnabled?: boolean | undefined
enableReasoningEffort?: boolean | undefined
ollamaModelId?: string | undefined
ollamaBaseUrl?: string | undefined
vsCodeLmModelSelector?:
Expand Down
2 changes: 2 additions & 0 deletions src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ export const providerSettingsSchema = z.object({
openAiUseAzure: z.boolean().optional(),
azureApiVersion: z.string().optional(),
openAiStreamingEnabled: z.boolean().optional(),
enableReasoningEffort: z.boolean().optional(),
// Ollama
ollamaModelId: z.string().optional(),
ollamaBaseUrl: z.string().optional(),
Expand Down Expand Up @@ -453,6 +454,7 @@ const providerSettingsRecord: ProviderSettingsRecord = {
openAiUseAzure: undefined,
azureApiVersion: undefined,
openAiStreamingEnabled: undefined,
enableReasoningEffort: undefined,
// Ollama
ollamaModelId: undefined,
ollamaBaseUrl: undefined,
Expand Down
46 changes: 39 additions & 7 deletions webview-ui/src/components/settings/ApiOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { memo, useCallback, useEffect, useMemo, useState } from "react"
import { useAppTranslation } from "@/i18n/TranslationContext"
import { Trans } from "react-i18next"
import { getRequestyAuthUrl, getOpenRouterAuthUrl, getGlamaAuthUrl } from "@src/oauth/urls"
import { useDebounce, useEvent } from "react-use"
import { Trans } from "react-i18next"
import { LanguageModelChatSelector } from "vscode"
import { Checkbox } from "vscrui"
import { VSCodeLink, VSCodeRadio, VSCodeRadioGroup, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
import { ExternalLinkIcon } from "@radix-ui/react-icons"

import { ReasoningEffort as ReasoningEffortType } from "@roo/schemas"
import {
ApiConfiguration,
ModelInfo,
Expand All @@ -21,21 +20,22 @@ import {
ApiProvider,
} from "@roo/shared/api"
import { ExtensionMessage } from "@roo/shared/ExtensionMessage"
import { AWS_REGIONS } from "@roo/shared/aws_regions"

import { vscode } from "@src/utils/vscode"
import { validateApiConfiguration, validateModelId, validateBedrockArn } from "@src/utils/validate"
import { useRouterModels } from "@/components/ui/hooks/useRouterModels"
import { useSelectedModel } from "@/components/ui/hooks/useSelectedModel"
import { useAppTranslation } from "@src/i18n/TranslationContext"
import { useRouterModels } from "@src/components/ui/hooks/useRouterModels"
import { useSelectedModel } from "@src/components/ui/hooks/useSelectedModel"
import {
useOpenRouterModelProviders,
OPENROUTER_DEFAULT_PROVIDER_NAME,
} from "@src/components/ui/hooks/useOpenRouterModelProviders"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Button } from "@src/components/ui"
import { getRequestyAuthUrl, getOpenRouterAuthUrl, getGlamaAuthUrl } from "@src/oauth/urls"

import { VSCodeButtonLink } from "../common/VSCodeButtonLink"

import { MODELS_BY_PROVIDER, PROVIDERS, VERTEX_REGIONS, REASONING_MODELS } from "./constants"
import { MODELS_BY_PROVIDER, PROVIDERS, VERTEX_REGIONS, REASONING_MODELS, AWS_REGIONS } from "./constants"
import { ModelInfoView } from "./ModelInfoView"
import { ModelPicker } from "./ModelPicker"
import { ApiErrorMessage } from "./ApiErrorMessage"
Expand Down Expand Up @@ -851,6 +851,38 @@ const ApiOptions = ({
)}
</div>

<div className="flex flex-col gap-1">
<Checkbox
checked={apiConfiguration.enableReasoningEffort ?? false}
onChange={(checked: boolean) => {
setApiConfigurationField("enableReasoningEffort", checked)

if (!checked) {
const { reasoningEffort: _, ...openAiCustomModelInfo } =
apiConfiguration.openAiCustomModelInfo || openAiModelInfoSaneDefaults

setApiConfigurationField("openAiCustomModelInfo", openAiCustomModelInfo)
}
}}>
{t("settings:providers.setReasoningLevel")}
</Checkbox>
{!!apiConfiguration.enableReasoningEffort && (
<ReasoningEffort
apiConfiguration={{
...apiConfiguration,
reasoningEffort: apiConfiguration.openAiCustomModelInfo?.reasoningEffort,
}}
setApiConfigurationField={(field, value) => {
if (field === "reasoningEffort") {
setApiConfigurationField("openAiCustomModelInfo", {
...(apiConfiguration.openAiCustomModelInfo || openAiModelInfoSaneDefaults),
reasoningEffort: value as ReasoningEffortType,
})
}
}}
/>
)}
</div>
<div className="flex flex-col gap-3">
<div className="text-sm text-vscode-descriptionForeground whitespace-pre-line">
{t("settings:providers.customModel.capabilities")}
Expand Down
Loading