fix: inject current date into summary prompt to prevent AI temporal confusion#2529
fix: inject current date into summary prompt to prevent AI temporal confusion#2529ursazoo wants to merge 1 commit intokarakeep-app:mainfrom
Conversation
AI 模型在生成摘要时不知道当前日期,会将文章中提到的近期日期(如2026年) 误判为"未来时间点,可能有误"。在 constructSummaryPrompt 中注入当前日期, 让模型准确判断文章中的时间引用是否真正过时。
WalkthroughThe pull request adds a new local constant capturing today's ISO date to the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/shared/prompts.ts (1)
76-76: Consider making the date injectable for deterministic tests.
Line 76makes prompt output time-dependent; an optionaltodayparameter (with the current expression as default) keeps runtime behavior while making tests/snapshots stable.♻️ Proposed refactor
export function constructSummaryPrompt( lang: string, customPrompts: string[], content: string, + today: string = new Date().toISOString().split("T")[0], ): string { - const today = new Date().toISOString().split("T")[0]; return ` Summarize the following content responding ONLY with the summary. You MUST follow the following rules: - Summary must be in 3-4 sentences. - The summary must be in ${lang}. - Today's date is ${today}. Do NOT flag or question dates that are in the past relative to today. ${customPrompts && customPrompts.map((p) => `- ${p}`).join("\n")} ${content}`; }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/shared/prompts.ts` at line 76, Replace the hard-coded today value with an injectable optional parameter so prompts are deterministic: change the local constant initialization (const today = new Date().toISOString().split("T")[0];) to accept a parameter (e.g., today?: string = new Date().toISOString().split("T")[0]) on the function that constructs the prompt in packages/shared/prompts.ts, use that parameter where the current today variable is referenced, and update callers/tests to pass a fixed date in unit tests while leaving runtime callers to rely on the default.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/shared/prompts.ts`:
- Line 76: Replace the hard-coded today value with an injectable optional
parameter so prompts are deterministic: change the local constant initialization
(const today = new Date().toISOString().split("T")[0];) to accept a parameter
(e.g., today?: string = new Date().toISOString().split("T")[0]) on the function
that constructs the prompt in packages/shared/prompts.ts, use that parameter
where the current today variable is referenced, and update callers/tests to pass
a fixed date in unit tests while leaving runtime callers to rely on the default.
Greptile SummaryThis PR fixes an issue where AI models generating article summaries would incorrectly flag recent dates (like "2026") as questionable because they don't know the current date and reason from their training cutoff year. The fix injects the current date into the Key changes:
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: d313932 |
Problem
When the AI model generates summaries, it doesn't know the current date. This causes it to incorrectly flag recent dates in articles (e.g., "2026 ClawHub trending list") as potentially erroneous in the summary's "questionable claims" section, because the model reasons from its training cutoff year rather than the actual current date.
Solution
Inject today's date (
new Date().toISOString().split('T')[0]) intoconstructSummaryPromptas an explicit rule. This is computed at runtime so it always reflects the server's actual current date.Changes
packages/shared/prompts.ts: Added current date injection inconstructSummaryPromptTest plan