fix: #3152 system prompt should be injected

This commit is contained in:
Yidadaa
2023-11-07 23:54:30 +08:00
parent 6e52d14180
commit 836bf836d3
2 changed files with 28 additions and 20 deletions

View File

@@ -7,6 +7,7 @@ import { createEmptyMask, Mask } from "./mask";
import {
DEFAULT_INPUT_TEMPLATE,
DEFAULT_SYSTEM_TEMPLATE,
KnowledgeCutOffDate,
StoreKey,
SUMMARIZE_MODEL,
} from "../constant";
@@ -116,7 +117,11 @@ function countMessages(msgs: ChatMessage[]) {
}
function fillTemplateWith(input: string, modelConfig: ModelConfig) {
let cutoff =
KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default;
const vars = {
cutoff,
model: modelConfig.model,
time: new Date().toLocaleString(),
lang: getLang(),
@@ -401,26 +406,22 @@ export const useChatStore = createPersistStore(
// system prompts, to get close to OpenAI Web ChatGPT
const shouldInjectSystemPrompts = modelConfig.enableInjectSystemPrompts;
let systemPrompts = shouldInjectSystemPrompts ? [] : [];
const systemPrompts = shouldInjectSystemPrompts
? [
createMessage({
role: "system",
content: fillTemplateWith("", {
...modelConfig,
template: DEFAULT_SYSTEM_TEMPLATE,
}),
}),
]
: [];
if (shouldInjectSystemPrompts) {
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);
console.log(
"[Global System Prompt] ",
systemPrompts.at(0)?.content ?? "empty",
);
}
// long term memory