Skip to content
Merged
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
6 changes: 4 additions & 2 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"cliVersion": "3.4.3",
"generatorName": "fernapi/fern-python-sdk",
"generatorVersion": "4.38.0",
"generatorVersion": "4.46.6",
"generatorConfig": {
"should_generate_websocket_clients": true,
"pyproject_python_version": ">=3.9,<4",
"enable_wire_tests": true,
"client": {
"class_name": "BaseHumeClient",
"filename": "base_client.py",
Expand Down Expand Up @@ -62,5 +63,6 @@
]
}
]
}
},
"sdkVersion": "0.13.6"
}
3 changes: 0 additions & 3 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ src/hume/client.py
src/hume/empathic_voice/chat/client.py
src/hume/empathic_voice/chat/raw_client.py

# Needs to add .chat to reference chat_client
src/hume/empathic_voice/client.py

# Needs to add .stream to reference expression measurement stream client
# Also wrap the .batch client in BatchClientWithUtils
src/hume/expression_measurement/client.py
Expand Down
279 changes: 153 additions & 126 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[project]
name = "hume"
dynamic = ["version"]

[tool.poetry]
name = "hume"
Expand Down Expand Up @@ -77,6 +78,8 @@ pytest-asyncio = "^0.23.5"
pytest-xdist = "^3.6.1"
python-dateutil = "^2.9.0"
types-python-dateutil = "^2.9.0.20240316"
requests = "^2.31.0"
types-requests = "^2.31.0"
covcheck = { version = "^0.4.3", extras = ["toml"]}
pydocstyle = "^6.1.1"
pydub-stubs = "^0.25.1"
Expand Down
96 changes: 48 additions & 48 deletions reference.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/hume/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
if typing.TYPE_CHECKING:
from .api_error import ApiError
from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper
from .custom_pagination import AsyncCustomPager, SyncCustomPager
from .datetime_utils import serialize_datetime
from .events import EventEmitterMixin, EventType
from .file import File, convert_file_dict_to_httpx_tuples, with_content_type
Expand All @@ -31,6 +32,7 @@
_dynamic_imports: typing.Dict[str, str] = {
"ApiError": ".api_error",
"AsyncClientWrapper": ".client_wrapper",
"AsyncCustomPager": ".custom_pagination",
"AsyncHttpClient": ".http_client",
"AsyncHttpResponse": ".http_response",
"AsyncPager": ".pagination",
Expand All @@ -44,6 +46,7 @@
"IS_PYDANTIC_V2": ".pydantic_utilities",
"RequestOptions": ".request_options",
"SyncClientWrapper": ".client_wrapper",
"SyncCustomPager": ".custom_pagination",
"SyncPager": ".pagination",
"UniversalBaseModel": ".pydantic_utilities",
"UniversalRootModel": ".pydantic_utilities",
Expand Down Expand Up @@ -85,6 +88,7 @@ def __dir__():
__all__ = [
"ApiError",
"AsyncClientWrapper",
"AsyncCustomPager",
"AsyncHttpClient",
"AsyncHttpResponse",
"AsyncPager",
Expand All @@ -98,6 +102,7 @@ def __dir__():
"IS_PYDANTIC_V2",
"RequestOptions",
"SyncClientWrapper",
"SyncCustomPager",
"SyncPager",
"UniversalBaseModel",
"UniversalRootModel",
Expand Down
14 changes: 13 additions & 1 deletion src/hume/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,21 @@ def __init__(
headers: typing.Optional[typing.Dict[str, str]] = None,
environment: HumeClientEnvironment,
timeout: typing.Optional[float] = None,
async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
httpx_client: httpx.AsyncClient,
):
super().__init__(api_key=api_key, headers=headers, environment=environment, timeout=timeout)
self._async_token = async_token
self.httpx_client = AsyncHttpClient(
httpx_client=httpx_client, base_headers=self.get_headers, base_timeout=self.get_timeout
httpx_client=httpx_client,
base_headers=self.get_headers,
base_timeout=self.get_timeout,
async_base_headers=self.async_get_headers,
)

async def async_get_headers(self) -> typing.Dict[str, str]:
headers = self.get_headers()
if self._async_token is not None:
token = await self._async_token()
headers["Authorization"] = f"Bearer {token}"
return headers
152 changes: 152 additions & 0 deletions src/hume/core/custom_pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# This file was auto-generated by Fern from our API Definition.

"""
Custom Pagination Support

This file is designed to be modified by SDK users to implement their own
pagination logic. The generator will import SyncCustomPager and AsyncCustomPager
from this module when custom pagination is used.

Users should:
1. Implement their custom pager (e.g., PayrocPager, MyCustomPager, etc.)
2. Create adapter classes (SyncCustomPager/AsyncCustomPager) that bridge
between the generated SDK code and their custom pager implementation
"""

from __future__ import annotations

from typing import Any, AsyncIterator, Generic, Iterator, TypeVar

# Import the base utilities you'll need
# Adjust these imports based on your actual structure
try:
from .client_wrapper import AsyncClientWrapper, SyncClientWrapper
except ImportError:
# Fallback for type hints
AsyncClientWrapper = Any # type: ignore
SyncClientWrapper = Any # type: ignore

TItem = TypeVar("TItem")
TResponse = TypeVar("TResponse")


class SyncCustomPager(Generic[TItem, TResponse]):
"""
Adapter for custom synchronous pagination.

The generator will call this with:
SyncCustomPager(initial_response=response, client_wrapper=client_wrapper)

Implement this class to extract pagination metadata from your response
and delegate to your custom pager implementation.

Example implementation:

class SyncCustomPager(Generic[TItem, TResponse]):
def __init__(
self,
*,
initial_response: TResponse,
client_wrapper: SyncClientWrapper,
):
# Extract data and pagination metadata from response
data = initial_response.data # Adjust based on your response structure
links = initial_response.links

# Initialize your custom pager
self._pager = MyCustomPager(
current_page=Page(data),
httpx_client=client_wrapper.httpx_client,
get_headers=client_wrapper.get_headers,
# ... other parameters
)

def __iter__(self):
return iter(self._pager)

# Delegate other methods to your pager...
"""

def __init__(
self,
*,
initial_response: TResponse,
client_wrapper: SyncClientWrapper,
):
"""
Initialize the custom pager.

Args:
initial_response: The parsed API response from the first request
client_wrapper: The client wrapper providing HTTP client and utilities
"""
raise NotImplementedError(
"SyncCustomPager must be implemented. "
"Please implement this class in core/custom_pagination.py to define your pagination logic. "
"See the class docstring for examples."
)

def __iter__(self) -> Iterator[TItem]:
"""Iterate through all items across all pages."""
raise NotImplementedError("Must implement __iter__ method")


class AsyncCustomPager(Generic[TItem, TResponse]):
"""
Adapter for custom asynchronous pagination.

The generator will call this with:
AsyncCustomPager(initial_response=response, client_wrapper=client_wrapper)

Implement this class to extract pagination metadata from your response
and delegate to your custom async pager implementation.

Example implementation:

class AsyncCustomPager(Generic[TItem, TResponse]):
def __init__(
self,
*,
initial_response: TResponse,
client_wrapper: AsyncClientWrapper,
):
# Extract data and pagination metadata from response
data = initial_response.data # Adjust based on your response structure
links = initial_response.links

# Initialize your custom async pager
self._pager = MyAsyncCustomPager(
current_page=Page(data),
httpx_client=client_wrapper.httpx_client,
get_headers=client_wrapper.get_headers,
# ... other parameters
)

async def __aiter__(self):
return self._pager.__aiter__()

# Delegate other methods to your pager...
"""

def __init__(
self,
*,
initial_response: TResponse,
client_wrapper: AsyncClientWrapper,
):
"""
Initialize the custom async pager.

Args:
initial_response: The parsed API response from the first request
client_wrapper: The client wrapper providing HTTP client and utilities
"""
raise NotImplementedError(
"AsyncCustomPager must be implemented. "
"Please implement this class in core/custom_pagination.py to define your pagination logic. "
"See the class docstring for examples."
)

async def __aiter__(self) -> AsyncIterator[TItem]:
"""Asynchronously iterate through all items across all pages."""
raise NotImplementedError("Must implement __aiter__ method")
Loading