Make SubFox production-ready with parallel translation and UI controls
This commit is contained in:
parent
c40b8bed2b
commit
2b1d05f02c
6046 changed files with 798327 additions and 0 deletions
35
.venv/lib/python3.10/site-packages/openai/_utils/_json.py
Normal file
35
.venv/lib/python3.10/site-packages/openai/_utils/_json.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import json
|
||||
from typing import Any
|
||||
from datetime import datetime
|
||||
from typing_extensions import override
|
||||
|
||||
import pydantic
|
||||
|
||||
from .._compat import model_dump
|
||||
|
||||
|
||||
def openapi_dumps(obj: Any) -> bytes:
|
||||
"""
|
||||
Serialize an object to UTF-8 encoded JSON bytes.
|
||||
|
||||
Extends the standard json.dumps with support for additional types
|
||||
commonly used in the SDK, such as `datetime`, `pydantic.BaseModel`, etc.
|
||||
"""
|
||||
return json.dumps(
|
||||
obj,
|
||||
cls=_CustomEncoder,
|
||||
# Uses the same defaults as httpx's JSON serialization
|
||||
ensure_ascii=False,
|
||||
separators=(",", ":"),
|
||||
allow_nan=False,
|
||||
).encode()
|
||||
|
||||
|
||||
class _CustomEncoder(json.JSONEncoder):
|
||||
@override
|
||||
def default(self, o: Any) -> Any:
|
||||
if isinstance(o, datetime):
|
||||
return o.isoformat()
|
||||
if isinstance(o, pydantic.BaseModel):
|
||||
return model_dump(o, exclude_unset=True, mode="json", by_alias=True)
|
||||
return super().default(o)
|
||||
Loading…
Add table
Add a link
Reference in a new issue