From a5517a1a51de81f9527f2e734d8412f6f4f8962c Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 5 Feb 2024 12:35:51 +0700 Subject: [PATCH 1/2] Improve Default System Template (#3996) * Feat [UI/UX] [Constant] [DEFAULT System Template] replace hardcoded - [+] feat(constant.ts): replace hardcoded OpenAI with dynamic ServiceProvider variable in DEFAULT_SYSTEM_TEMPLATE * Improve [UI/UX] [Chat] "fillTemplateWith" - [+] feat(chat.ts): add DEFAULT_MODELS to modelConfig - [+] fix(chat.ts): replace replaceAll with regex in output string replacement - [+] refactor(chat.ts): use const instead of let for cutoff variable --- app/constant.ts | 2 +- app/store/chat.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/constant.ts b/app/constant.ts index fc49e3dbc53..68d0e139506 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -95,7 +95,7 @@ export const Google = { export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang export const DEFAULT_SYSTEM_TEMPLATE = ` -You are ChatGPT, a large language model trained by OpenAI. +You are ChatGPT, a large language model trained by {{ServiceProvider}}. Knowledge cutoff: {{cutoff}} Current model: {{model}} Current time: {{time}} diff --git a/app/store/chat.ts b/app/store/chat.ts index dff6b7bf1c6..a3dc940898a 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -6,6 +6,7 @@ import { ModelConfig, ModelType, useAppConfig } from "./config"; import { createEmptyMask, Mask } from "./mask"; import { DEFAULT_INPUT_TEMPLATE, + DEFAULT_MODELS, DEFAULT_SYSTEM_TEMPLATE, KnowledgeCutOffDate, ModelProvider, @@ -91,10 +92,17 @@ function countMessages(msgs: ChatMessage[]) { } function fillTemplateWith(input: string, modelConfig: ModelConfig) { - let 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.`); + } + // Directly use the providerName from the modelInfo + const serviceProvider = modelInfo.provider.providerName; const vars = { + ServiceProvider: serviceProvider, cutoff, model: modelConfig.model, time: new Date().toLocaleString(), @@ -111,7 +119,8 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) { } Object.entries(vars).forEach(([name, value]) => { - output = output.replaceAll(`{{${name}}}`, value); + const regex = new RegExp(`{{${name}}}`, 'g'); + output = output.replace(regex, value.toString()); // Ensure value is a string }); return output; From bb26c03141473c9437827ceb559d43041b149604 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 5 Feb 2024 13:44:46 +0700 Subject: [PATCH 2/2] Feat [UI/UX] [Constants] [Models] gemini-pro KnowledgeCutOffDate (#3997) - [+] feat(constant.ts): add 'gemini-pro' to KnowledgeCutOffDate constant --- app/constant.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/constant.ts b/app/constant.ts index 68d0e139506..f0e895ed9a0 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -111,6 +111,9 @@ export const KnowledgeCutOffDate: Record = { "gpt-4-1106-preview": "2023-04", "gpt-4-0125-preview": "2023-04", "gpt-4-vision-preview": "2023-04", + // After improvements, + // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously. + "gemini-pro": "2023-12", }; export const DEFAULT_MODELS = [