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

77 lines
2.3 KiB
Python

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from .anthropiciterationcachecreation import (
AnthropicIterationCacheCreation,
AnthropicIterationCacheCreationTypedDict,
)
from openrouter.types import (
BaseModel,
Nullable,
OptionalNullable,
UNSET,
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Literal, Optional
from typing_extensions import NotRequired, TypedDict
AnthropicCompactionUsageIterationType = Literal["compaction",]
class AnthropicCompactionUsageIterationTypedDict(TypedDict):
type: AnthropicCompactionUsageIterationType
cache_creation: NotRequired[Nullable[AnthropicIterationCacheCreationTypedDict]]
cache_creation_input_tokens: NotRequired[int]
cache_read_input_tokens: NotRequired[int]
input_tokens: NotRequired[int]
output_tokens: NotRequired[int]
class AnthropicCompactionUsageIteration(BaseModel):
type: AnthropicCompactionUsageIterationType
cache_creation: OptionalNullable[AnthropicIterationCacheCreation] = UNSET
cache_creation_input_tokens: Optional[int] = None
cache_read_input_tokens: Optional[int] = None
input_tokens: Optional[int] = None
output_tokens: Optional[int] = None
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = set(
[
"cache_creation",
"cache_creation_input_tokens",
"cache_read_input_tokens",
"input_tokens",
"output_tokens",
]
)
nullable_fields = set(["cache_creation"])
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