Skip to content

Commit 9794ba8

Browse files
authored
Merge pull request #29 from Mng-dev-ai/fix/streaming-done-exit
Fix streaming completion exit
2 parents 9c747f8 + d41de62 commit 9794ba8

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

anthropic_bridge/providers/openai/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ async def _stream_response(
327327
"output_tokens": resp_usage.get("output_tokens", 0),
328328
}
329329
break
330+
break
330331

331332
except Exception as e:
332333
yield self._sse(

anthropic_bridge/providers/openrouter/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ async def _stream_openrouter(
182182
lines = buffer.split("\n")
183183
buffer = lines.pop()
184184

185+
done = False
185186
for line in lines:
186187
line = line.strip()
187188
if not line or not line.startswith("data: "):
188189
continue
189190

190191
data_str = line[6:]
191192
if data_str == "[DONE]":
193+
done = True
192194
break
193195

194196
try:
@@ -397,6 +399,8 @@ async def _stream_openrouter(
397399
await get_reasoning_cache().set(
398400
t["id"], current_reasoning_details.copy()
399401
)
402+
if done:
403+
break
400404

401405
if thinking_started:
402406
yield self._sse(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "anthropic-bridge"
3-
version = "0.1.25"
3+
version = "0.1.26"
44
description = "Bridge Anthropic API to OpenRouter and OpenAI models."
55
license = "MIT"
66
requires-python = ">=3.11"

0 commit comments

Comments
 (0)