Skip to content

Commit 05086dc

Browse files
committed
Revert streaming to v0.1.1 approach to fix hang
- Use continue instead of break for [DONE] handling - Remove done flag and explicit outer loop break - Rely on natural HTTP connection close - Fix duplicate break in OpenAI provider - Use conditional stop_reason (tool_use vs end_turn)
1 parent d91290e commit 05086dc

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

anthropic_bridge/providers/openai/client.py

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

332331
except Exception as e:
333332
yield self._sse(
@@ -370,7 +369,7 @@ async def _stream_response(
370369
{
371370
"type": "message_delta",
372371
"delta": {
373-
"stop_reason": "end_turn",
372+
"stop_reason": "tool_use" if saw_tool_use else "end_turn",
374373
"stop_sequence": None,
375374
},
376375
"usage": usage,

anthropic_bridge/providers/openrouter/client.py

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

185-
done = False
186185
for line in lines:
187186
line = line.strip()
188187
if not line or not line.startswith("data: "):
189188
continue
190189

191190
data_str = line[6:]
192191
if data_str == "[DONE]":
193-
done = True
194-
break
192+
continue
195193

196194
try:
197195
data = json.loads(data_str)
@@ -399,8 +397,6 @@ async def _stream_openrouter(
399397
await get_reasoning_cache().set(
400398
t["id"], current_reasoning_details.copy()
401399
)
402-
if done:
403-
break
404400

405401
if thinking_started:
406402
yield self._sse(
@@ -435,7 +431,7 @@ async def _stream_openrouter(
435431
{
436432
"type": "message_delta",
437433
"delta": {
438-
"stop_reason": "end_turn",
434+
"stop_reason": "tool_use" if saw_tool_use else "end_turn",
439435
"stop_sequence": None,
440436
},
441437
"usage": {

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.27"
3+
version = "0.1.28"
44
description = "Bridge Anthropic API to OpenRouter and OpenAI models."
55
license = "MIT"
66
requires-python = ">=3.11"

0 commit comments

Comments
 (0)