Repository navigation
Add {date} replacement to chat - #17430
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughPrompt configurations now declare an optional ChangesDate prompt support
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant ChatClient
participant DialogService
participant LLM
ChatClient->>DialogService: Start chat request
DialogService->>DialogService: Generate UTC sys_date
DialogService->>LLM: Send system prompt with date substituted
LLM-->>DialogService: Return stream or response
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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)
api/db/services/dialog_service.py (1)
338-344: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd debug logging for the new date-injection paths.
Log the date parameter/default injection without logging prompt contents:
api/db/services/dialog_service.py#L338-L344: log{date}expansion for solo chat.api/apps/restful_apis/chat_api.py#L356-L357: log automaticdateparameter insertion.api/db/services/dialog_service.py#L682-L683: log UTC date injection before prompt formatting.As per coding guidelines:
**/*.py: Add logging for new flows.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/db/services/dialog_service.py` around lines 338 - 344, ضيف debug logging لمسارات حقن التاريخ الثلاثة دون تسجيل محتوى prompts: في api/db/services/dialog_service.py:338-344 سجّل توسعة {date} لمسار solo chat، وفي api/apps/restful_apis/chat_api.py:356-357 سجّل إدراج معامل date تلقائياً، وفي api/db/services/dialog_service.py:682-683 سجّل حقن تاريخ UTC قبل تنسيق prompt؛ استخدم logger القائم ومستوى debug، واذكر قيمة التاريخ أو الإجراء فقط.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@api/db/services/dialog_service.py`:
- Around line 338-344: ضيف debug logging لمسارات حقن التاريخ الثلاثة دون تسجيل
محتوى prompts: في api/db/services/dialog_service.py:338-344 سجّل توسعة {date}
لمسار solo chat، وفي api/apps/restful_apis/chat_api.py:356-357 سجّل إدراج معامل
date تلقائياً، وفي api/db/services/dialog_service.py:682-683 سجّل حقن تاريخ UTC
قبل تنسيق prompt؛ استخدم logger القائم ومستوى debug، واذكر قيمة التاريخ أو
الإجراء فقط.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 0632ca98-68ca-4244-888c-85644d10d1b3
📒 Files selected for processing (3)
api/apps/restful_apis/chat_api.pyapi/db/services/dialog_service.pyweb/src/pages/next-chats/hooks/use-create-chat.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17430 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…8/ragflow into feature/add-current-time-injection
wangq8
left a comment
There was a problem hiding this comment.
PR Review: Add {date} replacement to chat
Author: @wangq8 | State: OPEN | +17 / −8 across 4 files
Overview
This PR adds a {date} placeholder that gets replaced with the current UTC time (YYYY-MM-DD HH:MM:SS) in both the direct chat (async_chat_solo) and agentic chat (async_chat) code paths. The date parameter is also registered as an optional parameter in default prompt configs.
What works well ✅
- Both chat paths covered:
async_chat_solouses a direct.replace("{date}", sys_date), whileasync_chatleverages the existingprompt_config["system"].format(**kwargs)at line 819 — both correct. - No duplication:
_apply_prompt_defaultschecks for existingdateparam before adding. - Frontend sync:
use-create-chat.tsupdated to match backend defaults. - Low-risk change: optional parameter, minimal lines, no breaking changes.
Items to consider ⚠️
-
Inconsistent guard logic in
_apply_prompt_defaults
Theknowledgeparameter is only added when"{knowledge}" in system_prompt, butdateis added unconditionally (as long as it's not already present). Consider aligning:if not any(p.get("key") == "date" for p in prompt_config.get("parameters", [])) and "{date}" in prompt_config.get("system", ""):
This avoids polluting the parameters list when
{date}isn't actually used. -
str.replacecould match partial tokens
system_prompt.replace("{date}", sys_date)will also replace{date}inside strings like{dateformat}or{date_of_birth}, producing e.g.2026-07-27 17:58:00format. Usingre.sub(r"\{date\}", sys_date, system_prompt)would be a safer alternative if this edge case matters. -
Missing test for the
{date}replacement itself
The existing test intest_chats.pyonly verifies the parameter list. Adding a test that actually sends a prompt with{date}and verifies it gets replaced with a date string would increase confidence. -
UTC timezone — is that intentional?
datetime.now(timezone.utc)produces UTC time. For users in other timezones (e.g. Asia/Shanghai), the displayed date will be off by up to 12 hours. This may be fine as a default, but consider whether a tenant-level or user-level timezone setting would be useful in the future. -
In
async_chat_solothesys_datevariable is computed even for non-stream path — this is harmless but could be moved closer to where it's used. Minor nit, not worth blocking.
Verdict
Approve with suggestions. The logic is sound, both code paths are handled, and the risk is low. The _apply_prompt_defaults guard and the timezone question are the two items worth addressing before merge. The rest are nice-to-haves.
No description provided.