|
7 | 7 | from openai import Omit, omit |
8 | 8 | from openai.types.chat import ( |
9 | 9 | ChatCompletionAssistantMessageParam, |
| 10 | + ChatCompletionContentPartInputAudioParam, |
10 | 11 | ChatCompletionContentPartImageParam, |
11 | 12 | ChatCompletionContentPartParam, |
12 | 13 | ChatCompletionContentPartTextParam, |
|
30 | 31 | ResponseInputContentParam, |
31 | 32 | ResponseInputFileParam, |
32 | 33 | ResponseInputImageParam, |
| 34 | + ResponseInputAudioParam, |
33 | 35 | ResponseInputTextParam, |
34 | 36 | ResponseOutputMessage, |
35 | 37 | ResponseOutputMessageParam, |
@@ -287,6 +289,32 @@ def extract_all_content( |
287 | 289 | }, |
288 | 290 | ) |
289 | 291 | ) |
| 292 | + elif isinstance(c, dict) and c.get("type") == "input_audio": |
| 293 | + casted_audio_param = cast(ResponseInputAudioParam, c) |
| 294 | + audio_payload = casted_audio_param.get("input_audio") |
| 295 | + if not audio_payload: |
| 296 | + raise UserError( |
| 297 | + f"Only audio data is supported for input_audio {casted_audio_param}" |
| 298 | + ) |
| 299 | + if not isinstance(audio_payload, dict): |
| 300 | + raise UserError( |
| 301 | + f"input_audio must provide audio data and format {casted_audio_param}" |
| 302 | + ) |
| 303 | + audio_data = audio_payload.get("data") |
| 304 | + audio_format = audio_payload.get("format") |
| 305 | + if not audio_data or not audio_format: |
| 306 | + raise UserError( |
| 307 | + f"input_audio requires both data and format {casted_audio_param}" |
| 308 | + ) |
| 309 | + out.append( |
| 310 | + ChatCompletionContentPartInputAudioParam( |
| 311 | + type="input_audio", |
| 312 | + input_audio={ |
| 313 | + "data": audio_data, |
| 314 | + "format": audio_format, |
| 315 | + }, |
| 316 | + ) |
| 317 | + ) |
290 | 318 | elif isinstance(c, dict) and c.get("type") == "input_file": |
291 | 319 | casted_file_param = cast(ResponseInputFileParam, c) |
292 | 320 | if "file_data" not in casted_file_param or not casted_file_param["file_data"]: |
|
0 commit comments