diff --git a/src/renderer/src/utils/__tests__/prompt.test.ts b/src/renderer/src/utils/__tests__/prompt.test.ts index ab4be618c9..6d990c16eb 100644 --- a/src/renderer/src/utils/__tests__/prompt.test.ts +++ b/src/renderer/src/utils/__tests__/prompt.test.ts @@ -133,7 +133,15 @@ describe('prompt', () => { const result = await replacePromptVariables(userPrompt, assistant.model?.name) const expectedPrompt = ` 以下是一些辅助信息: - - 日期和时间: ${mockDate.toLocaleString()}; + - 日期和时间: ${mockDate.toLocaleString(undefined, { + weekday: 'short', + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric' + })}; - 操作系统: macOS; - 中央处理器架构: darwin64; - 语言: zh-CN; @@ -176,7 +184,12 @@ describe('prompt', () => { basePrompt = await replacePromptVariables(initialPrompt, assistant.model?.name) expectedBasePrompt = ` System Information: - - Date: ${mockDate.toLocaleDateString()} + - Date: ${mockDate.toLocaleDateString(undefined, { + weekday: 'short', + year: 'numeric', + month: 'numeric', + day: 'numeric' + })} - User: MockUser Instructions: Be helpful. @@ -239,7 +252,12 @@ describe('prompt', () => { const basePrompt = await replacePromptVariables(initialPrompt, assistant.model?.name) const expectedBasePrompt = ` System Information: - - Date: ${mockDate.toLocaleDateString()} + - Date: ${mockDate.toLocaleDateString(undefined, { + weekday: 'short', + year: 'numeric', + month: 'numeric', + day: 'numeric' + })} - User: MockUser Instructions: Be helpful. diff --git a/src/renderer/src/utils/prompt.ts b/src/renderer/src/utils/prompt.ts index 4f7b9d5408..85766953ba 100644 --- a/src/renderer/src/utils/prompt.ts +++ b/src/renderer/src/utils/prompt.ts @@ -176,7 +176,12 @@ export const replacePromptVariables = async (userSystemPrompt: string, modelName const now = new Date() if (userSystemPrompt.includes('{{date}}')) { - const date = now.toLocaleDateString() + const date = now.toLocaleDateString(undefined, { + weekday: 'short', + year: 'numeric', + month: 'numeric', + day: 'numeric' + }) userSystemPrompt = userSystemPrompt.replace(/{{date}}/g, date) } @@ -186,7 +191,15 @@ export const replacePromptVariables = async (userSystemPrompt: string, modelName } if (userSystemPrompt.includes('{{datetime}}')) { - const datetime = now.toLocaleString() + const datetime = now.toLocaleString(undefined, { + weekday: 'short', + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric' + }) userSystemPrompt = userSystemPrompt.replace(/{{datetime}}/g, datetime) }