|
56 | 56 | ) |
57 | 57 | from .fake_id import FAKE_RESPONSES_ID |
58 | 58 |
|
59 | | -ResponseInputContentWithAudioParam = Union[ResponseInputContentParam, ResponseInputAudioParam] |
| 59 | +ResponseInputContentWithAudioParam = Union[ |
| 60 | + ResponseInputContentParam, |
| 61 | + ResponseInputAudioParam, |
| 62 | + dict[str, Any], |
| 63 | +] |
60 | 64 |
|
61 | 65 |
|
62 | 66 | class Converter: |
@@ -309,10 +313,14 @@ def extract_text_content( |
309 | 313 | all_content = cls.extract_all_content(content) |
310 | 314 | if isinstance(all_content, str): |
311 | 315 | return all_content |
| 316 | + |
312 | 317 | out: list[ChatCompletionContentPartTextParam] = [] |
313 | 318 | for c in all_content: |
314 | | - if c.get("type") == "text": |
| 319 | + c_type = cast(dict[str, Any], c).get("type") |
| 320 | + if c_type == "text": |
315 | 321 | out.append(cast(ChatCompletionContentPartTextParam, c)) |
| 322 | + elif c_type == "video_url": |
| 323 | + raise UserError(f"Only text content is supported here, got: {c}") |
316 | 324 | return out |
317 | 325 |
|
318 | 326 | @classmethod |
@@ -352,6 +360,19 @@ def extract_all_content( |
352 | 360 | }, |
353 | 361 | ) |
354 | 362 | ) |
| 363 | + elif isinstance(c, dict) and c.get("type") == "video_url": |
| 364 | + video_payload = c.get("video_url") |
| 365 | + if not isinstance(video_payload, dict) or not video_payload.get("url"): |
| 366 | + raise UserError(f"Only video URLs are supported for video_url {c}") |
| 367 | + out.append( |
| 368 | + cast( |
| 369 | + Any, |
| 370 | + { |
| 371 | + "type": "video_url", |
| 372 | + "video_url": {"url": video_payload["url"]}, |
| 373 | + }, |
| 374 | + ) |
| 375 | + ) |
355 | 376 | elif isinstance(c, dict) and c.get("type") == "input_audio": |
356 | 377 | casted_audio_param = cast(ResponseInputAudioParam, c) |
357 | 378 | audio_payload = casted_audio_param.get("input_audio") |
@@ -657,7 +678,15 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam: |
657 | 678 | if preserve_tool_output_all_content: |
658 | 679 | tool_result_content = cls.extract_all_content(output_content) |
659 | 680 | else: |
660 | | - tool_result_content = cls.extract_text_content(output_content) # type: ignore[assignment] |
| 681 | + all_output_content = cls.extract_all_content(output_content) |
| 682 | + if isinstance(all_output_content, str): |
| 683 | + tool_result_content = all_output_content |
| 684 | + else: |
| 685 | + tool_result_content = [ |
| 686 | + cast(ChatCompletionContentPartTextParam, c) |
| 687 | + for c in all_output_content |
| 688 | + if c.get("type") == "text" |
| 689 | + ] |
661 | 690 | msg: ChatCompletionToolMessageParam = { |
662 | 691 | "role": "tool", |
663 | 692 | "tool_call_id": func_output["call_id"], |
|
0 commit comments