| 588 | |
| 589 | |
| 590 | def _extract_assistant_text(content: bytes) -> str: |
| 591 | try: |
| 592 | data = json.loads(content) |
| 593 | except Exception: |
| 594 | return "" |
| 595 | choices = data.get("choices") or [] |
| 596 | if not choices: |
| 597 | return "" |
| 598 | message = choices[0].get("message") or {} |
| 599 | text = message.get("content", "") |
| 600 | if isinstance(text, str): |
| 601 | return text |
| 602 | if isinstance(text, list): |
| 603 | parts: list[str] = [] |
| 604 | for item in text: |
| 605 | if isinstance(item, dict) and item.get("type") == "text": |
| 606 | parts.append(item.get("text", "")) |
| 607 | return "\n".join(parts) |
| 608 | return str(text) |
| 609 | |
| 610 | |
| 611 | def _normalize_reasoning_content_chunk(raw: bytes) -> bytes: |