From a64f1c9cf088af5d5047126c9099ea4d674cc70c Mon Sep 17 00:00:00 2001 From: rokieg77-alt Date: Tue, 16 Jun 2026 16:58:47 +0800 Subject: [PATCH] perf(prompts): use date-level current_date to preserve prompt-prefix caching (#2271) create_chat_header_prompt rendered current_date with sub-second datetime.now().isoformat() into the system prompt header, before the guidelines and retrieved-context blocks. Since it changes every request, the system-prompt prefix is never byte-stable, which defeats LLM prompt-prefix caching (OpenAI automatic prefix caching, Anthropic cache_control, local KV-cache reuse). Use date-level granularity; the model only needs the calendar date for relative-date reasoning and the prefix stays stable within a day. Co-authored-by: Claude Opus 4.8 --- private_gpt/components/prompts/prompt_builder.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/private_gpt/components/prompts/prompt_builder.py b/private_gpt/components/prompts/prompt_builder.py index f7665889..938db329 100644 --- a/private_gpt/components/prompts/prompt_builder.py +++ b/private_gpt/components/prompts/prompt_builder.py @@ -117,7 +117,12 @@ class PromptBuilderService: assistant_name=assistant_name or settings().chat.assistant_name, assistant_description=assistant_description or settings().chat.assistant_description, - current_date=current_date.astimezone().isoformat(), + # Use date-level granularity: a sub-second timestamp here changes on + # every request and sits at the front of the system prompt (before the + # guidelines and retrieved context), which defeats LLM prompt-prefix + # caching (e.g. OpenAI automatic prefix caching, local KV-cache reuse). + # The model only needs the calendar date for relative-date reasoning. + current_date=current_date.astimezone().date().isoformat(), ) def create_chat_context_for_system_prompt(