From ccb4738d7ebdf77c7b93b085572cc93d4773aef0 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Tue, 8 Oct 2024 17:03:42 -0400 Subject: [PATCH] Use or instead of null coalescing instead since state may return non undefined for new values --- src/api/providers/ollama.ts | 2 +- webview-ui/src/components/settings/ApiOptions.tsx | 8 ++++---- webview-ui/src/utils/validate.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/api/providers/ollama.ts b/src/api/providers/ollama.ts index f2134bb..7668bd3 100644 --- a/src/api/providers/ollama.ts +++ b/src/api/providers/ollama.ts @@ -42,7 +42,7 @@ export class OllamaHandler implements ApiHandler { getModel(): { id: string; info: ModelInfo } { return { - id: this.options.ollamaModelId ?? "", + id: this.options.ollamaModelId || "", info: openAiModelInfoSaneDefaults, } } diff --git a/webview-ui/src/components/settings/ApiOptions.tsx b/webview-ui/src/components/settings/ApiOptions.tsx index 1d746e2..e708fbc 100644 --- a/webview-ui/src/components/settings/ApiOptions.tsx +++ b/webview-ui/src/components/settings/ApiOptions.tsx @@ -724,19 +724,19 @@ export function normalizeApiConfiguration(apiConfiguration?: ApiConfiguration) { case "openrouter": return { selectedProvider: provider, - selectedModelId: apiConfiguration?.openRouterModelId ?? openRouterDefaultModelId, - selectedModelInfo: apiConfiguration?.openRouterModelInfo ?? openRouterDefaultModelInfo, + selectedModelId: apiConfiguration?.openRouterModelId || openRouterDefaultModelId, + selectedModelInfo: apiConfiguration?.openRouterModelInfo || openRouterDefaultModelInfo, } case "openai": return { selectedProvider: provider, - selectedModelId: apiConfiguration?.openAiModelId ?? "", + selectedModelId: apiConfiguration?.openAiModelId || "", selectedModelInfo: openAiModelInfoSaneDefaults, } case "ollama": return { selectedProvider: provider, - selectedModelId: apiConfiguration?.ollamaModelId ?? "", + selectedModelId: apiConfiguration?.ollamaModelId || "", selectedModelInfo: openAiModelInfoSaneDefaults, } default: diff --git a/webview-ui/src/utils/validate.ts b/webview-ui/src/utils/validate.ts index dd3ec58..060e0f6 100644 --- a/webview-ui/src/utils/validate.ts +++ b/webview-ui/src/utils/validate.ts @@ -59,7 +59,7 @@ export function validateModelId( if (apiConfiguration) { switch (apiConfiguration.apiProvider) { case "openrouter": - const modelId = apiConfiguration.openRouterModelId ?? openRouterDefaultModelId // in case the user hasn't changed the model id, it will be undefined by default + const modelId = apiConfiguration.openRouterModelId || openRouterDefaultModelId // in case the user hasn't changed the model id, it will be undefined by default if (!modelId) { return "You must provide a model ID." }