Skip to content

Commit 88c4fa3

Browse files
committed
fix: reset when model is invalid
1 parent 54ab6d5 commit 88c4fa3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ const ApiOptions = ({
209209

210210
// Add the current selected model if it's not in the valid models list
211211
// This allows users to see their invalid selection
212-
if (selectedModelId && !modelOptions.some(option => option.value === selectedModelId)) {
212+
if (selectedModelId && !modelOptions.some((option) => option.value === selectedModelId)) {
213213
modelOptions.unshift({
214214
value: selectedModelId,
215215
label: `${selectedModelId} (invalid)`,
@@ -238,9 +238,13 @@ const ApiOptions = ({
238238
// in case we haven't set a default value for a provider
239239
if (!defaultValue) return
240240

241-
// Only set default if no model is set at all
242-
// Don't reset invalid models - let users see their invalid selection
243-
const shouldSetDefault = !modelId
241+
const providerModels = MODELS_BY_PROVIDER[value]
242+
const filteredModels = filterModels(providerModels || null, value, organizationAllowList)
243+
const isModelValid = modelId && filteredModels && Object.keys(filteredModels).includes(modelId)
244+
245+
// set default if no model is set OR if the current model is invalid for the new provider
246+
// this is to help 'reset' the invalid model when switching providers
247+
const shouldSetDefault = !modelId || !isModelValid
244248

245249
if (shouldSetDefault) {
246250
setApiConfigurationField(field, defaultValue)

0 commit comments

Comments
 (0)