|
18 | 18 | """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" |
19 | 19 |
|
20 | 20 | from __future__ import annotations |
| 21 | +from .. import BaseModel |
| 22 | +from ...utils.unions import parse_open_union |
21 | 23 | from .audioresponseformat import AudioResponseFormat, AudioResponseFormatParam |
22 | 24 | from .imageresponseformat import ImageResponseFormat, ImageResponseFormatParam |
23 | 25 | from .textresponseformat import TextResponseFormat, TextResponseFormatParam |
24 | 26 | from .videoresponseformat import VideoResponseFormat, VideoResponseFormatParam |
25 | | -from typing import Any, Dict, Union |
26 | | -from typing_extensions import TypeAliasType |
| 27 | +from functools import partial |
| 28 | +from pydantic import ConfigDict |
| 29 | +from pydantic.functional_validators import BeforeValidator |
| 30 | +from typing import Any, Literal, Union |
| 31 | +from typing_extensions import Annotated, TypeAliasType |
27 | 32 |
|
28 | 33 |
|
29 | 34 | ResponseFormatParam = TypeAliasType( |
|
33 | 38 | AudioResponseFormatParam, |
34 | 39 | ImageResponseFormatParam, |
35 | 40 | VideoResponseFormatParam, |
36 | | - Dict[str, Any], |
37 | 41 | ], |
38 | 42 | ) |
39 | 43 |
|
40 | 44 |
|
41 | | -ResponseFormat = TypeAliasType( |
42 | | - "ResponseFormat", |
| 45 | +class UnknownResponseFormat(BaseModel): |
| 46 | + r"""A ResponseFormat variant the SDK doesn't recognize. Preserves the raw payload.""" |
| 47 | + |
| 48 | + type: Literal["UNKNOWN"] = "UNKNOWN" |
| 49 | + raw: Any |
| 50 | + is_unknown: Literal[True] = True |
| 51 | + |
| 52 | + model_config = ConfigDict(frozen=True) |
| 53 | + |
| 54 | + |
| 55 | +_RESPONSE_FORMAT_VARIANTS: dict[str, Any] = { |
| 56 | + "audio": AudioResponseFormat, |
| 57 | + "image": ImageResponseFormat, |
| 58 | + "text": TextResponseFormat, |
| 59 | + "video": VideoResponseFormat, |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | +ResponseFormat = Annotated[ |
43 | 64 | Union[ |
44 | | - TextResponseFormat, |
45 | 65 | AudioResponseFormat, |
46 | 66 | ImageResponseFormat, |
| 67 | + TextResponseFormat, |
47 | 68 | VideoResponseFormat, |
48 | | - Dict[str, Any], |
| 69 | + UnknownResponseFormat, |
49 | 70 | ], |
50 | | -) |
| 71 | + BeforeValidator( |
| 72 | + partial( |
| 73 | + parse_open_union, |
| 74 | + disc_key="type", |
| 75 | + variants=_RESPONSE_FORMAT_VARIANTS, |
| 76 | + unknown_cls=UnknownResponseFormat, |
| 77 | + union_name="ResponseFormat", |
| 78 | + lenient=True, |
| 79 | + ) |
| 80 | + ), |
| 81 | +] |
0 commit comments