chore: update SDK settings (#17)

This commit is contained in:
stainless-app[bot]
2025-03-27 04:48:17 +00:00
parent 8c0000317f
commit 2ad76db743
5 changed files with 116 additions and 15 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
configured_endpoints: 188
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/hanzo-industries-inc%2FHanzo-AI-0a7d35addf32cac4b920117d914306cd24392e3b43a81508b72d2fe5e6a501aa.yml
openapi_spec_hash: 17b0da4e67edba72578ce5ce7f142ef7
config_hash: e1a69420db5ac10401f63a73d06e1810
config_hash: 830747463ff4d018b5633ce511e88558
+4
View File
@@ -27,6 +27,8 @@ from hanzoai import Hanzo
client = Hanzo(
api_key=os.environ.get("HANZO_API_KEY"), # This is the default and can be omitted
# defaults to "production".
environment="sandbox",
)
response = client.get_home()
@@ -48,6 +50,8 @@ from hanzoai import AsyncHanzo
client = AsyncHanzo(
api_key=os.environ.get("HANZO_API_KEY"), # This is the default and can be omitted
# defaults to "production".
environment="sandbox",
)
+13 -1
View File
@@ -3,7 +3,18 @@
from . import types
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
from ._utils import file_from_path
from ._client import Hanzo, Client, Stream, Timeout, Transport, AsyncHanzo, AsyncClient, AsyncStream, RequestOptions
from ._client import (
ENVIRONMENTS,
Hanzo,
Client,
Stream,
Timeout,
Transport,
AsyncHanzo,
AsyncClient,
AsyncStream,
RequestOptions,
)
from ._models import BaseModel
from ._version import __title__, __version__
from ._response import APIResponse as APIResponse, AsyncAPIResponse as AsyncAPIResponse
@@ -59,6 +70,7 @@ __all__ = [
"AsyncStream",
"Hanzo",
"AsyncHanzo",
"ENVIRONMENTS",
"file_from_path",
"BaseModel",
"DEFAULT_TIMEOUT",
+80 -13
View File
@@ -3,8 +3,8 @@
from __future__ import annotations
import os
from typing import Any, Union, Mapping
from typing_extensions import Self, override
from typing import Any, Dict, Union, Mapping, cast
from typing_extensions import Self, Literal, override
import httpx
@@ -92,7 +92,22 @@ from .resources.responses import responses
from .resources.fine_tuning import fine_tuning
from .resources.organization import organization
__all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Hanzo", "AsyncHanzo", "Client", "AsyncClient"]
__all__ = [
"ENVIRONMENTS",
"Timeout",
"Transport",
"ProxiesTypes",
"RequestOptions",
"Hanzo",
"AsyncHanzo",
"Client",
"AsyncClient",
]
ENVIRONMENTS: Dict[str, str] = {
"production": "https://api.hanzo.ai",
"sandbox": "https://api.sandbox.hanzo.ai",
}
class Hanzo(SyncAPIClient):
@@ -150,11 +165,14 @@ class Hanzo(SyncAPIClient):
# client options
api_key: str
_environment: Literal["production", "sandbox"] | NotGiven
def __init__(
self,
*,
api_key: str | None = None,
base_url: str | httpx.URL | None = None,
environment: Literal["production", "sandbox"] | NotGiven = NOT_GIVEN,
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
@@ -185,10 +203,31 @@ class Hanzo(SyncAPIClient):
)
self.api_key = api_key
if base_url is None:
base_url = os.environ.get("HANZO_BASE_URL")
if base_url is None:
base_url = f"https://api.hanzo.ai"
self._environment = environment
base_url_env = os.environ.get("HANZO_BASE_URL")
if is_given(base_url) and base_url is not None:
# cast required because mypy doesn't understand the type narrowing
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
elif is_given(environment):
if base_url_env and base_url is not None:
raise ValueError(
"Ambiguous URL; The `HANZO_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
)
try:
base_url = ENVIRONMENTS[environment]
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc
elif base_url_env is not None:
base_url = base_url_env
else:
self._environment = environment = "production"
try:
base_url = ENVIRONMENTS[environment]
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc
super().__init__(
version=__version__,
@@ -276,6 +315,7 @@ class Hanzo(SyncAPIClient):
self,
*,
api_key: str | None = None,
environment: Literal["production", "sandbox"] | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.Client | None = None,
@@ -311,6 +351,7 @@ class Hanzo(SyncAPIClient):
return self.__class__(
api_key=api_key or self.api_key,
base_url=base_url or self.base_url,
environment=environment or self._environment,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
max_retries=max_retries if is_given(max_retries) else self.max_retries,
@@ -431,11 +472,14 @@ class AsyncHanzo(AsyncAPIClient):
# client options
api_key: str
_environment: Literal["production", "sandbox"] | NotGiven
def __init__(
self,
*,
api_key: str | None = None,
base_url: str | httpx.URL | None = None,
environment: Literal["production", "sandbox"] | NotGiven = NOT_GIVEN,
base_url: str | httpx.URL | None | NotGiven = NOT_GIVEN,
timeout: Union[float, Timeout, None, NotGiven] = NOT_GIVEN,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
@@ -466,10 +510,31 @@ class AsyncHanzo(AsyncAPIClient):
)
self.api_key = api_key
if base_url is None:
base_url = os.environ.get("HANZO_BASE_URL")
if base_url is None:
base_url = f"https://api.hanzo.ai"
self._environment = environment
base_url_env = os.environ.get("HANZO_BASE_URL")
if is_given(base_url) and base_url is not None:
# cast required because mypy doesn't understand the type narrowing
base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast]
elif is_given(environment):
if base_url_env and base_url is not None:
raise ValueError(
"Ambiguous URL; The `HANZO_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None",
)
try:
base_url = ENVIRONMENTS[environment]
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc
elif base_url_env is not None:
base_url = base_url_env
else:
self._environment = environment = "production"
try:
base_url = ENVIRONMENTS[environment]
except KeyError as exc:
raise ValueError(f"Unknown environment: {environment}") from exc
super().__init__(
version=__version__,
@@ -557,6 +622,7 @@ class AsyncHanzo(AsyncAPIClient):
self,
*,
api_key: str | None = None,
environment: Literal["production", "sandbox"] | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
http_client: httpx.AsyncClient | None = None,
@@ -592,6 +658,7 @@ class AsyncHanzo(AsyncAPIClient):
return self.__class__(
api_key=api_key or self.api_key,
base_url=base_url or self.base_url,
environment=environment or self._environment,
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
http_client=http_client,
max_retries=max_retries if is_given(max_retries) else self.max_retries,
+18
View File
@@ -556,6 +556,14 @@ class TestHanzo:
client = Hanzo(api_key=api_key, _strict_response_validation=True)
assert client.base_url == "http://localhost:5000/from/env/"
# explicit environment arg requires explicitness
with update_env(HANZO_BASE_URL="http://localhost:5000/from/env"):
with pytest.raises(ValueError, match=r"you must pass base_url=None"):
Hanzo(api_key=api_key, _strict_response_validation=True, environment="production")
client = Hanzo(base_url=None, api_key=api_key, _strict_response_validation=True, environment="production")
assert str(client.base_url).startswith("https://api.hanzo.ai")
@pytest.mark.parametrize(
"client",
[
@@ -1306,6 +1314,16 @@ class TestAsyncHanzo:
client = AsyncHanzo(api_key=api_key, _strict_response_validation=True)
assert client.base_url == "http://localhost:5000/from/env/"
# explicit environment arg requires explicitness
with update_env(HANZO_BASE_URL="http://localhost:5000/from/env"):
with pytest.raises(ValueError, match=r"you must pass base_url=None"):
AsyncHanzo(api_key=api_key, _strict_response_validation=True, environment="production")
client = AsyncHanzo(
base_url=None, api_key=api_key, _strict_response_validation=True, environment="production"
)
assert str(client.base_url).startswith("https://api.hanzo.ai")
@pytest.mark.parametrize(
"client",
[