mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	Refactor KnowledgeCutoff
[+] 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
This commit is contained in:
		@@ -69,9 +69,10 @@ export const OpenaiPath = {
 | 
				
			|||||||
export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
 | 
					export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
 | 
				
			||||||
export const DEFAULT_SYSTEM_TEMPLATE = `
 | 
					export const DEFAULT_SYSTEM_TEMPLATE = `
 | 
				
			||||||
You are ChatGPT, a large language model trained by OpenAI.
 | 
					You are ChatGPT, a large language model trained by OpenAI.
 | 
				
			||||||
Knowledge cutoff: 2021-09
 | 
					Knowledge cutoff: {{knowledgeCutoff}}
 | 
				
			||||||
Current model: {{model}}
 | 
					Current model: {{model}}
 | 
				
			||||||
Current time: {{time}}`;
 | 
					Current time: {{time}}
 | 
				
			||||||
 | 
					`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const SUMMARIZE_MODEL = "gpt-3.5-turbo";
 | 
					export const SUMMARIZE_MODEL = "gpt-3.5-turbo";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -401,22 +401,26 @@ export const useChatStore = createPersistStore(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // system prompts, to get close to OpenAI Web ChatGPT
 | 
					        // system prompts, to get close to OpenAI Web ChatGPT
 | 
				
			||||||
        const shouldInjectSystemPrompts = modelConfig.enableInjectSystemPrompts;
 | 
					        const shouldInjectSystemPrompts = modelConfig.enableInjectSystemPrompts;
 | 
				
			||||||
        const systemPrompts = shouldInjectSystemPrompts
 | 
					        let systemPrompts = shouldInjectSystemPrompts ? [] : [];
 | 
				
			||||||
          ? [
 | 
					
 | 
				
			||||||
              createMessage({
 | 
					 | 
				
			||||||
                role: "system",
 | 
					 | 
				
			||||||
                content: fillTemplateWith("", {
 | 
					 | 
				
			||||||
                  ...modelConfig,
 | 
					 | 
				
			||||||
                  template: DEFAULT_SYSTEM_TEMPLATE,
 | 
					 | 
				
			||||||
                }),
 | 
					 | 
				
			||||||
              }),
 | 
					 | 
				
			||||||
            ]
 | 
					 | 
				
			||||||
          : [];
 | 
					 | 
				
			||||||
        if (shouldInjectSystemPrompts) {
 | 
					        if (shouldInjectSystemPrompts) {
 | 
				
			||||||
          console.log(
 | 
					          const model = modelConfig.model;
 | 
				
			||||||
            "[Global System Prompt] ",
 | 
					          let systemTemplate = DEFAULT_SYSTEM_TEMPLATE;
 | 
				
			||||||
            systemPrompts.at(0)?.content ?? "empty",
 | 
					
 | 
				
			||||||
          );
 | 
					          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
 | 
					        // long term memory
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user