From b2e9f90a808bce926ef50450786720f0e38ae287 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Tue, 7 Nov 2023 06:49:14 +0700 Subject: [PATCH] Refactor KnowledgeCutoff (#59) [+] fix(constant.ts): update DEFAULT_SYSTEM_TEMPLATE to include knowledgeCutoff and time variables [+] feat(chat.ts): add support for injecting system prompts based on model configuration --- app/constant.ts | 5 +++-- app/store/chat.ts | 34 +++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/constant.ts b/app/constant.ts index 8f69caadc7b..b9d6d873221 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -79,9 +79,10 @@ export const OpenaiPath = { 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. -Knowledge cutoff: 2021-09 +Knowledge cutoff: {{knowledgeCutoff}} Current model: {{model}} -Current time: {{time}}`; +Current time: {{time}} +`; export const SUMMARIZE_MODEL = "gpt-3.5-turbo"; diff --git a/app/store/chat.ts b/app/store/chat.ts index c12fa2f5141..4f925efeabc 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -402,22 +402,26 @@ export const useChatStore = createPersistStore( // system prompts, to get close to OpenAI Web ChatGPT const shouldInjectSystemPrompts = modelConfig.enableInjectSystemPrompts; - const systemPrompts = shouldInjectSystemPrompts - ? [ - createMessage({ - role: "system", - content: fillTemplateWith("", { - ...modelConfig, - template: DEFAULT_SYSTEM_TEMPLATE, - }), - }), - ] - : []; + let systemPrompts = shouldInjectSystemPrompts ? [] : []; + if (shouldInjectSystemPrompts) { - console.log( - "[Global System Prompt] ", - systemPrompts.at(0)?.content ?? "empty", - ); + const model = modelConfig.model; + let systemTemplate = DEFAULT_SYSTEM_TEMPLATE; + + if (model === "gpt-4-1106-preview" || model === "gpt-4-vision-preview") { + systemTemplate = systemTemplate.replace("{{knowledgeCutoff}}", "2023-04"); + } else { + systemTemplate = systemTemplate.replace("{{knowledgeCutoff}}", "2021-09"); + } + + const systemPrompt = createMessage({ + role: "system", + content: fillTemplateWith("", { + ...modelConfig, + template: systemTemplate, + }), + }); + console.log("[Global System Prompt] ", systemPrompt.content); } // long term memory