mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-29 11:23:49 +08:00
docs: Mintlify MDX docs + docs.json; bump Speakeasy to 1.787.0 (#382)
This commit is contained in:
@@ -35,6 +35,7 @@ from .outputitemimagegenerationcall import (
|
||||
OutputItemImageGenerationCallTypedDict,
|
||||
)
|
||||
from .outputmessage import OutputMessage, OutputMessageTypedDict
|
||||
from functools import partial
|
||||
from openrouter.types import (
|
||||
BaseModel,
|
||||
Nullable,
|
||||
@@ -42,8 +43,9 @@ from openrouter.types import (
|
||||
UNSET,
|
||||
UNSET_SENTINEL,
|
||||
)
|
||||
from openrouter.utils import get_discriminator
|
||||
from pydantic import Discriminator, Tag, model_serializer
|
||||
from openrouter.utils.unions import parse_open_union
|
||||
from pydantic import ConfigDict, model_serializer
|
||||
from pydantic.functional_validators import BeforeValidator
|
||||
from typing import Any, List, Literal, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
||||
|
||||
@@ -56,14 +58,35 @@ BaseInputsContent1TypedDict = TypeAliasType(
|
||||
)
|
||||
|
||||
|
||||
class UnknownBaseInputsContent1(BaseModel):
|
||||
r"""A BaseInputsContent1 variant the SDK doesn't recognize. Preserves the raw payload."""
|
||||
|
||||
type: Literal["UNKNOWN"] = "UNKNOWN"
|
||||
raw: Any
|
||||
is_unknown: Literal[True] = True
|
||||
|
||||
model_config = ConfigDict(frozen=True)
|
||||
|
||||
|
||||
_BASE_INPUTS_CONTENT_1_VARIANTS: dict[str, Any] = {
|
||||
"input_audio": InputAudio,
|
||||
"input_file": InputFile,
|
||||
"input_image": InputImage,
|
||||
"input_text": InputText,
|
||||
}
|
||||
|
||||
|
||||
BaseInputsContent1 = Annotated[
|
||||
Union[
|
||||
Annotated[InputAudio, Tag("input_audio")],
|
||||
Annotated[InputFile, Tag("input_file")],
|
||||
Annotated[InputImage, Tag("input_image")],
|
||||
Annotated[InputText, Tag("input_text")],
|
||||
],
|
||||
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
||||
Union[InputAudio, InputFile, InputImage, InputText, UnknownBaseInputsContent1],
|
||||
BeforeValidator(
|
||||
partial(
|
||||
parse_open_union,
|
||||
disc_key="type",
|
||||
variants=_BASE_INPUTS_CONTENT_1_VARIANTS,
|
||||
unknown_cls=UnknownBaseInputsContent1,
|
||||
union_name="BaseInputsContent1",
|
||||
)
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@@ -150,31 +173,26 @@ class BaseInputsMessage(BaseModel):
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
optional_fields = ["phase", "type"]
|
||||
nullable_fields = ["phase"]
|
||||
null_default_fields = []
|
||||
|
||||
optional_fields = set(["phase", "type"])
|
||||
nullable_fields = set(["phase"])
|
||||
serialized = handler(self)
|
||||
|
||||
m = {}
|
||||
|
||||
for n, f in type(self).model_fields.items():
|
||||
k = f.alias or n
|
||||
val = serialized.get(k)
|
||||
serialized.pop(k, None)
|
||||
val = serialized.get(k, serialized.get(n))
|
||||
is_nullable_and_explicitly_set = (
|
||||
k in nullable_fields
|
||||
and (self.__pydantic_fields_set__.intersection({n})) # pylint: disable=no-member
|
||||
)
|
||||
|
||||
optional_nullable = k in optional_fields and k in nullable_fields
|
||||
is_set = (
|
||||
self.__pydantic_fields_set__.intersection({n})
|
||||
or k in null_default_fields
|
||||
) # pylint: disable=no-member
|
||||
|
||||
if val is not None and val != UNSET_SENTINEL:
|
||||
m[k] = val
|
||||
elif val != UNSET_SENTINEL and (
|
||||
not k in optional_fields or (optional_nullable and is_set)
|
||||
):
|
||||
m[k] = val
|
||||
if val != UNSET_SENTINEL:
|
||||
if (
|
||||
val is not None
|
||||
or k not in optional_fields
|
||||
or is_nullable_and_explicitly_set
|
||||
):
|
||||
m[k] = val
|
||||
|
||||
return m
|
||||
|
||||
|
||||
Reference in New Issue
Block a user