(messages: list[dict[str, Any]])
| 36 | |
| 37 | |
| 38 | def _serialize_response_input(messages: list[dict[str, Any]]) -> list[dict[str, Any]]: |
| 39 | serialized: list[dict[str, Any]] = [] |
| 40 | for message in messages: |
| 41 | role = message["role"] |
| 42 | if role == "exit": |
| 43 | continue |
| 44 | content = message.get("content", "") |
| 45 | if isinstance(content, str): |
| 46 | serialized_content = [text_part(content)] |
| 47 | else: |
| 48 | serialized_content = [part for part in content if isinstance(part, dict)] |
| 49 | # The Responses API accepts "developer" for system-style instructions. |
| 50 | mapped_role = "developer" if role == "system" else role |
| 51 | serialized.append( |
| 52 | { |
| 53 | "type": "message", |
| 54 | "role": mapped_role, |
| 55 | "content": [ |
| 56 | _serialize_response_content_part(part, role=mapped_role) |
| 57 | for part in serialized_content |
| 58 | ], |
| 59 | } |
| 60 | ) |
| 61 | return serialized |
| 62 | |
| 63 | |
| 64 | def _extract_response_text(payload: dict[str, Any]) -> str: |
no test coverage detected