bug: Anthropic provider: `system` sent as plain string — prompt caching never engages
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Bắt đầu tại cptr/utils/ai.py, ở stream_anthropic và chat_completion, hai luồng yêu cầu được nêu trong issue. Kiểm tra cách mỗi luồng xây dựng trường system của Anthropic và xem lại các bài kiểm thử hiện có cho những luồng này; issue không nêu tên tệp kiểm thử. Hoàn thành khi cả hai luồng gửi lời nhắc hệ thống dưới dạng khối văn bản được lưu trong bộ nhớ đệm, đồng thời giữ nguyên điều kiện bảo vệ khi system rỗng, và báo cáo mức sử dụng của Anthropic cho biết bộ nhớ đệm được tạo ở lượt đầu tiên và được đọc ở các lượt sau.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
The Anthropic provider sends system as a plain string in the /v1/messages body. Anthropic only creates a cache entry when a system text block carries a cache_control breakpoint — a plain string is never eligible. Result: prompt caching is silently dead for every Anthropic connection; each turn of a chat re-reads the entire system prompt at full input-token price (no cache_creation_input_tokens / cache_read_input_tokens in the Anthropic usage analytics).
Where (cptr/utils/ai.py, HEAD):
stream_anthropic(line ~437) — the main chat path:body = { "model": form_data.model, "system": form_data.instructions, ... }chat_completion(line ~144) — the non-streaming path (title/summary generation):if system: body["system"] = system
Proposed fix
Send the system as a cached block list in both call sites:
body["system"] = [
{
"type": "text",
"text": system,
"cache_control": {"type": "ephemeral"},
}
]
(Keep the if system: / empty→None guard as-is.)
Notes
- Anthropic's minimum cacheable prefix is 1024 tokens; cptr's system prompt (instructions + memory + skills + tools) comfortably exceeds it, so the breakpoint pays off from the second turn of every chat.
- The client side is already ready:
stream_anthropicparsescache_read_input_tokensandcache_creation_input_tokensfrom the response usage — only the request side never opts in. - #27 ("feat: ephemeral caching header for anthropic models") asked for a per-model configurable ephemeral cache header and was closed 2026-06-11 with "Request parameters support added". That makes caching possible via per-model
request_params, but the provider's default still sends a plain string, so nothing is cached unless the user wires it up manually. Making the breakpoint the default (still overridable viarequest_params) would fix it for everyone.
Verification
After the fix: first turn of a chat shows cache_creation_input_tokens > 0, subsequent turns show cache_read_input_tokens > 0 — visible in the Anthropic console usage analytics and in cptr's per-request usage logging.
- Ngôn ngữ chính
- Python
- Star
- 768
- Fork
- 108
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của open-webui/computer
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
open-webui/computer#327 · 7 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
open-webui/computer#324 · 3 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
open-webui/computer#314 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
open-webui/computer#293 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
open-webui/computer#286 · 1 bình luận ·
Tất cả issue của open-webui/computer
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Groundskeeper-robot/groundskeeper#248 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
containers/podman-compose#1640 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
debpalash/VoiceStudio#4550 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fundamentals step:6
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
voantony/OpenCourtVision#244 ·
Maintainer thường phản hồi trong vòng 1 ngày