MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / anthropic_native_sse

Function anthropic_native_sse

uncommon_route/proxy.py:5473–5496  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5471
5472 if native_anthropic_transport:
5473 async def anthropic_native_sse() -> AsyncGenerator[bytes, None]:
5474 stream_chunks: list[bytes] = []
5475 converter = None if api_format == "anthropic" else AnthropicToOpenAIStreamConverter(model=selected_model)
5476 try:
5477 async for chunk in stream_resp.aiter_bytes():
5478 stream_chunks.append(chunk)
5479 if converter is None:
5480 yield chunk
5481 else:
5482 for ev in converter.feed(chunk):
5483 yield ev
5484 if converter is not None:
5485 for ev in converter.finish():
5486 yield ev
5487 await _record_stream_success(
5488 parse_stream_usage_metrics(stream_chunks, selected_model, _get_pricing()),
5489 stream_chunks=stream_chunks,
5490 )
5491 except Exception:
5492 await _record_stream_failure()
5493 raise
5494 finally:
5495 await _record_stream_aborted(stream_chunks=stream_chunks)
5496 await stream_resp.aclose()
5497
5498 return StreamingResponse(
5499 anthropic_native_sse(),

Callers 1

_handle_chat_coreFunction · 0.85

Calls 9

_record_stream_successFunction · 0.85
_get_pricingFunction · 0.85
_record_stream_failureFunction · 0.85
_record_stream_abortedFunction · 0.85
appendMethod · 0.45
feedMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected