mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 09:21:22 +00:00
fix: prompt cache markers on tool results are dropped before reaching the provider (#33757)
Tool results sent through an OpenAI-compatible gateway lose their prompt cache marker right before the request leaves, so Anthropic models behind OpenRouter or LiteLLM never cache the prefix in tool loops. Now the marker is kept on a single text block when a tool result carries one. Tool results without a marker are sent exactly as before. Fixes #33755
This commit is contained in:
parent
d221a4f69b
commit
1be39d2f32
1 changed files with 8 additions and 2 deletions
|
|
@ -1559,8 +1559,14 @@ async def generate_chat_completion(
|
|||
if not is_responses and 'messages' in payload:
|
||||
for message in payload['messages']:
|
||||
if message.get('role') == 'tool' and isinstance(message.get('content'), list):
|
||||
message['content'] = ''.join(
|
||||
part.get('text', '') for part in message['content'] if part.get('type') in ('input_text', 'text')
|
||||
parts = message['content']
|
||||
text = ''.join(part.get('text', '') for part in parts if part.get('type') in ('input_text', 'text'))
|
||||
cache_control = next(
|
||||
(part['cache_control'] for part in reversed(parts) if part.get('cache_control')), None
|
||||
)
|
||||
# Prompt-cache markers only work on a content block, so keep the text as one
|
||||
message['content'] = (
|
||||
[{'type': 'text', 'text': text, 'cache_control': cache_control}] if cache_control and text else text
|
||||
)
|
||||
|
||||
is_streaming_request = bool(payload.get('stream', False))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue