From 0b010715afd25771773c181f212916d94048fdff Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Fri, 24 Nov 2023 16:41:48 +0000 Subject: [PATCH] chore(internal): send more detailed x-stainless headers --- pyproject.toml | 1 + src/finch/_client.py | 4 +++- src/finch/_utils/__init__.py | 1 + src/finch/_utils/_utils.py | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3fa1fd1b..d9f8ddc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ dependencies = [ "typing-extensions>=4.5, <5", "anyio>=3.5.0, <4", "distro>=1.7.0, <2", + "sniffio", ] requires-python = ">= 3.7" diff --git a/src/finch/_client.py b/src/finch/_client.py index a840d0d3..d5579f9f 100644 --- a/src/finch/_client.py +++ b/src/finch/_client.py @@ -22,7 +22,7 @@ AsyncTransport, RequestOptions, ) -from ._utils import is_given +from ._utils import is_given, get_async_library from ._version import __version__ from ._streaming import Stream as Stream from ._streaming import AsyncStream as AsyncStream @@ -156,6 +156,7 @@ def auth_headers(self) -> dict[str, str]: def default_headers(self) -> dict[str, str | Omit]: return { **super().default_headers, + "X-Stainless-Async": "false", "Finch-API-Version": "2020-09-17", **self._custom_headers, } @@ -459,6 +460,7 @@ def auth_headers(self) -> dict[str, str]: def default_headers(self) -> dict[str, str | Omit]: return { **super().default_headers, + "X-Stainless-Async": f"async:{get_async_library()}", "Finch-API-Version": "2020-09-17", **self._custom_headers, } diff --git a/src/finch/_utils/__init__.py b/src/finch/_utils/__init__.py index d3397212..400ca9b8 100644 --- a/src/finch/_utils/__init__.py +++ b/src/finch/_utils/__init__.py @@ -25,6 +25,7 @@ from ._utils import deepcopy_minimal as deepcopy_minimal from ._utils import extract_type_arg as extract_type_arg from ._utils import is_required_type as is_required_type +from ._utils import get_async_library as get_async_library from ._utils import is_annotated_type as is_annotated_type from ._utils import maybe_coerce_float as maybe_coerce_float from ._utils import get_required_header as get_required_header diff --git a/src/finch/_utils/_utils.py b/src/finch/_utils/_utils.py index 4b51dcb2..d2bfc91a 100644 --- a/src/finch/_utils/_utils.py +++ b/src/finch/_utils/_utils.py @@ -18,6 +18,8 @@ from pathlib import Path from typing_extensions import Required, Annotated, TypeGuard, get_args, get_origin +import sniffio + from .._types import Headers, NotGiven, FileTypes, NotGivenOr, HeadersLike from .._compat import is_union as _is_union from .._compat import parse_date as parse_date @@ -406,3 +408,10 @@ def get_required_header(headers: HeadersLike, header: str) -> str: return value raise ValueError(f"Could not find {header} header") + + +def get_async_library() -> str: + try: + return sniffio.current_async_library() + except Exception: + return "false"