Skip to content

Add {date} replacement to chat - #17430

Merged
wangq8 merged 6 commits into
infiniflow:mainfrom
wangq8:feature/add-current-time-injection
Jul 28, 2026
Merged

wangq8 merged 6 commits into
infiniflow:mainfrom
wangq8:feature/add-current-time-injection

Conversation

@wangq8

@wangq8 wangq8 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@wangq8 wangq8 added the ci Continue Integration label Jul 27, 2026
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3fde3ea9-30fa-476f-9fc8-16947e6fc519

📥 Commits

Reviewing files that changed from the base of the PR and between e3ebd93 and 5a4e201.

📒 Files selected for processing (1)
  • test/testcases/restful_api/test_chats.py

📝 Walkthrough

Walkthrough

Prompt configurations now declare an optional date parameter. Chat service paths populate it with the current UTC timestamp and apply it to system prompts for streaming and non-streaming LLM calls.

Changes

Date prompt support

Layer / File(s) Summary
Prompt parameter contract
api/apps/restful_apis/chat_api.py, web/src/pages/next-chats/hooks/use-create-chat.ts, test/testcases/restful_api/test_chats.py
Default and newly created chat prompt configurations include an optional date parameter, with the saved configuration assertion updated.
UTC date rendering
api/db/services/dialog_service.py
Chat flows generate a UTC timestamp and substitute it into system prompts before streaming or non-streaming LLM requests.

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
Loading

Suggested reviewers: 6ba3i, jinhai-cn, buua436

Poem

A rabbit checks the prompt at dawn,
Adds today before it’s gone.
UTC hops through every line,
Streaming words in date-time rhyme.
“Fresh context!” the bunny cheers.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided, so the required Summary section and background context are missing. Add a Summary section that briefly explains the change, its purpose, and any relevant context for reviewers.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding {date} handling to chat prompts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
api/db/services/dialog_service.py (1)

338-344: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add 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 automatic date parameter 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6e1e540 and e3ebd93.

📒 Files selected for processing (3)
  • api/apps/restful_apis/chat_api.py
  • api/db/services/dialog_service.py
  • web/src/pages/next-chats/hooks/use-create-chat.ts

@codecov

codecov Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (5bfd59f) to head (883b7fb).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_solo uses a direct .replace("{date}", sys_date), while async_chat leverages the existing prompt_config["system"].format(**kwargs) at line 819 — both correct.
  • No duplication: _apply_prompt_defaults checks for existing date param before adding.
  • Frontend sync: use-create-chat.ts updated to match backend defaults.
  • Low-risk change: optional parameter, minimal lines, no breaking changes.

Items to consider ⚠️

  1. Inconsistent guard logic in _apply_prompt_defaults
    The knowledge parameter is only added when "{knowledge}" in system_prompt, but date is 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.

  2. str.replace could 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. Using re.sub(r"\{date\}", sys_date, system_prompt) would be a safer alternative if this edge case matters.

  3. Missing test for the {date} replacement itself
    The existing test in test_chats.py only 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.

  4. 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.

  5. In async_chat_solo the sys_date variable 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.

@wangq8
wangq8 merged commit 619b58f into infiniflow:main Jul 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant