mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-30 12:20:57 +08:00
123 lines
4.0 KiB
Python
123 lines
4.0 KiB
Python
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
|
|
from __future__ import annotations
|
|
from .chatassistantimages import ChatAssistantImages, ChatAssistantImagesTypedDict
|
|
from .chataudiooutput import ChatAudioOutput, ChatAudioOutputTypedDict
|
|
from .chatcontentitems import ChatContentItems, ChatContentItemsTypedDict
|
|
from .chattoolcall import ChatToolCall, ChatToolCallTypedDict
|
|
from .reasoningdetailunion import ReasoningDetailUnion, ReasoningDetailUnionTypedDict
|
|
from openrouter.types import (
|
|
BaseModel,
|
|
Nullable,
|
|
OptionalNullable,
|
|
UNSET,
|
|
UNSET_SENTINEL,
|
|
)
|
|
from pydantic import model_serializer
|
|
from typing import Any, List, Literal, Optional, Union
|
|
from typing_extensions import NotRequired, TypeAliasType, TypedDict
|
|
|
|
|
|
ChatAssistantMessageContentTypedDict = TypeAliasType(
|
|
"ChatAssistantMessageContentTypedDict",
|
|
Union[str, List[ChatContentItemsTypedDict], Any],
|
|
)
|
|
r"""Assistant message content"""
|
|
|
|
|
|
ChatAssistantMessageContent = TypeAliasType(
|
|
"ChatAssistantMessageContent", Union[str, List[ChatContentItems], Any]
|
|
)
|
|
r"""Assistant message content"""
|
|
|
|
|
|
ChatAssistantMessageRole = Literal["assistant",]
|
|
|
|
|
|
class ChatAssistantMessageTypedDict(TypedDict):
|
|
r"""Assistant message for requests and responses"""
|
|
|
|
role: ChatAssistantMessageRole
|
|
audio: NotRequired[ChatAudioOutputTypedDict]
|
|
r"""Audio output data or reference"""
|
|
content: NotRequired[Nullable[ChatAssistantMessageContentTypedDict]]
|
|
r"""Assistant message content"""
|
|
images: NotRequired[List[ChatAssistantImagesTypedDict]]
|
|
r"""Generated images from image generation models"""
|
|
name: NotRequired[str]
|
|
r"""Optional name for the assistant"""
|
|
reasoning: NotRequired[Nullable[str]]
|
|
r"""Reasoning output"""
|
|
reasoning_details: NotRequired[List[ReasoningDetailUnionTypedDict]]
|
|
r"""Reasoning details for extended thinking models"""
|
|
refusal: NotRequired[Nullable[str]]
|
|
r"""Refusal message if content was refused"""
|
|
tool_calls: NotRequired[List[ChatToolCallTypedDict]]
|
|
r"""Tool calls made by the assistant"""
|
|
|
|
|
|
class ChatAssistantMessage(BaseModel):
|
|
r"""Assistant message for requests and responses"""
|
|
|
|
role: ChatAssistantMessageRole
|
|
|
|
audio: Optional[ChatAudioOutput] = None
|
|
r"""Audio output data or reference"""
|
|
|
|
content: OptionalNullable[ChatAssistantMessageContent] = UNSET
|
|
r"""Assistant message content"""
|
|
|
|
images: Optional[List[ChatAssistantImages]] = None
|
|
r"""Generated images from image generation models"""
|
|
|
|
name: Optional[str] = None
|
|
r"""Optional name for the assistant"""
|
|
|
|
reasoning: OptionalNullable[str] = UNSET
|
|
r"""Reasoning output"""
|
|
|
|
reasoning_details: Optional[List[ReasoningDetailUnion]] = None
|
|
r"""Reasoning details for extended thinking models"""
|
|
|
|
refusal: OptionalNullable[str] = UNSET
|
|
r"""Refusal message if content was refused"""
|
|
|
|
tool_calls: Optional[List[ChatToolCall]] = None
|
|
r"""Tool calls made by the assistant"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = set(
|
|
[
|
|
"audio",
|
|
"content",
|
|
"images",
|
|
"name",
|
|
"reasoning",
|
|
"reasoning_details",
|
|
"refusal",
|
|
"tool_calls",
|
|
]
|
|
)
|
|
nullable_fields = set(["content", "reasoning", "refusal"])
|
|
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
|