mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-03 02:59:07 +08:00
feat(utils): show weekday in date and datetime prompt variables (#9362)
* feat(utils): 优化日期时间变量替换格式
为 {{date}} 和 {{datetime}} 变量替换添加更详细的格式选项,包括星期、年月日和时间信息
* test(prompt): 更新测试中日期时间的本地化格式
This commit is contained in:
parent
0e750c64db
commit
a671f95bee
@ -133,7 +133,15 @@ describe('prompt', () => {
|
|||||||
const result = await replacePromptVariables(userPrompt, assistant.model?.name)
|
const result = await replacePromptVariables(userPrompt, assistant.model?.name)
|
||||||
const expectedPrompt = `
|
const expectedPrompt = `
|
||||||
以下是一些辅助信息:
|
以下是一些辅助信息:
|
||||||
- 日期和时间: ${mockDate.toLocaleString()};
|
- 日期和时间: ${mockDate.toLocaleString(undefined, {
|
||||||
|
weekday: 'short',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
day: 'numeric',
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: 'numeric',
|
||||||
|
second: 'numeric'
|
||||||
|
})};
|
||||||
- 操作系统: macOS;
|
- 操作系统: macOS;
|
||||||
- 中央处理器架构: darwin64;
|
- 中央处理器架构: darwin64;
|
||||||
- 语言: zh-CN;
|
- 语言: zh-CN;
|
||||||
@ -176,7 +184,12 @@ describe('prompt', () => {
|
|||||||
basePrompt = await replacePromptVariables(initialPrompt, assistant.model?.name)
|
basePrompt = await replacePromptVariables(initialPrompt, assistant.model?.name)
|
||||||
expectedBasePrompt = `
|
expectedBasePrompt = `
|
||||||
System Information:
|
System Information:
|
||||||
- Date: ${mockDate.toLocaleDateString()}
|
- Date: ${mockDate.toLocaleDateString(undefined, {
|
||||||
|
weekday: 'short',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
day: 'numeric'
|
||||||
|
})}
|
||||||
- User: MockUser
|
- User: MockUser
|
||||||
|
|
||||||
Instructions: Be helpful.
|
Instructions: Be helpful.
|
||||||
@ -239,7 +252,12 @@ describe('prompt', () => {
|
|||||||
const basePrompt = await replacePromptVariables(initialPrompt, assistant.model?.name)
|
const basePrompt = await replacePromptVariables(initialPrompt, assistant.model?.name)
|
||||||
const expectedBasePrompt = `
|
const expectedBasePrompt = `
|
||||||
System Information:
|
System Information:
|
||||||
- Date: ${mockDate.toLocaleDateString()}
|
- Date: ${mockDate.toLocaleDateString(undefined, {
|
||||||
|
weekday: 'short',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'numeric',
|
||||||
|
day: 'numeric'
|
||||||
|
})}
|
||||||
- User: MockUser
|
- User: MockUser
|
||||||
|
|
||||||
Instructions: Be helpful.
|
Instructions: Be helpful.
|
||||||
|
|||||||
@ -176,7 +176,12 @@ export const replacePromptVariables = async (userSystemPrompt: string, modelName
|
|||||||
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
if (userSystemPrompt.includes('{{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)
|
userSystemPrompt = userSystemPrompt.replace(/{{date}}/g, date)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +191,15 @@ export const replacePromptVariables = async (userSystemPrompt: string, modelName
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (userSystemPrompt.includes('{{datetime}}')) {
|
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)
|
userSystemPrompt = userSystemPrompt.replace(/{{datetime}}/g, datetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user