| 16 | |
| 17 | |
| 18 | def _repaired_message(message): |
| 19 | if not isinstance(message, AIMessage) or not isinstance(message.content, list): |
| 20 | return message |
| 21 | if not any( |
| 22 | isinstance(b, dict) and b.get("type") == "thinking" and "thinking" not in b |
| 23 | for b in message.content |
| 24 | ): |
| 25 | return message |
| 26 | content = [ |
| 27 | {**b, "thinking": ""} |
| 28 | if isinstance(b, dict) and b.get("type") == "thinking" and "thinking" not in b |
| 29 | else b |
| 30 | for b in message.content |
| 31 | ] |
| 32 | return message.model_copy(update={"content": content}) |
| 33 | |
| 34 | |
| 35 | def _reordered(request: ModelRequest) -> ModelRequest: |