Skip to content

Commit d9cac62

Browse files
committed
feat: add checkbox to control maximum context window for magistral-medium model
- Added useMaximumContextWindow field to provider settings schema - Implemented checkbox UI in Mistral provider settings with yellow warning - Updated context window logic to limit to 41k tokens when checkbox is unchecked - Added localization strings for the new feature This allows users to opt-in to using the full 128k context window for the magistral-medium-latest model, with a warning about potential performance degradation.
1 parent c479678 commit d9cac62

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

packages/types/src/provider-settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ const baseProviderSettingsSchema = z.object({
111111

112112
// Model verbosity.
113113
verbosity: verbosityLevelsSchema.optional(),
114+
115+
// Context window settings.
116+
useMaximumContextWindow: z.boolean().optional(),
114117
})
115118

116119
// Several of the providers share common model config properties.

packages/types/src/providers/mistral.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ export const mistralDefaultModelId: MistralModelId = "codestral-latest"
77

88
export const mistralModels = {
99
"magistral-medium-latest": {
10-
maxTokens: 41_000,
11-
contextWindow: 41_000,
10+
maxTokens: 128_000,
11+
contextWindow: 128_000,
1212
supportsImages: false,
1313
supportsPromptCache: false,
14+
supportsReasoningBudget: true,
1415
inputPrice: 2.0,
1516
outputPrice: 5.0,
1617
},

src/api/providers/mistral.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,17 @@ export class MistralHandler extends BaseProvider implements SingleCompletionHand
9595

9696
override getModel() {
9797
const id = this.options.apiModelId ?? mistralDefaultModelId
98-
const info = mistralModels[id as MistralModelId] ?? mistralModels[mistralDefaultModelId]
98+
let info = mistralModels[id as MistralModelId] ?? mistralModels[mistralDefaultModelId]
99+
100+
// For magistral-medium-latest, optionally limit context window if useMaximumContextWindow is false
101+
if (id === "magistral-medium-latest" && !this.options.useMaximumContextWindow && info.contextWindow > 41000) {
102+
// Create a modified info object with reduced context window for better performance
103+
info = {
104+
...info,
105+
contextWindow: 41000,
106+
maxTokens: 41000,
107+
}
108+
}
99109

100110
// @TODO: Move this to the `getModelParams` function.
101111
const maxTokens = this.options.includeMaxTokens ? info.maxTokens : undefined

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { useCallback } from "react"
22
import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
33

4-
import { type ProviderSettings, mistralDefaultModelId } from "@roo-code/types"
4+
import { type ProviderSettings, mistralDefaultModelId, mistralModels } from "@roo-code/types"
55

66
import type { RouterModels } from "@roo/api"
77

88
import { useAppTranslation } from "@src/i18n/TranslationContext"
99
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
10+
import { Checkbox } from "@src/components/ui"
1011

1112
import { inputEventTransform } from "../transforms"
1213

@@ -30,6 +31,15 @@ export const Mistral = ({ apiConfiguration, setApiConfigurationField }: MistralP
3031
[setApiConfigurationField],
3132
)
3233

34+
// Check if the current model is magistral-medium-latest
35+
const isMagistralMedium =
36+
apiConfiguration?.apiModelId === "magistral-medium-latest" ||
37+
(!apiConfiguration?.apiModelId && mistralDefaultModelId === "magistral-medium-latest")
38+
39+
// Get the model info for magistral-medium-latest
40+
const magistralMediumModel = mistralModels["magistral-medium-latest"]
41+
const hasLargeContext = magistralMediumModel && magistralMediumModel.contextWindow >= 100000
42+
3343
return (
3444
<>
3545
<VSCodeTextField
@@ -48,6 +58,23 @@ export const Mistral = ({ apiConfiguration, setApiConfigurationField }: MistralP
4858
{t("settings:providers.getMistralApiKey")}
4959
</VSCodeButtonLink>
5060
)}
61+
{isMagistralMedium && hasLargeContext && (
62+
<div className="flex flex-col gap-2">
63+
<Checkbox
64+
checked={apiConfiguration?.useMaximumContextWindow || false}
65+
onChange={(checked: boolean) => setApiConfigurationField("useMaximumContextWindow", checked)}>
66+
{t("settings:providers.mistral.useMaximumContextWindow")}
67+
</Checkbox>
68+
{apiConfiguration?.useMaximumContextWindow && (
69+
<div className="flex items-start gap-2 p-2 rounded-md bg-[color-mix(in_srgb,var(--vscode-editorWarning-foreground)_20%,transparent)] border border-[var(--vscode-editorWarning-foreground)]">
70+
<span className="codicon codicon-warning text-[var(--vscode-editorWarning-foreground)] mt-0.5"></span>
71+
<div className="text-sm text-[var(--vscode-editorWarning-foreground)]">
72+
{t("settings:providers.mistral.contextWindowWarning")}
73+
</div>
74+
</div>
75+
)}
76+
</div>
77+
)}
5178
{(apiConfiguration?.apiModelId?.startsWith("codestral-") ||
5279
(!apiConfiguration?.apiModelId && mistralDefaultModelId.startsWith("codestral-"))) && (
5380
<>

webview-ui/src/i18n/locales/en/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@
313313
"getMistralApiKey": "Get Mistral / Codestral API Key",
314314
"codestralBaseUrl": "Codestral Base URL (Optional)",
315315
"codestralBaseUrlDesc": "Set an alternative URL for the Codestral model.",
316+
"mistral": {
317+
"useMaximumContextWindow": "Use maximum context window (128k tokens)",
318+
"contextWindowWarning": "Using the full 128k context window may significantly degrade performance. Consider using a smaller context for better responsiveness unless you specifically need the extended context."
319+
},
316320
"xaiApiKey": "xAI API Key",
317321
"getXaiApiKey": "Get xAI API Key",
318322
"litellmApiKey": "LiteLLM API Key",

0 commit comments

Comments
 (0)