@@ -40,6 +40,7 @@ interface ModelPickerProps<T extends ModelProvider = ModelProvider> {
4040 serviceName : string
4141 serviceUrl : string
4242 recommendedModel : string
43+ allowCustomModel ?: boolean
4344}
4445
4546export const ModelPicker = ( {
@@ -52,7 +53,10 @@ export const ModelPicker = ({
5253 serviceName,
5354 serviceUrl,
5455 recommendedModel,
56+ allowCustomModel = false ,
5557} : ModelPickerProps ) => {
58+ const [ customModelId , setCustomModelId ] = useState ( "" )
59+ const [ isCustomModel , setIsCustomModel ] = useState ( false )
5660 const [ open , setOpen ] = useState ( false )
5761 const [ value , setValue ] = useState ( defaultModelId )
5862 const [ isDescriptionExpanded , setIsDescriptionExpanded ] = useState ( false )
@@ -70,6 +74,20 @@ export const ModelPicker = ({
7074 [ apiConfiguration ] ,
7175 )
7276
77+ const onSelectCustomModel = useCallback (
78+ ( modelId : string ) => {
79+ setCustomModelId ( modelId )
80+ const modelInfo = { id : modelId }
81+ const apiConfig = { ...apiConfiguration , [ configKey ] : modelId , [ infoKey ] : modelInfo }
82+ setApiConfiguration ( apiConfig )
83+ onUpdateApiConfig ( apiConfig )
84+ setValue ( modelId )
85+ setOpen ( false )
86+ setIsCustomModel ( false )
87+ } ,
88+ [ apiConfiguration , configKey , infoKey , onUpdateApiConfig , setApiConfiguration ] ,
89+ )
90+
7391 const onSelect = useCallback (
7492 ( modelId : string ) => {
7593 const modelInfo = Array . isArray ( models )
@@ -147,6 +165,17 @@ export const ModelPicker = ({
147165 </ CommandItem >
148166 ) ) }
149167 </ CommandGroup >
168+ { allowCustomModel && (
169+ < CommandGroup heading = "Custom" >
170+ < CommandItem
171+ onSelect = { ( ) => {
172+ setIsCustomModel ( true )
173+ setOpen ( false )
174+ } } >
175+ + Add custom model
176+ </ CommandItem >
177+ </ CommandGroup >
178+ ) }
150179 </ CommandList >
151180 </ Command >
152181 </ PopoverContent >
@@ -168,6 +197,28 @@ export const ModelPicker = ({
168197 < VSCodeLink onClick = { ( ) => onSelect ( recommendedModel ) } > { recommendedModel } .</ VSCodeLink >
169198 You can also try searching "free" for no-cost options currently available.
170199 </ p >
200+ { allowCustomModel && isCustomModel && (
201+ < div className = "fixed inset-0 bg-black/50 flex items-center justify-center z-50" >
202+ < div className = "bg-[var(--vscode-editor-background)] p-6 rounded-lg w-96" >
203+ < h3 className = "text-lg font-semibold mb-4" > Add Custom Model</ h3 >
204+ < input
205+ type = "text"
206+ className = "w-full p-2 mb-4 bg-[var(--vscode-input-background)] text-[var(--vscode-input-foreground)] border border-[var(--vscode-input-border)] rounded"
207+ placeholder = "Enter model ID"
208+ value = { customModelId }
209+ onChange = { ( e ) => setCustomModelId ( e . target . value ) }
210+ />
211+ < div className = "flex justify-end gap-2" >
212+ < Button variant = "secondary" onClick = { ( ) => setIsCustomModel ( false ) } >
213+ Cancel
214+ </ Button >
215+ < Button onClick = { ( ) => onSelectCustomModel ( customModelId ) } disabled = { ! customModelId . trim ( ) } >
216+ Add
217+ </ Button >
218+ </ div >
219+ </ div >
220+ </ div >
221+ ) }
171222 </ >
172223 )
173224}
0 commit comments