Skip to content

Commit 2d84092

Browse files
committed
feat: Adding UI and settings for the max context window
- added `MaxContextWindowControl.tsx` - added maxContextWindow in `settings.json`
1 parent 664346e commit 2d84092

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

packages/types/src/provider-settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const baseProviderSettingsSchema = z.object({
5757
diffEnabled: z.boolean().optional(),
5858
fuzzyMatchThreshold: z.number().optional(),
5959
modelTemperature: z.number().nullish(),
60+
modelMaxContextWindow: z.number().nullish(),
6061
rateLimitSeconds: z.number().optional(),
6162

6263
// Model reasoning.
@@ -346,6 +347,7 @@ export const PROVIDER_SETTINGS_KEYS = keysOf<ProviderSettings>()([
346347
"diffEnabled",
347348
"fuzzyMatchThreshold",
348349
"modelTemperature",
350+
"modelMaxContextWindow",
349351
"rateLimitSeconds",
350352
// Fake AI
351353
"fakeAi",

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { ApiErrorMessage } from "./ApiErrorMessage"
5151
import { ThinkingBudget } from "./ThinkingBudget"
5252
import { DiffSettingsControl } from "./DiffSettingsControl"
5353
import { TemperatureControl } from "./TemperatureControl"
54+
import { MaxContextWindowControl } from "./MaxContextWindowControl"
5455
import { RateLimitSecondsControl } from "./RateLimitSecondsControl"
5556
import { BedrockCustomArn } from "./providers/BedrockCustomArn"
5657
import { buildDocLink } from "@src/utils/docLinks"
@@ -484,6 +485,11 @@ const ApiOptions = ({
484485
onChange={handleInputChange("modelTemperature", noTransform)}
485486
maxValue={2}
486487
/>
488+
<MaxContextWindowControl
489+
value={apiConfiguration.modelMaxContextWindow}
490+
onChange={handleInputChange("modelMaxContextWindow", noTransform)}
491+
maxValue={1000000}
492+
/>
487493
<RateLimitSecondsControl
488494
value={apiConfiguration.rateLimitSeconds || 0}
489495
onChange={(value) => setApiConfigurationField("rateLimitSeconds", value)}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
2+
import { useEffect, useState } from "react"
3+
import { useAppTranslation } from "@/i18n/TranslationContext"
4+
import { useDebounce } from "react-use"
5+
6+
import { Slider } from "@/components/ui"
7+
8+
interface MaxContextWindowControlProps {
9+
value: number | undefined | null
10+
onChange: (value: number | undefined | null) => void
11+
maxValue?: number // Some providers like OpenAI use 0-2 range.
12+
}
13+
14+
export const MaxContextWindowControl = ({ value, onChange, maxValue = 1000000 }: MaxContextWindowControlProps) => {
15+
const { t } = useAppTranslation()
16+
const [isCustomTemperature, setIsCustomTemperature] = useState(value !== undefined)
17+
const [inputValue, setInputValue] = useState(value)
18+
19+
useDebounce(() => onChange(inputValue), 50, [onChange, inputValue])
20+
21+
// Sync internal state with prop changes when switching profiles.
22+
useEffect(() => {
23+
const hasCustomTemperature = value !== undefined && value !== null
24+
setIsCustomTemperature(hasCustomTemperature)
25+
setInputValue(value)
26+
}, [value])
27+
28+
return (
29+
<>
30+
<div>
31+
<VSCodeCheckbox
32+
checked={isCustomTemperature}
33+
onChange={(e: any) => {
34+
const isChecked = e.target.checked
35+
setIsCustomTemperature(isChecked)
36+
37+
if (!isChecked) {
38+
setInputValue(null) // Unset the temperature, note that undefined is unserializable.
39+
} else {
40+
setInputValue(value ?? 0) // Use the value from apiConfiguration, if set.
41+
}
42+
}}>
43+
<label className="block font-medium mb-1">{t("settings:maxContextWindow.useCustom")}</label>
44+
</VSCodeCheckbox>
45+
<div className="text-sm text-vscode-descriptionForeground mt-1">
46+
{t("settings:maxContextWindow.description")}
47+
</div>
48+
</div>
49+
50+
{isCustomTemperature && (
51+
<div className="flex flex-col gap-3 pl-3 border-l-2 border-vscode-button-background">
52+
<div>
53+
<div className="flex items-center gap-2">
54+
<Slider
55+
min={0}
56+
max={maxValue}
57+
step={1}
58+
value={[inputValue ?? 0]}
59+
onValueChange={([value]) => setInputValue(value)}
60+
/>
61+
<span className="w-10">{inputValue}</span>
62+
</div>
63+
<div className="text-vscode-descriptionForeground text-sm mt-1">
64+
{t("settings:maxContextWindow.rangeDescription")}
65+
</div>
66+
</div>
67+
</div>
68+
)}
69+
</>
70+
)
71+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@
497497
"description": "Controls randomness in the model's responses.",
498498
"rangeDescription": "Higher values make output more random, lower values make it more deterministic."
499499
},
500+
"maxContextWindow": {
501+
"useCustom": "Use custom context max window",
502+
"description": "Controls randomness in the model's responses.",
503+
"rangeDescription": "Higher values make output more random, lower values make it more deterministic."
504+
},
500505
"modelInfo": {
501506
"supportsImages": "Supports images",
502507
"noImages": "Does not support images",

0 commit comments

Comments
 (0)