mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-08-01 12:40:23 +08:00
docs: Mintlify MDX docs + docs.json; bump Speakeasy to 1.787.0 (#382)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
import io
|
||||
from openrouter.types import BaseModel
|
||||
from openrouter.types import BaseModel, UNSET_SENTINEL
|
||||
from openrouter.utils import (
|
||||
FieldMetadata,
|
||||
HeaderMetadata,
|
||||
@@ -11,6 +11,7 @@ from openrouter.utils import (
|
||||
RequestMetadata,
|
||||
)
|
||||
import pydantic
|
||||
from pydantic import model_serializer
|
||||
from typing import IO, Optional, Union
|
||||
from typing_extensions import Annotated, NotRequired, TypedDict
|
||||
|
||||
@@ -60,10 +61,28 @@ class UploadFileGlobals(BaseModel):
|
||||
|
||||
"""
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
optional_fields = set(
|
||||
["HTTP-Referer", "X-OpenRouter-Title", "X-OpenRouter-Categories"]
|
||||
)
|
||||
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))
|
||||
|
||||
if val != UNSET_SENTINEL:
|
||||
if val is not None or k not in optional_fields:
|
||||
m[k] = val
|
||||
|
||||
return m
|
||||
|
||||
|
||||
class FileTypedDict(TypedDict):
|
||||
file_name: str
|
||||
content: Union[bytes, IO[bytes], io.BufferedReader]
|
||||
content: Union[bytes, IO[bytes], io.IOBase]
|
||||
content_type: NotRequired[str]
|
||||
|
||||
|
||||
@@ -73,7 +92,7 @@ class File(BaseModel):
|
||||
]
|
||||
|
||||
content: Annotated[
|
||||
Union[bytes, IO[bytes], io.BufferedReader],
|
||||
Union[bytes, IO[bytes], io.IOBase],
|
||||
pydantic.Field(alias=""),
|
||||
FieldMetadata(multipart=MultipartFormMetadata(content=True)),
|
||||
]
|
||||
@@ -84,6 +103,22 @@ class File(BaseModel):
|
||||
FieldMetadata(multipart=True),
|
||||
] = None
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
optional_fields = set(["contentType"])
|
||||
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))
|
||||
|
||||
if val != UNSET_SENTINEL:
|
||||
if val is not None or k not in optional_fields:
|
||||
m[k] = val
|
||||
|
||||
return m
|
||||
|
||||
|
||||
class UploadFileRequestBodyTypedDict(TypedDict):
|
||||
file: FileTypedDict
|
||||
@@ -151,3 +186,26 @@ class UploadFileRequest(BaseModel):
|
||||
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
|
||||
] = None
|
||||
r"""Workspace to scope the request to. Defaults to the caller’s default workspace."""
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
optional_fields = set(
|
||||
[
|
||||
"HTTP-Referer",
|
||||
"X-OpenRouter-Title",
|
||||
"X-OpenRouter-Categories",
|
||||
"workspace_id",
|
||||
]
|
||||
)
|
||||
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))
|
||||
|
||||
if val != UNSET_SENTINEL:
|
||||
if val is not None or k not in optional_fields:
|
||||
m[k] = val
|
||||
|
||||
return m
|
||||
|
||||
Reference in New Issue
Block a user