Print a summary of the stream statistics.
(self)
| 424 | return (self.last_event_time - self.first_event_time).total_seconds() |
| 425 | |
| 426 | def summarize(self): |
| 427 | """Print a summary of the stream statistics.""" |
| 428 | print(f"Total chunks: {self.total_chunks}") |
| 429 | print(f"Unique event types: {sorted(list(self.event_types))}") |
| 430 | print(f"Event counts: {json.dumps(self.event_counts, indent=2)}") |
| 431 | print(f"Duration: {self.get_duration():.2f} seconds") |
| 432 | print(f"Has tool use: {self.has_tool_use}") |
| 433 | |
| 434 | # Print the first few lines of content |
| 435 | if self.text_content: |
| 436 | max_preview_lines = 5 |
| 437 | text_preview = "\n".join(self.text_content.strip().split("\n")[:max_preview_lines]) |
| 438 | print(f"Text preview:\n{text_preview}") |
| 439 | else: |
| 440 | print("No text content extracted") |
| 441 | |
| 442 | if self.has_error: |
| 443 | print(f"Error: {self.error_message}") |
| 444 | |
| 445 | async def stream_response(url, headers, data, stream_name): |
| 446 | """Send a streaming request and process the response.""" |
no test coverage detected