mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-08-01 12:40:23 +08:00
100 lines
3.2 KiB
Python
100 lines
3.2 KiB
Python
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
|
|
from __future__ import annotations
|
|
from .chatcompletioncontentpart import (
|
|
ChatCompletionContentPart,
|
|
ChatCompletionContentPartTypedDict,
|
|
)
|
|
from .chatcompletionmessagetoolcall import (
|
|
ChatCompletionMessageToolCall,
|
|
ChatCompletionMessageToolCallTypedDict,
|
|
)
|
|
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
|
|
|
|
|
|
ChatCompletionAssistantMessageParamRole = Literal["assistant"]
|
|
|
|
ChatCompletionAssistantMessageParamContentTypedDict = TypeAliasType(
|
|
"ChatCompletionAssistantMessageParamContentTypedDict",
|
|
Union[str, List[ChatCompletionContentPartTypedDict], Any],
|
|
)
|
|
r"""Assistant message content"""
|
|
|
|
|
|
ChatCompletionAssistantMessageParamContent = TypeAliasType(
|
|
"ChatCompletionAssistantMessageParamContent",
|
|
Union[str, List[ChatCompletionContentPart], Any],
|
|
)
|
|
r"""Assistant message content"""
|
|
|
|
|
|
class ChatCompletionAssistantMessageParamTypedDict(TypedDict):
|
|
r"""Assistant message with tool calls and audio support"""
|
|
|
|
role: ChatCompletionAssistantMessageParamRole
|
|
content: NotRequired[Nullable[ChatCompletionAssistantMessageParamContentTypedDict]]
|
|
r"""Assistant message content"""
|
|
name: NotRequired[str]
|
|
r"""Optional name for the assistant"""
|
|
tool_calls: NotRequired[List[ChatCompletionMessageToolCallTypedDict]]
|
|
r"""Tool calls made by the assistant"""
|
|
refusal: NotRequired[Nullable[str]]
|
|
r"""Refusal message if content was refused"""
|
|
|
|
|
|
class ChatCompletionAssistantMessageParam(BaseModel):
|
|
r"""Assistant message with tool calls and audio support"""
|
|
|
|
role: ChatCompletionAssistantMessageParamRole
|
|
|
|
content: OptionalNullable[ChatCompletionAssistantMessageParamContent] = UNSET
|
|
r"""Assistant message content"""
|
|
|
|
name: Optional[str] = None
|
|
r"""Optional name for the assistant"""
|
|
|
|
tool_calls: Optional[List[ChatCompletionMessageToolCall]] = None
|
|
r"""Tool calls made by the assistant"""
|
|
|
|
refusal: OptionalNullable[str] = UNSET
|
|
r"""Refusal message if content was refused"""
|
|
|
|
@model_serializer(mode="wrap")
|
|
def serialize_model(self, handler):
|
|
optional_fields = ["content", "name", "tool_calls", "refusal"]
|
|
nullable_fields = ["content", "refusal"]
|
|
null_default_fields = []
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
return m
|