From 9d5801fb5ff21893c6dfc0417ab65eb99ccc0fdc Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:31:49 +0800 Subject: [PATCH] fix: avoiding not operation for custom models (#4010) --- app/store/chat.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index a3dc940898a..254325a7552 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -92,14 +92,18 @@ function countMessages(msgs: ChatMessage[]) { } function fillTemplateWith(input: string, modelConfig: ModelConfig) { - const cutoff = KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default; + const cutoff = + KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default; // Find the model in the DEFAULT_MODELS array that matches the modelConfig.model - const modelInfo = DEFAULT_MODELS.find(m => m.name === modelConfig.model); - if (!modelInfo) { - throw new Error(`Model ${modelConfig.model} not found in DEFAULT_MODELS array.`); + const modelInfo = DEFAULT_MODELS.find((m) => m.name === modelConfig.model); + + var serviceProvider = "OpenAI"; + if (modelInfo) { + // TODO: auto detect the providerName from the modelConfig.model + + // Directly use the providerName from the modelInfo + serviceProvider = modelInfo.provider.providerName; } - // Directly use the providerName from the modelInfo - const serviceProvider = modelInfo.provider.providerName; const vars = { ServiceProvider: serviceProvider, @@ -119,7 +123,7 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) { } Object.entries(vars).forEach(([name, value]) => { - const regex = new RegExp(`{{${name}}}`, 'g'); + const regex = new RegExp(`{{${name}}}`, "g"); output = output.replace(regex, value.toString()); // Ensure value is a string });