mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 09:21:22 +00:00
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.
This commit is contained in:
parent
a5933798b2
commit
653e2ce3b4
1 changed files with 7 additions and 4 deletions
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue