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

Function _parse_anthropic_events

tests/test_anthropic_compat.py:561–578  ·  view source on GitHub ↗

Parse Anthropic SSE events into (event_type, data) tuples.

(raw_events: list[bytes])

Source from the content-addressed store, hash-verified

559
560
561def _parse_anthropic_events(raw_events: list[bytes]) -> list[dict]:
562 """Parse Anthropic SSE events into (event_type, data) tuples."""
563 results: list[dict] = []
564 for raw in raw_events:
565 text = raw.decode()
566 lines = text.strip().split("\n")
567 event_type = ""
568 data_str = ""
569 for line in lines:
570 if line.startswith("event: "):
571 event_type = line[7:]
572 elif line.startswith("data: "):
573 data_str = line[6:]
574 if data_str:
575 parsed = json.loads(data_str)
576 parsed["_event"] = event_type
577 results.append(parsed)
578 return results
579
580
581def _parse_openai_events(raw_events: list[bytes]) -> tuple[list[dict], bool]:

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected