Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/deepgram/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import typing

import httpx

from ..environment import DeepgramClientEnvironment
from .http_client import AsyncHttpClient, HttpClient

Expand All @@ -26,7 +27,7 @@ def get_headers(self) -> typing.Dict[str, str]:
"X-Fern-Language": "Python",
"X-Fern-SDK-Name": "deepgram",
# x-release-please-start-version
"X-Fern-SDK-Version": "5.2.0",
"X-Fern-SDK-Version": "5.2.0",
# x-release-please-end
**(self.get_custom_headers() or {}),
}
Expand Down
3 changes: 2 additions & 1 deletion src/deepgram/core/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
from random import random

import httpx
from httpx._types import RequestFiles

from .file import File, convert_file_dict_to_httpx_tuples
from .force_multipart import FORCE_MULTIPART
from .jsonable_encoder import jsonable_encoder
from .query_encoder import encode_query
from .remove_none_from_dict import remove_none_from_dict
from .request_options import RequestOptions
from httpx._types import RequestFiles

INITIAL_RETRY_DELAY_SECONDS = 0.5
MAX_RETRY_DELAY_SECONDS = 10
Expand Down
19 changes: 15 additions & 4 deletions src/deepgram/core/pydantic_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
# nopycln: file
import datetime as dt
from collections import defaultdict
from typing import Any, Callable, ClassVar, Dict, List, Mapping, Optional, Set, Tuple, Type, TypeVar, Union, cast
from functools import lru_cache
from typing import (Any, Callable, ClassVar, Dict, List, Mapping, Optional,
Set, Tuple, Type, TypeVar, Union, cast)

import pydantic

from deepgram.core.serialization import convert_and_respect_annotation_metadata

IS_PYDANTIC_V2 = pydantic.VERSION.startswith("2.")

if IS_PYDANTIC_V2:
from pydantic.v1.datetime_parse import parse_date as parse_date
from pydantic.v1.datetime_parse import parse_datetime as parse_datetime
from pydantic.v1.fields import ModelField as ModelField
from pydantic.v1.json import ENCODERS_BY_TYPE as encoders_by_type # type: ignore[attr-defined]
from pydantic.v1.json import \
ENCODERS_BY_TYPE as encoders_by_type # type: ignore[attr-defined]
from pydantic.v1.typing import get_args as get_args
from pydantic.v1.typing import get_origin as get_origin
from pydantic.v1.typing import is_literal_type as is_literal_type
Expand All @@ -28,9 +33,10 @@
from pydantic.typing import is_literal_type as is_literal_type # type: ignore[no-redef]
from pydantic.typing import is_union as is_union # type: ignore[no-redef]

from typing_extensions import TypeAlias

from .datetime_utils import serialize_datetime
from .serialization import convert_and_respect_annotation_metadata
from typing_extensions import TypeAlias

T = TypeVar("T")
Model = TypeVar("Model", bound=pydantic.BaseModel)
Expand All @@ -39,7 +45,7 @@
def parse_obj_as(type_: Type[T], object_: Any) -> T:
dealiased_object = convert_and_respect_annotation_metadata(object_=object_, annotation=type_, direction="read")
if IS_PYDANTIC_V2:
adapter = pydantic.TypeAdapter(type_) # type: ignore[attr-defined]
adapter = get_type_adapter(type_)
return adapter.validate_python(dealiased_object)
return pydantic.parse_obj_as(type_, dealiased_object)

Expand Down Expand Up @@ -256,3 +262,8 @@ def _get_field_default(field: PydanticField) -> Any:
return None
return value
return value


@lru_cache(maxsize=128)
def get_type_adapter(type_):
return pydantic.TypeAdapter(type_) # type: ignore[attr-defined]