mirror of
https://github.com/open-webui/computer.git
synced 2026-11-22 21:50:43 -05:00
refac
This commit is contained in:
1 parent
5ae2218f24
commit
fa2b38b2bc
1 file changed
+11
@@ -779,6 +779,12 @@ async def stream_openai_completions(
|
||||
emitted = True
|
||||
yield {"type": "output", "item": item}
|
||||
raw = chunk["usage"]
|
||||
usage_tokens = sum(
|
||||
raw.get(key, 0)
|
||||
for key in ("prompt_tokens", "completion_tokens", "total_tokens")
|
||||
)
|
||||
if not emitted and usage_tokens <= 0:
|
||||
continue
|
||||
emitted = True
|
||||
yield {
|
||||
"type": "usage",
|
||||
@@ -792,6 +798,11 @@ async def stream_openai_completions(
|
||||
if item is not None:
|
||||
emitted = True
|
||||
yield {"type": "output", "item": item}
|
||||
if not emitted:
|
||||
raise RuntimeError(
|
||||
"Upstream provider returned an empty completion with no text, "
|
||||
"output items, tool calls, or usage tokens."
|
||||
)
|
||||
emitted = True
|
||||
yield {"type": "done"}
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user