Files
openrouter-python-sdk-retry…/src/openrouter/components/model.py
T

171 lines
6.1 KiB
Python

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from .defaultparameters import DefaultParameters, DefaultParametersTypedDict
from .modelarchitecture import ModelArchitecture, ModelArchitectureTypedDict
from .modelbenchmarks import ModelBenchmarks, ModelBenchmarksTypedDict
from .modellinks import ModelLinks, ModelLinksTypedDict
from .modelreasoning import ModelReasoning, ModelReasoningTypedDict
from .parameter import Parameter
from .perrequestlimits import PerRequestLimits, PerRequestLimitsTypedDict
from .publicpricing import PublicPricing, PublicPricingTypedDict
from .topproviderinfo import TopProviderInfo, TopProviderInfoTypedDict
from openrouter.types import (
BaseModel,
Nullable,
OptionalNullable,
UNSET,
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict
class ModelTypedDict(TypedDict):
r"""Information about an AI model available on OpenRouter"""
architecture: ModelArchitectureTypedDict
r"""Model architecture information"""
canonical_slug: str
r"""Canonical slug for the model"""
context_length: Nullable[int]
r"""Maximum context length in tokens"""
created: int
r"""Unix timestamp of when the model was created"""
default_parameters: Nullable[DefaultParametersTypedDict]
r"""Default parameters for this model"""
id: str
r"""Unique identifier for the model"""
links: ModelLinksTypedDict
r"""Related API endpoints and resources for this model."""
name: str
r"""Display name of the model"""
per_request_limits: Nullable[PerRequestLimitsTypedDict]
r"""Per-request token limits"""
pricing: PublicPricingTypedDict
r"""Pricing information for the model"""
supported_parameters: List[Parameter]
r"""List of supported parameters for this model"""
supported_voices: Nullable[List[str]]
r"""List of supported voice identifiers for TTS models. Null for non-TTS models."""
top_provider: TopProviderInfoTypedDict
r"""Information about the top provider for this model"""
benchmarks: NotRequired[ModelBenchmarksTypedDict]
r"""Third-party benchmark rankings for this model. Omitted when no benchmark data is available."""
description: NotRequired[str]
r"""Description of the model"""
expiration_date: NotRequired[Nullable[str]]
r"""The date after which the model may be removed. ISO 8601 date string (YYYY-MM-DD) or null if no expiration."""
hugging_face_id: NotRequired[Nullable[str]]
r"""Hugging Face model identifier, if applicable"""
knowledge_cutoff: NotRequired[Nullable[str]]
r"""The date up to which the model was trained on data. ISO 8601 date string (YYYY-MM-DD) or null if unknown."""
reasoning: NotRequired[ModelReasoningTypedDict]
r"""Reasoning effort configuration. Omitted for non-reasoning models and dynamic router models."""
class Model(BaseModel):
r"""Information about an AI model available on OpenRouter"""
architecture: ModelArchitecture
r"""Model architecture information"""
canonical_slug: str
r"""Canonical slug for the model"""
context_length: Nullable[int]
r"""Maximum context length in tokens"""
created: int
r"""Unix timestamp of when the model was created"""
default_parameters: Nullable[DefaultParameters]
r"""Default parameters for this model"""
id: str
r"""Unique identifier for the model"""
links: ModelLinks
r"""Related API endpoints and resources for this model."""
name: str
r"""Display name of the model"""
per_request_limits: Nullable[PerRequestLimits]
r"""Per-request token limits"""
pricing: PublicPricing
r"""Pricing information for the model"""
supported_parameters: List[Parameter]
r"""List of supported parameters for this model"""
supported_voices: Nullable[List[str]]
r"""List of supported voice identifiers for TTS models. Null for non-TTS models."""
top_provider: TopProviderInfo
r"""Information about the top provider for this model"""
benchmarks: Optional[ModelBenchmarks] = None
r"""Third-party benchmark rankings for this model. Omitted when no benchmark data is available."""
description: Optional[str] = None
r"""Description of the model"""
expiration_date: OptionalNullable[str] = UNSET
r"""The date after which the model may be removed. ISO 8601 date string (YYYY-MM-DD) or null if no expiration."""
hugging_face_id: OptionalNullable[str] = UNSET
r"""Hugging Face model identifier, if applicable"""
knowledge_cutoff: OptionalNullable[str] = UNSET
r"""The date up to which the model was trained on data. ISO 8601 date string (YYYY-MM-DD) or null if unknown."""
reasoning: Optional[ModelReasoning] = None
r"""Reasoning effort configuration. Omitted for non-reasoning models and dynamic router models."""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(
[
"benchmarks",
"description",
"expiration_date",
"hugging_face_id",
"knowledge_cutoff",
"reasoning",
]
)
nullable_fields = set(
[
"context_length",
"default_parameters",
"expiration_date",
"hugging_face_id",
"knowledge_cutoff",
"per_request_limits",
"supported_voices",
]
)
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias or n
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
)
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