Files
openrouter-python-sdk-retry…/src/openrouter/models/chatcompletionmessage.py
T
2025-08-22 10:31:13 -05:00

102 lines
3.1 KiB
Python

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from .annotationdetail import AnnotationDetail, AnnotationDetailTypedDict
from .chatcompletionmessagetoolcall import (
ChatCompletionMessageToolCall,
ChatCompletionMessageToolCallTypedDict,
)
from .reasoningdetail import ReasoningDetail, ReasoningDetailTypedDict
from enum import Enum
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 ChatCompletionMessageRole(str, Enum):
ASSISTANT = "assistant"
class ChatCompletionMessageTypedDict(TypedDict):
r"""Assistant message in completion response"""
role: ChatCompletionMessageRole
content: Nullable[str]
r"""Message content"""
refusal: Nullable[str]
r"""Refusal message if content was refused"""
reasoning: NotRequired[Nullable[str]]
r"""Reasoning output"""
tool_calls: NotRequired[List[ChatCompletionMessageToolCallTypedDict]]
r"""Tool calls made by the assistant"""
reasoning_details: NotRequired[List[ReasoningDetailTypedDict]]
r"""Reasoning details delta to send reasoning details back to upstream"""
annotations: NotRequired[List[AnnotationDetailTypedDict]]
r"""Annotations delta to send annotations back to upstream"""
class ChatCompletionMessage(BaseModel):
r"""Assistant message in completion response"""
role: ChatCompletionMessageRole
content: Nullable[str]
r"""Message content"""
refusal: Nullable[str]
r"""Refusal message if content was refused"""
reasoning: OptionalNullable[str] = UNSET
r"""Reasoning output"""
tool_calls: Optional[List[ChatCompletionMessageToolCall]] = None
r"""Tool calls made by the assistant"""
reasoning_details: Optional[List[ReasoningDetail]] = None
r"""Reasoning details delta to send reasoning details back to upstream"""
annotations: Optional[List[AnnotationDetail]] = None
r"""Annotations delta to send annotations back to upstream"""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = [
"reasoning",
"tool_calls",
"reasoning_details",
"annotations",
]
nullable_fields = ["content", "reasoning", "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