mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
feat(api): update via SDK Studio (#4)
This commit is contained in:
@@ -28,4 +28,4 @@ jobs:
|
||||
run: |
|
||||
bash ./bin/publish-pypi
|
||||
env:
|
||||
PYPI_TOKEN: ${{ secrets.HANZO_AI_PYPI_TOKEN || secrets.PYPI_TOKEN }}
|
||||
PYPI_TOKEN: ${{ secrets.HANZO_PYPI_TOKEN || secrets.PYPI_TOKEN }}
|
||||
|
||||
@@ -18,4 +18,4 @@ jobs:
|
||||
run: |
|
||||
bash ./bin/check-release-environment
|
||||
env:
|
||||
PYPI_TOKEN: ${{ secrets.HANZO_AI_PYPI_TOKEN || secrets.PYPI_TOKEN }}
|
||||
PYPI_TOKEN: ${{ secrets.HANZO_PYPI_TOKEN || secrets.PYPI_TOKEN }}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ $ pip install -r requirements-dev.lock
|
||||
|
||||
Most of the SDK is generated code. Modifications to code will be persisted between generations, but may
|
||||
result in merge conflicts between manual patches and changes from the generator. The generator will never
|
||||
modify the contents of the `src/Hanzo_AI/lib/` and `examples/` directories.
|
||||
modify the contents of the `src/hanzoai/lib/` and `examples/` directories.
|
||||
|
||||
## Adding and running examples
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2025 Hanzo AI
|
||||
Copyright 2025 Hanzo
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Hanzo AI Python API library
|
||||
# Hanzo Python API library
|
||||
|
||||
[](https://pypi.org/project/hanzoai/)
|
||||
|
||||
The Hanzo AI Python library provides convenient access to the Hanzo AI REST API from any Python 3.8+
|
||||
The Hanzo Python library provides convenient access to the Hanzo REST API from any Python 3.8+
|
||||
application. The library includes type definitions for all request params and response fields,
|
||||
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
|
||||
|
||||
@@ -10,7 +10,7 @@ It is generated with [Stainless](https://www.stainless.com/).
|
||||
|
||||
## Documentation
|
||||
|
||||
The REST API documentation can be found on [docs.hanzo-ai.com](https://docs.Hanzo-AI.com). The full API of this library can be found in [api.md](api.md).
|
||||
The REST API documentation can be found on [docs.hanzo.ai](https://docs.hanzo.ai). The full API of this library can be found in [api.md](api.md).
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -25,10 +25,10 @@ The full API of this library can be found in [api.md](api.md).
|
||||
|
||||
```python
|
||||
import os
|
||||
from Hanzo_AI import HanzoAI
|
||||
from hanzoai import Hanzo
|
||||
|
||||
client = HanzoAI(
|
||||
api_key=os.environ.get("HANZO_AI_API_KEY"), # This is the default and can be omitted
|
||||
client = Hanzo(
|
||||
api_key=os.environ.get("HANZO_API_KEY"), # This is the default and can be omitted
|
||||
)
|
||||
|
||||
response = client.get_home()
|
||||
@@ -36,20 +36,20 @@ response = client.get_home()
|
||||
|
||||
While you can provide an `api_key` keyword argument,
|
||||
we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
|
||||
to add `HANZO_AI_API_KEY="My API Key"` to your `.env` file
|
||||
to add `HANZO_API_KEY="My API Key"` to your `.env` file
|
||||
so that your API Key is not stored in source control.
|
||||
|
||||
## Async usage
|
||||
|
||||
Simply import `AsyncHanzoAI` instead of `HanzoAI` and use `await` with each API call:
|
||||
Simply import `AsyncHanzo` instead of `Hanzo` and use `await` with each API call:
|
||||
|
||||
```python
|
||||
import os
|
||||
import asyncio
|
||||
from Hanzo_AI import AsyncHanzoAI
|
||||
from hanzoai import AsyncHanzo
|
||||
|
||||
client = AsyncHanzoAI(
|
||||
api_key=os.environ.get("HANZO_AI_API_KEY"), # This is the default and can be omitted
|
||||
client = AsyncHanzo(
|
||||
api_key=os.environ.get("HANZO_API_KEY"), # This is the default and can be omitted
|
||||
)
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ Typed requests and responses provide autocomplete and documentation within your
|
||||
Nested parameters are dictionaries, typed using `TypedDict`, for example:
|
||||
|
||||
```python
|
||||
from Hanzo_AI import HanzoAI
|
||||
from hanzoai import Hanzo
|
||||
|
||||
client = HanzoAI()
|
||||
client = Hanzo()
|
||||
|
||||
model = client.model.create(
|
||||
litellm_params={
|
||||
@@ -126,9 +126,9 @@ Request parameters that correspond to file uploads can be passed as `bytes`, a [
|
||||
|
||||
```python
|
||||
from pathlib import Path
|
||||
from Hanzo_AI import HanzoAI
|
||||
from hanzoai import Hanzo
|
||||
|
||||
client = HanzoAI()
|
||||
client = Hanzo()
|
||||
|
||||
client.audio.transcriptions.create(
|
||||
file=Path("/path/to/file"),
|
||||
@@ -139,27 +139,27 @@ The async client uses the exact same interface. If you pass a [`PathLike`](https
|
||||
|
||||
## Handling errors
|
||||
|
||||
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `Hanzo_AI.APIConnectionError` is raised.
|
||||
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `hanzoai.APIConnectionError` is raised.
|
||||
|
||||
When the API returns a non-success status code (that is, 4xx or 5xx
|
||||
response), a subclass of `Hanzo_AI.APIStatusError` is raised, containing `status_code` and `response` properties.
|
||||
response), a subclass of `hanzoai.APIStatusError` is raised, containing `status_code` and `response` properties.
|
||||
|
||||
All errors inherit from `Hanzo_AI.APIError`.
|
||||
All errors inherit from `hanzoai.APIError`.
|
||||
|
||||
```python
|
||||
import Hanzo_AI
|
||||
from Hanzo_AI import HanzoAI
|
||||
import hanzoai
|
||||
from hanzoai import Hanzo
|
||||
|
||||
client = HanzoAI()
|
||||
client = Hanzo()
|
||||
|
||||
try:
|
||||
client.get_home()
|
||||
except Hanzo_AI.APIConnectionError as e:
|
||||
except hanzoai.APIConnectionError as e:
|
||||
print("The server could not be reached")
|
||||
print(e.__cause__) # an underlying Exception, likely raised within httpx.
|
||||
except Hanzo_AI.RateLimitError as e:
|
||||
except hanzoai.RateLimitError as e:
|
||||
print("A 429 status code was received; we should back off a bit.")
|
||||
except Hanzo_AI.APIStatusError as e:
|
||||
except hanzoai.APIStatusError as e:
|
||||
print("Another non-200-range status code was received")
|
||||
print(e.status_code)
|
||||
print(e.response)
|
||||
@@ -187,10 +187,10 @@ Connection errors (for example, due to a network connectivity problem), 408 Requ
|
||||
You can use the `max_retries` option to configure or disable retry settings:
|
||||
|
||||
```python
|
||||
from Hanzo_AI import HanzoAI
|
||||
from hanzoai import Hanzo
|
||||
|
||||
# Configure the default for all requests:
|
||||
client = HanzoAI(
|
||||
client = Hanzo(
|
||||
# default is 2
|
||||
max_retries=0,
|
||||
)
|
||||
@@ -205,16 +205,16 @@ By default requests time out after 1 minute. You can configure this with a `time
|
||||
which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
|
||||
|
||||
```python
|
||||
from Hanzo_AI import HanzoAI
|
||||
from hanzoai import Hanzo
|
||||
|
||||
# Configure the default for all requests:
|
||||
client = HanzoAI(
|
||||
client = Hanzo(
|
||||
# 20 seconds (default is 1 minute)
|
||||
timeout=20.0,
|
||||
)
|
||||
|
||||
# More granular control:
|
||||
client = HanzoAI(
|
||||
client = Hanzo(
|
||||
timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
|
||||
)
|
||||
|
||||
@@ -232,10 +232,10 @@ Note that requests that time out are [retried twice by default](#retries).
|
||||
|
||||
We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
|
||||
|
||||
You can enable logging by setting the environment variable `HANZO_AI_LOG` to `info`.
|
||||
You can enable logging by setting the environment variable `HANZO_LOG` to `info`.
|
||||
|
||||
```shell
|
||||
$ export HANZO_AI_LOG=info
|
||||
$ export HANZO_LOG=info
|
||||
```
|
||||
|
||||
Or to `debug` for more verbose logging.
|
||||
@@ -257,9 +257,9 @@ if response.my_field is None:
|
||||
The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
|
||||
|
||||
```py
|
||||
from Hanzo_AI import HanzoAI
|
||||
from hanzoai import Hanzo
|
||||
|
||||
client = HanzoAI()
|
||||
client = Hanzo()
|
||||
response = client.with_raw_response.get_home()
|
||||
print(response.headers.get('X-My-Header'))
|
||||
|
||||
@@ -267,9 +267,9 @@ client = response.parse() # get the object that `get_home()` would have returne
|
||||
print(client)
|
||||
```
|
||||
|
||||
These methods return an [`APIResponse`](https://github.com/hanzoai/python-sdk/tree/main/src/Hanzo_AI/_response.py) object.
|
||||
These methods return an [`APIResponse`](https://github.com/hanzoai/python-sdk/tree/main/src/hanzoai/_response.py) object.
|
||||
|
||||
The async client returns an [`AsyncAPIResponse`](https://github.com/hanzoai/python-sdk/tree/main/src/Hanzo_AI/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
|
||||
The async client returns an [`AsyncAPIResponse`](https://github.com/hanzoai/python-sdk/tree/main/src/hanzoai/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
|
||||
|
||||
#### `.with_streaming_response`
|
||||
|
||||
@@ -331,10 +331,10 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
|
||||
|
||||
```python
|
||||
import httpx
|
||||
from Hanzo_AI import HanzoAI, DefaultHttpxClient
|
||||
from hanzoai import Hanzo, DefaultHttpxClient
|
||||
|
||||
client = HanzoAI(
|
||||
# Or use the `HANZO_AI_BASE_URL` env var
|
||||
client = Hanzo(
|
||||
# Or use the `HANZO_BASE_URL` env var
|
||||
base_url="http://my.test.server.example.com:8083",
|
||||
http_client=DefaultHttpxClient(
|
||||
proxy="http://my.test.proxy.example.com",
|
||||
@@ -354,9 +354,9 @@ client.with_options(http_client=DefaultHttpxClient(...))
|
||||
By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
|
||||
|
||||
```py
|
||||
from Hanzo_AI import HanzoAI
|
||||
from hanzoai import Hanzo
|
||||
|
||||
with HanzoAI() as client:
|
||||
with Hanzo() as client:
|
||||
# make requests here
|
||||
...
|
||||
|
||||
@@ -382,8 +382,8 @@ If you've upgraded to the latest version but aren't seeing any new features you
|
||||
You can determine the version that is being used at runtime with:
|
||||
|
||||
```py
|
||||
import Hanzo_AI
|
||||
print(Hanzo_AI.__version__)
|
||||
import hanzoai
|
||||
print(hanzoai.__version__)
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
+3
-3
@@ -16,11 +16,11 @@ before making any information public.
|
||||
## Reporting Non-SDK Related Security Issues
|
||||
|
||||
If you encounter security issues that are not directly related to SDKs but pertain to the services
|
||||
or products provided by Hanzo AI please follow the respective company's security reporting guidelines.
|
||||
or products provided by Hanzo please follow the respective company's security reporting guidelines.
|
||||
|
||||
### Hanzo AI Terms and Policies
|
||||
### Hanzo Terms and Policies
|
||||
|
||||
Please contact dev-feedback@Hanzo-AI.com for any questions or concerns regarding security of our services.
|
||||
Please contact dev-feedback@hanzo.ai for any questions or concerns regarding security of our services.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
errors=()
|
||||
|
||||
if [ -z "${PYPI_TOKEN}" ]; then
|
||||
errors+=("The HANZO_AI_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
|
||||
errors+=("The HANZO_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
|
||||
fi
|
||||
|
||||
lenErrors=${#errors[@]}
|
||||
|
||||
@@ -8,7 +8,7 @@ show_error_codes = True
|
||||
#
|
||||
# We also exclude our `tests` as mypy doesn't always infer
|
||||
# types correctly and Pyright will still catch any type errors.
|
||||
exclude = ^(src/Hanzo_AI/_files\.py|_dev/.*\.py|tests/.*)$
|
||||
exclude = ^(src/hanzoai/_files\.py|_dev/.*\.py|tests/.*)$
|
||||
|
||||
strict_equality = True
|
||||
implicit_reexport = True
|
||||
|
||||
+6
-6
@@ -1,11 +1,11 @@
|
||||
[project]
|
||||
name = "hanzoai"
|
||||
version = "0.0.1-alpha.0"
|
||||
description = "The official Python library for the Hanzo-AI API"
|
||||
description = "The official Python library for the Hanzo API"
|
||||
dynamic = ["readme"]
|
||||
license = "Apache-2.0"
|
||||
authors = [
|
||||
{ name = "Hanzo AI", email = "dev-feedback@Hanzo-AI.com" },
|
||||
{ name = "Hanzo", email = "dev-feedback@hanzo.ai" },
|
||||
]
|
||||
dependencies = [
|
||||
"httpx>=0.23.0, <1",
|
||||
@@ -75,14 +75,14 @@ format = { chain = [
|
||||
"check:ruff" = "ruff check ."
|
||||
"fix:ruff" = "ruff check --fix ."
|
||||
|
||||
"check:importable" = "python -c 'import Hanzo_AI'"
|
||||
"check:importable" = "python -c 'import hanzoai'"
|
||||
|
||||
typecheck = { chain = [
|
||||
"typecheck:pyright",
|
||||
"typecheck:mypy"
|
||||
]}
|
||||
"typecheck:pyright" = "pyright"
|
||||
"typecheck:verify-types" = "pyright --verifytypes Hanzo_AI --ignoreexternal"
|
||||
"typecheck:verify-types" = "pyright --verifytypes hanzoai --ignoreexternal"
|
||||
"typecheck:mypy" = "mypy ."
|
||||
|
||||
[build-system]
|
||||
@@ -95,7 +95,7 @@ include = [
|
||||
]
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["src/Hanzo_AI"]
|
||||
packages = ["src/hanzoai"]
|
||||
|
||||
[tool.hatch.build.targets.sdist]
|
||||
# Basically everything except hidden files/directories (such as .github, .devcontainers, .python-version, etc)
|
||||
@@ -197,7 +197,7 @@ length-sort = true
|
||||
length-sort-straight = true
|
||||
combine-as-imports = true
|
||||
extra-standard-library = ["typing_extensions"]
|
||||
known-first-party = ["Hanzo_AI", "tests"]
|
||||
known-first-party = ["hanzoai", "tests"]
|
||||
|
||||
[tool.ruff.lint.per-file-ignores]
|
||||
"bin/**.py" = ["T201", "T203"]
|
||||
|
||||
@@ -61,6 +61,6 @@
|
||||
],
|
||||
"release-type": "python",
|
||||
"extra-files": [
|
||||
"src/Hanzo_AI/_version.py"
|
||||
"src/hanzoai/_version.py"
|
||||
]
|
||||
}
|
||||
+1
-1
@@ -8,4 +8,4 @@ echo "==> Running lints"
|
||||
rye run lint
|
||||
|
||||
echo "==> Making sure it imports"
|
||||
rye run python -c 'import Hanzo_AI'
|
||||
rye run python -c 'import hanzoai'
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
from . import types
|
||||
from ._types import NOT_GIVEN, Omit, NoneType, NotGiven, Transport, ProxiesTypes
|
||||
from ._utils import file_from_path
|
||||
from ._client import Client, Stream, HanzoAI, Timeout, Transport, AsyncClient, AsyncStream, AsyncHanzoAI, RequestOptions
|
||||
from ._client import 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
|
||||
from ._constants import DEFAULT_TIMEOUT, DEFAULT_MAX_RETRIES, DEFAULT_CONNECTION_LIMITS
|
||||
from ._exceptions import (
|
||||
APIError,
|
||||
HanzoAIError,
|
||||
HanzoError,
|
||||
ConflictError,
|
||||
NotFoundError,
|
||||
APIStatusError,
|
||||
@@ -37,7 +37,7 @@ __all__ = [
|
||||
"NotGiven",
|
||||
"NOT_GIVEN",
|
||||
"Omit",
|
||||
"HanzoAIError",
|
||||
"HanzoError",
|
||||
"APIError",
|
||||
"APIStatusError",
|
||||
"APITimeoutError",
|
||||
@@ -57,8 +57,8 @@ __all__ = [
|
||||
"AsyncClient",
|
||||
"Stream",
|
||||
"AsyncStream",
|
||||
"HanzoAI",
|
||||
"AsyncHanzoAI",
|
||||
"Hanzo",
|
||||
"AsyncHanzo",
|
||||
"file_from_path",
|
||||
"BaseModel",
|
||||
"DEFAULT_TIMEOUT",
|
||||
@@ -73,12 +73,12 @@ _setup_logging()
|
||||
# Update the __module__ attribute for exported symbols so that
|
||||
# error messages point to this module instead of the module
|
||||
# it was originally defined in, e.g.
|
||||
# Hanzo_AI._exceptions.NotFoundError -> Hanzo_AI.NotFoundError
|
||||
# hanzoai._exceptions.NotFoundError -> hanzoai.NotFoundError
|
||||
__locals = locals()
|
||||
for __name in __all__:
|
||||
if not __name.startswith("__"):
|
||||
try:
|
||||
__locals[__name].__module__ = "Hanzo_AI"
|
||||
__locals[__name].__module__ = "hanzoai"
|
||||
except (TypeError, AttributeError):
|
||||
# Some of our exported symbols are builtins which we can't set attributes for.
|
||||
pass
|
||||
@@ -360,7 +360,7 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
||||
|
||||
if max_retries is None: # pyright: ignore[reportUnnecessaryComparison]
|
||||
raise TypeError(
|
||||
"max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number; if you want the default behavior, pass `Hanzo_AI.DEFAULT_MAX_RETRIES`"
|
||||
"max_retries cannot be None. If you want to disable retries, pass `0`; if you want unlimited retries, pass `math.inf` or a very high number; if you want the default behavior, pass `hanzoai.DEFAULT_MAX_RETRIES`"
|
||||
)
|
||||
|
||||
def _enforce_trailing_slash(self, url: URL) -> URL:
|
||||
@@ -67,7 +67,7 @@ from .resources import (
|
||||
eu_assemblyai,
|
||||
)
|
||||
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
|
||||
from ._exceptions import HanzoAIError, APIStatusError
|
||||
from ._exceptions import HanzoError, APIStatusError
|
||||
from ._base_client import (
|
||||
DEFAULT_MAX_RETRIES,
|
||||
SyncAPIClient,
|
||||
@@ -92,10 +92,10 @@ from .resources.responses import responses
|
||||
from .resources.fine_tuning import fine_tuning
|
||||
from .resources.organization import organization
|
||||
|
||||
__all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "HanzoAI", "AsyncHanzoAI", "Client", "AsyncClient"]
|
||||
__all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Hanzo", "AsyncHanzo", "Client", "AsyncClient"]
|
||||
|
||||
|
||||
class HanzoAI(SyncAPIClient):
|
||||
class Hanzo(SyncAPIClient):
|
||||
models: models.ModelsResource
|
||||
openai: openai.OpenAIResource
|
||||
engines: engines.EnginesResource
|
||||
@@ -144,8 +144,8 @@ class HanzoAI(SyncAPIClient):
|
||||
delete: delete.DeleteResource
|
||||
files: files.FilesResource
|
||||
budget: budget.BudgetResource
|
||||
with_raw_response: HanzoAIWithRawResponse
|
||||
with_streaming_response: HanzoAIWithStreamedResponse
|
||||
with_raw_response: HanzoWithRawResponse
|
||||
with_streaming_response: HanzoWithStreamedResponse
|
||||
|
||||
# client options
|
||||
api_key: str
|
||||
@@ -173,22 +173,22 @@ class HanzoAI(SyncAPIClient):
|
||||
# part of our public interface in the future.
|
||||
_strict_response_validation: bool = False,
|
||||
) -> None:
|
||||
"""Construct a new synchronous HanzoAI client instance.
|
||||
"""Construct a new synchronous Hanzo client instance.
|
||||
|
||||
This automatically infers the `api_key` argument from the `HANZO_AI_API_KEY` environment variable if it is not provided.
|
||||
This automatically infers the `api_key` argument from the `HANZO_API_KEY` environment variable if it is not provided.
|
||||
"""
|
||||
if api_key is None:
|
||||
api_key = os.environ.get("HANZO_AI_API_KEY")
|
||||
api_key = os.environ.get("HANZO_API_KEY")
|
||||
if api_key is None:
|
||||
raise HanzoAIError(
|
||||
"The api_key client option must be set either by passing api_key to the client or by setting the HANZO_AI_API_KEY environment variable"
|
||||
raise HanzoError(
|
||||
"The api_key client option must be set either by passing api_key to the client or by setting the HANZO_API_KEY environment variable"
|
||||
)
|
||||
self.api_key = api_key
|
||||
|
||||
if base_url is None:
|
||||
base_url = os.environ.get("HANZO_AI_BASE_URL")
|
||||
base_url = os.environ.get("HANZO_BASE_URL")
|
||||
if base_url is None:
|
||||
base_url = f"https://api.example.com"
|
||||
base_url = f"https://api.hanzo.ai"
|
||||
|
||||
super().__init__(
|
||||
version=__version__,
|
||||
@@ -249,8 +249,8 @@ class HanzoAI(SyncAPIClient):
|
||||
self.delete = delete.DeleteResource(self)
|
||||
self.files = files.FilesResource(self)
|
||||
self.budget = budget.BudgetResource(self)
|
||||
self.with_raw_response = HanzoAIWithRawResponse(self)
|
||||
self.with_streaming_response = HanzoAIWithStreamedResponse(self)
|
||||
self.with_raw_response = HanzoWithRawResponse(self)
|
||||
self.with_streaming_response = HanzoWithStreamedResponse(self)
|
||||
|
||||
@property
|
||||
@override
|
||||
@@ -376,7 +376,7 @@ class HanzoAI(SyncAPIClient):
|
||||
return APIStatusError(err_msg, response=response, body=body)
|
||||
|
||||
|
||||
class AsyncHanzoAI(AsyncAPIClient):
|
||||
class AsyncHanzo(AsyncAPIClient):
|
||||
models: models.AsyncModelsResource
|
||||
openai: openai.AsyncOpenAIResource
|
||||
engines: engines.AsyncEnginesResource
|
||||
@@ -425,8 +425,8 @@ class AsyncHanzoAI(AsyncAPIClient):
|
||||
delete: delete.AsyncDeleteResource
|
||||
files: files.AsyncFilesResource
|
||||
budget: budget.AsyncBudgetResource
|
||||
with_raw_response: AsyncHanzoAIWithRawResponse
|
||||
with_streaming_response: AsyncHanzoAIWithStreamedResponse
|
||||
with_raw_response: AsyncHanzoWithRawResponse
|
||||
with_streaming_response: AsyncHanzoWithStreamedResponse
|
||||
|
||||
# client options
|
||||
api_key: str
|
||||
@@ -454,22 +454,22 @@ class AsyncHanzoAI(AsyncAPIClient):
|
||||
# part of our public interface in the future.
|
||||
_strict_response_validation: bool = False,
|
||||
) -> None:
|
||||
"""Construct a new async AsyncHanzoAI client instance.
|
||||
"""Construct a new async AsyncHanzo client instance.
|
||||
|
||||
This automatically infers the `api_key` argument from the `HANZO_AI_API_KEY` environment variable if it is not provided.
|
||||
This automatically infers the `api_key` argument from the `HANZO_API_KEY` environment variable if it is not provided.
|
||||
"""
|
||||
if api_key is None:
|
||||
api_key = os.environ.get("HANZO_AI_API_KEY")
|
||||
api_key = os.environ.get("HANZO_API_KEY")
|
||||
if api_key is None:
|
||||
raise HanzoAIError(
|
||||
"The api_key client option must be set either by passing api_key to the client or by setting the HANZO_AI_API_KEY environment variable"
|
||||
raise HanzoError(
|
||||
"The api_key client option must be set either by passing api_key to the client or by setting the HANZO_API_KEY environment variable"
|
||||
)
|
||||
self.api_key = api_key
|
||||
|
||||
if base_url is None:
|
||||
base_url = os.environ.get("HANZO_AI_BASE_URL")
|
||||
base_url = os.environ.get("HANZO_BASE_URL")
|
||||
if base_url is None:
|
||||
base_url = f"https://api.example.com"
|
||||
base_url = f"https://api.hanzo.ai"
|
||||
|
||||
super().__init__(
|
||||
version=__version__,
|
||||
@@ -530,8 +530,8 @@ class AsyncHanzoAI(AsyncAPIClient):
|
||||
self.delete = delete.AsyncDeleteResource(self)
|
||||
self.files = files.AsyncFilesResource(self)
|
||||
self.budget = budget.AsyncBudgetResource(self)
|
||||
self.with_raw_response = AsyncHanzoAIWithRawResponse(self)
|
||||
self.with_streaming_response = AsyncHanzoAIWithStreamedResponse(self)
|
||||
self.with_raw_response = AsyncHanzoWithRawResponse(self)
|
||||
self.with_streaming_response = AsyncHanzoWithStreamedResponse(self)
|
||||
|
||||
@property
|
||||
@override
|
||||
@@ -657,8 +657,8 @@ class AsyncHanzoAI(AsyncAPIClient):
|
||||
return APIStatusError(err_msg, response=response, body=body)
|
||||
|
||||
|
||||
class HanzoAIWithRawResponse:
|
||||
def __init__(self, client: HanzoAI) -> None:
|
||||
class HanzoWithRawResponse:
|
||||
def __init__(self, client: Hanzo) -> None:
|
||||
self.models = models.ModelsResourceWithRawResponse(client.models)
|
||||
self.openai = openai.OpenAIResourceWithRawResponse(client.openai)
|
||||
self.engines = engines.EnginesResourceWithRawResponse(client.engines)
|
||||
@@ -713,8 +713,8 @@ class HanzoAIWithRawResponse:
|
||||
)
|
||||
|
||||
|
||||
class AsyncHanzoAIWithRawResponse:
|
||||
def __init__(self, client: AsyncHanzoAI) -> None:
|
||||
class AsyncHanzoWithRawResponse:
|
||||
def __init__(self, client: AsyncHanzo) -> None:
|
||||
self.models = models.AsyncModelsResourceWithRawResponse(client.models)
|
||||
self.openai = openai.AsyncOpenAIResourceWithRawResponse(client.openai)
|
||||
self.engines = engines.AsyncEnginesResourceWithRawResponse(client.engines)
|
||||
@@ -769,8 +769,8 @@ class AsyncHanzoAIWithRawResponse:
|
||||
)
|
||||
|
||||
|
||||
class HanzoAIWithStreamedResponse:
|
||||
def __init__(self, client: HanzoAI) -> None:
|
||||
class HanzoWithStreamedResponse:
|
||||
def __init__(self, client: Hanzo) -> None:
|
||||
self.models = models.ModelsResourceWithStreamingResponse(client.models)
|
||||
self.openai = openai.OpenAIResourceWithStreamingResponse(client.openai)
|
||||
self.engines = engines.EnginesResourceWithStreamingResponse(client.engines)
|
||||
@@ -825,8 +825,8 @@ class HanzoAIWithStreamedResponse:
|
||||
)
|
||||
|
||||
|
||||
class AsyncHanzoAIWithStreamedResponse:
|
||||
def __init__(self, client: AsyncHanzoAI) -> None:
|
||||
class AsyncHanzoWithStreamedResponse:
|
||||
def __init__(self, client: AsyncHanzo) -> None:
|
||||
self.models = models.AsyncModelsResourceWithStreamingResponse(client.models)
|
||||
self.openai = openai.AsyncOpenAIResourceWithStreamingResponse(client.openai)
|
||||
self.engines = engines.AsyncEnginesResourceWithStreamingResponse(client.engines)
|
||||
@@ -881,6 +881,6 @@ class AsyncHanzoAIWithStreamedResponse:
|
||||
)
|
||||
|
||||
|
||||
Client = HanzoAI
|
||||
Client = Hanzo
|
||||
|
||||
AsyncClient = AsyncHanzoAI
|
||||
AsyncClient = AsyncHanzo
|
||||
@@ -18,11 +18,11 @@ __all__ = [
|
||||
]
|
||||
|
||||
|
||||
class HanzoAIError(Exception):
|
||||
class HanzoError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class APIError(HanzoAIError):
|
||||
class APIError(HanzoError):
|
||||
message: str
|
||||
request: httpx.Request
|
||||
|
||||
@@ -8,13 +8,13 @@ from typing import TYPE_CHECKING
|
||||
import anyio
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._client import HanzoAI, AsyncHanzoAI
|
||||
from ._client import Hanzo, AsyncHanzo
|
||||
|
||||
|
||||
class SyncAPIResource:
|
||||
_client: HanzoAI
|
||||
_client: Hanzo
|
||||
|
||||
def __init__(self, client: HanzoAI) -> None:
|
||||
def __init__(self, client: Hanzo) -> None:
|
||||
self._client = client
|
||||
self._get = client.get
|
||||
self._post = client.post
|
||||
@@ -28,9 +28,9 @@ class SyncAPIResource:
|
||||
|
||||
|
||||
class AsyncAPIResource:
|
||||
_client: AsyncHanzoAI
|
||||
_client: AsyncHanzo
|
||||
|
||||
def __init__(self, client: AsyncHanzoAI) -> None:
|
||||
def __init__(self, client: AsyncHanzo) -> None:
|
||||
self._client = client
|
||||
self._get = client.get
|
||||
self._post = client.post
|
||||
@@ -29,7 +29,7 @@ from ._utils import is_given, extract_type_arg, is_annotated_type, is_type_alias
|
||||
from ._models import BaseModel, is_basemodel
|
||||
from ._constants import RAW_RESPONSE_HEADER, OVERRIDE_CAST_TO_HEADER
|
||||
from ._streaming import Stream, AsyncStream, is_stream_class_type, extract_stream_chunk_type
|
||||
from ._exceptions import HanzoAIError, APIResponseValidationError
|
||||
from ._exceptions import HanzoError, APIResponseValidationError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._models import FinalRequestOptions
|
||||
@@ -217,7 +217,7 @@ class BaseAPIResponse(Generic[R]):
|
||||
and not issubclass(origin, BaseModel)
|
||||
and issubclass(origin, pydantic.BaseModel)
|
||||
):
|
||||
raise TypeError("Pydantic models must subclass our base model type, e.g. `from Hanzo_AI import BaseModel`")
|
||||
raise TypeError("Pydantic models must subclass our base model type, e.g. `from hanzoai import BaseModel`")
|
||||
|
||||
if (
|
||||
cast_to is not object
|
||||
@@ -283,7 +283,7 @@ class APIResponse(BaseAPIResponse[R]):
|
||||
the `to` argument, e.g.
|
||||
|
||||
```py
|
||||
from Hanzo_AI import BaseModel
|
||||
from hanzoai import BaseModel
|
||||
|
||||
|
||||
class MyModel(BaseModel):
|
||||
@@ -385,7 +385,7 @@ class AsyncAPIResponse(BaseAPIResponse[R]):
|
||||
the `to` argument, e.g.
|
||||
|
||||
```py
|
||||
from Hanzo_AI import BaseModel
|
||||
from hanzoai import BaseModel
|
||||
|
||||
|
||||
class MyModel(BaseModel):
|
||||
@@ -556,11 +556,11 @@ class AsyncStreamedBinaryAPIResponse(AsyncAPIResponse[bytes]):
|
||||
class MissingStreamClassError(TypeError):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
"The `stream` argument was set to `True` but the `stream_cls` argument was not given. See `Hanzo_AI._streaming` for reference",
|
||||
"The `stream` argument was set to `True` but the `stream_cls` argument was not given. See `hanzoai._streaming` for reference",
|
||||
)
|
||||
|
||||
|
||||
class StreamAlreadyConsumed(HanzoAIError):
|
||||
class StreamAlreadyConsumed(HanzoError):
|
||||
"""
|
||||
Attempted to read or stream content, but the content has already
|
||||
been streamed.
|
||||
@@ -12,7 +12,7 @@ import httpx
|
||||
from ._utils import extract_type_var_from_base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ._client import HanzoAI, AsyncHanzoAI
|
||||
from ._client import Hanzo, AsyncHanzo
|
||||
|
||||
|
||||
_T = TypeVar("_T")
|
||||
@@ -30,7 +30,7 @@ class Stream(Generic[_T]):
|
||||
*,
|
||||
cast_to: type[_T],
|
||||
response: httpx.Response,
|
||||
client: HanzoAI,
|
||||
client: Hanzo,
|
||||
) -> None:
|
||||
self.response = response
|
||||
self._cast_to = cast_to
|
||||
@@ -93,7 +93,7 @@ class AsyncStream(Generic[_T]):
|
||||
*,
|
||||
cast_to: type[_T],
|
||||
response: httpx.Response,
|
||||
client: AsyncHanzoAI,
|
||||
client: AsyncHanzo,
|
||||
) -> None:
|
||||
self.response = response
|
||||
self._cast_to = cast_to
|
||||
@@ -81,7 +81,7 @@ HttpxRequestFiles = Union[Mapping[str, HttpxFileTypes], Sequence[Tuple[str, Http
|
||||
# This unfortunately means that you will either have
|
||||
# to import this type and pass it explicitly:
|
||||
#
|
||||
# from Hanzo_AI import NoneType
|
||||
# from hanzoai import NoneType
|
||||
# client.get('/foo', cast_to=NoneType)
|
||||
#
|
||||
# or build it yourself:
|
||||
@@ -1,12 +1,12 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
logger: logging.Logger = logging.getLogger("Hanzo_AI")
|
||||
logger: logging.Logger = logging.getLogger("hanzoai")
|
||||
httpx_logger: logging.Logger = logging.getLogger("httpx")
|
||||
|
||||
|
||||
def _basic_config() -> None:
|
||||
# e.g. [2023-10-05 14:12:26 - Hanzo_AI._base_client:818 - DEBUG] HTTP Request: POST http://127.0.0.1:4010/foo/bar "200 OK"
|
||||
# e.g. [2023-10-05 14:12:26 - hanzoai._base_client:818 - DEBUG] HTTP Request: POST http://127.0.0.1:4010/foo/bar "200 OK"
|
||||
logging.basicConfig(
|
||||
format="[%(asctime)s - %(name)s:%(lineno)d - %(levelname)s] %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
@@ -14,7 +14,7 @@ def _basic_config() -> None:
|
||||
|
||||
|
||||
def setup_logging() -> None:
|
||||
env = os.environ.get("HANZO_AI_LOG")
|
||||
env = os.environ.get("HANZO_LOG")
|
||||
if env == "debug":
|
||||
_basic_config()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
@@ -1,4 +1,4 @@
|
||||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
__title__ = "Hanzo_AI"
|
||||
__title__ = "hanzoai"
|
||||
__version__ = "0.0.1-alpha.0" # x-release-please-version
|
||||
@@ -0,0 +1,4 @@
|
||||
File generated from our OpenAPI spec by Stainless.
|
||||
|
||||
This directory can be used to store custom files to expand the SDK.
|
||||
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user