From 653e2ce3b459fb30454c8ae5859e1f9ab51367bb Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sun, 30 Aug 2026 22:18:35 +0200 Subject: [PATCH] refactor: read tool['arguments'] directly in the JSON completion guard Restores the pre-existing comment above the guard to its original wording and drops the `buffered` local, so the guard and the parse call both read `tool['arguments']`, the name the rest of the file already uses for that buffer. Behaviour is unchanged: same three conditions in the same order, same short-circuit result. --- backend/open_webui/utils/anthropic.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/utils/anthropic.py b/backend/open_webui/utils/anthropic.py index 46028d8d1e..cc8392bdc1 100644 --- a/backend/open_webui/utils/anthropic.py +++ b/backend/open_webui/utils/anthropic.py @@ -874,15 +874,18 @@ async def openai_stream_to_anthropic_stream(openai_stream_generator, model: str } yield f'event: content_block_delta\ndata: {JSONCodec.dumps(block_delta)}\n\n'.encode() - # Close the block once arguments form complete JSON, without re-parsing on every chunk - buffered = tool['arguments'] + # Close the block once arguments form complete JSON if ( tool['started'] and not tool['stopped'] - and (buffered[-1] == '}' or buffered[-1].isspace() or buffered[0] != '{') + and ( + tool['arguments'][-1] == '}' + or tool['arguments'][-1].isspace() + or tool['arguments'][0] != '{' + ) ): try: - JSONCodec.loads(buffered) + JSONCodec.loads(tool['arguments']) tool['stopped'] = True block_stop = { 'type': 'content_block_stop',