Skip to content

Commit 32e46de

Browse files
committed
refactor: remove unnecessary switch cases
1 parent e27109e commit 32e46de

File tree

1 file changed

+37
-59
lines changed

1 file changed

+37
-59
lines changed

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

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -251,65 +251,43 @@ const ApiOptions = ({
251251
}
252252
}
253253

254-
switch (value) {
255-
case "openrouter":
256-
validateAndResetModel(
257-
apiConfiguration.openRouterModelId,
258-
"openRouterModelId",
259-
openRouterDefaultModelId,
260-
)
261-
break
262-
case "glama":
263-
validateAndResetModel(apiConfiguration.glamaModelId, "glamaModelId", glamaDefaultModelId)
264-
break
265-
case "unbound":
266-
validateAndResetModel(apiConfiguration.unboundModelId, "unboundModelId", unboundDefaultModelId)
267-
break
268-
case "requesty":
269-
validateAndResetModel(apiConfiguration.requestyModelId, "requestyModelId", requestyDefaultModelId)
270-
break
271-
case "litellm":
272-
validateAndResetModel(apiConfiguration.litellmModelId, "litellmModelId", litellmDefaultModelId)
273-
break
274-
case "anthropic":
275-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", anthropicDefaultModelId)
276-
break
277-
case "openai-native":
278-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", openAiNativeDefaultModelId)
279-
break
280-
case "gemini":
281-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", geminiDefaultModelId)
282-
break
283-
case "deepseek":
284-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", deepSeekDefaultModelId)
285-
break
286-
case "mistral":
287-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", mistralDefaultModelId)
288-
break
289-
case "xai":
290-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", xaiDefaultModelId)
291-
break
292-
case "groq":
293-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", groqDefaultModelId)
294-
break
295-
case "chutes":
296-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", chutesDefaultModelId)
297-
break
298-
case "bedrock":
299-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", bedrockDefaultModelId)
300-
break
301-
case "vertex":
302-
validateAndResetModel(apiConfiguration.apiModelId, "apiModelId", vertexDefaultModelId)
303-
break
304-
case "openai":
305-
validateAndResetModel(apiConfiguration.openAiModelId, "openAiModelId")
306-
break
307-
case "ollama":
308-
validateAndResetModel(apiConfiguration.ollamaModelId, "ollamaModelId")
309-
break
310-
case "lmstudio":
311-
validateAndResetModel(apiConfiguration.lmStudioModelId, "lmStudioModelId")
312-
break
254+
// Define a mapping object that associates each provider with its model configuration
255+
const PROVIDER_MODEL_CONFIG: Partial<
256+
Record<
257+
ProviderName,
258+
{
259+
field: keyof ProviderSettings
260+
default?: string
261+
}
262+
>
263+
> = {
264+
openrouter: { field: "openRouterModelId", default: openRouterDefaultModelId },
265+
glama: { field: "glamaModelId", default: glamaDefaultModelId },
266+
unbound: { field: "unboundModelId", default: unboundDefaultModelId },
267+
requesty: { field: "requestyModelId", default: requestyDefaultModelId },
268+
litellm: { field: "litellmModelId", default: litellmDefaultModelId },
269+
anthropic: { field: "apiModelId", default: anthropicDefaultModelId },
270+
"openai-native": { field: "apiModelId", default: openAiNativeDefaultModelId },
271+
gemini: { field: "apiModelId", default: geminiDefaultModelId },
272+
deepseek: { field: "apiModelId", default: deepSeekDefaultModelId },
273+
mistral: { field: "apiModelId", default: mistralDefaultModelId },
274+
xai: { field: "apiModelId", default: xaiDefaultModelId },
275+
groq: { field: "apiModelId", default: groqDefaultModelId },
276+
chutes: { field: "apiModelId", default: chutesDefaultModelId },
277+
bedrock: { field: "apiModelId", default: bedrockDefaultModelId },
278+
vertex: { field: "apiModelId", default: vertexDefaultModelId },
279+
openai: { field: "openAiModelId" },
280+
ollama: { field: "ollamaModelId" },
281+
lmstudio: { field: "lmStudioModelId" },
282+
}
283+
284+
const config = PROVIDER_MODEL_CONFIG[value]
285+
if (config) {
286+
validateAndResetModel(
287+
apiConfiguration[config.field] as string | undefined,
288+
config.field,
289+
config.default,
290+
)
313291
}
314292
},
315293
[setApiConfigurationField, apiConfiguration, organizationAllowList],

0 commit comments

Comments
 (0)