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
2 changes: 2 additions & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ src/hume/expression_measurement/client.py
src/hume/tts/client.py

src/hume/expression_measurement/batch/client_with_utils.py
# Backward compatibility for InferenceJob.status
src/hume/expression_measurement/batch/types/inference_job.py
src/hume/empathic_voice/chat/audio/microphone.py
src/hume/empathic_voice/chat/audio/microphone_interface.py
src/hume/empathic_voice/chat/audio/microphone_sender.py
Expand Down
86 changes: 63 additions & 23 deletions src/hume/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,44 @@
from .environment import HumeClientEnvironment


def _base_url_to_environment(base_url: str) -> HumeClientEnvironment:
if base_url.startswith("http://"):
return HumeClientEnvironment(
base=base_url,
evi=base_url.replace("http://", "ws://") + "/v0/evi",
tts=base_url.replace("http://", "ws://") + "/v0/tts",
stream=base_url.replace("http://", "ws://") + "/v0/stream",
)
elif base_url.startswith("https://"):
return HumeClientEnvironment(
base=base_url,
evi=base_url.replace("https://", "wss://") + "/v0/evi",
tts=base_url.replace("https://", "wss://") + "/v0/tts",
stream=base_url.replace("https://", "wss://") + "/v0/stream",
)
else:
# Assume https if no protocol specified
return HumeClientEnvironment(
base="https://" + base_url,
evi="wss://" + base_url + "/v0/evi",
tts="wss://" + base_url + "/v0/tts",
stream="wss://" + base_url + "/v0/stream",
)


class HumeClient(BaseHumeClient):
"""
Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propogate to these functions.

Parameters
----------
base_url : typing.Optional[str]
The base url to use for requests from the client.

environment : HumeClientEnvironment
The base URL to use for requests from the client. If provided, this will be converted
to a HumeClientEnvironment. Can be a full URL (http://... or https://...) or just
a hostname (which will default to https://).
environment : typing.Optional[HumeClientEnvironment]
The environment to use for requests from the client. from .environment import HumeClientEnvironment



Defaults to HumeClientEnvironment.PROD



Defaults to None, which will use HumeClientEnvironment.PROD. Cannot be specified together with base_url.
api_key : typing.Optional[str]
timeout : typing.Optional[float]
The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set.
Expand All @@ -49,18 +69,27 @@ class HumeClient(BaseHumeClient):
def __init__(
self,
*,
# TODO: this was removed by the generator?
# base_url: typing.Optional[str] = None,
environment: HumeClientEnvironment = HumeClientEnvironment.PROD,
base_url: typing.Optional[str] = None,
environment: typing.Optional[HumeClientEnvironment] = None,
api_key: typing.Optional[str] = None,
headers: typing.Optional[typing.Dict[str, str]] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.Client] = None
):
# Error if both base_url and environment are specified
if base_url is not None and environment is not None:
raise ValueError("Cannot specify both 'base_url' and 'environment'. Please use only one.")

# Convert base_url string to environment if provided
if base_url is not None:
environment = _base_url_to_environment(base_url)

# Default to PROD if neither base_url nor environment was provided
if environment is None:
environment = HumeClientEnvironment.PROD

super().__init__(
# TODO: this was removed by the generator?
# base_url=base_url,
environment=environment,
api_key=api_key,
headers=headers,
Expand All @@ -76,10 +105,12 @@ class AsyncHumeClient(AsyncBaseHumeClient):
Parameters
----------
base_url : typing.Optional[str]
The base url to use for requests from the client.
environment : HumeClientEnvironment
The base URL to use for requests from the client. If provided, this will be converted
to a HumeClientEnvironment. Can be a full URL (http://... or https://...) or just
a hostname (which will default to https://).
environment : typing.Optional[HumeClientEnvironment]
The environment to use for requests from the client. from .environment import HumeClientEnvironment
Defaults to HumeClientEnvironment.PROD
Defaults to None, which will use HumeClientEnvironment.PROD. Cannot be specified together with base_url.
api_key : typing.Optional[str]
timeout : typing.Optional[float]
The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set.
Expand All @@ -98,18 +129,27 @@ class AsyncHumeClient(AsyncBaseHumeClient):
def __init__(
self,
*,
# TODO: this was removed by the generator?
# base_url: typing.Optional[str] = None,
environment: HumeClientEnvironment = HumeClientEnvironment.PROD,
base_url: typing.Optional[str] = None,
environment: typing.Optional[HumeClientEnvironment] = None,
headers: typing.Optional[typing.Dict[str, str]] = None,
api_key: typing.Optional[str] = None,
timeout: typing.Optional[float] = None,
follow_redirects: typing.Optional[bool] = True,
httpx_client: typing.Optional[httpx.AsyncClient] = None
):
# Error if both base_url and environment are specified
if base_url is not None and environment is not None:
raise ValueError("Cannot specify both 'base_url' and 'environment'. Please use only one.")

# Convert base_url string to environment if provided
if base_url is not None:
environment = _base_url_to_environment(base_url)

# Default to PROD if neither base_url nor environment was provided
if environment is None:
environment = HumeClientEnvironment.PROD

super().__init__(
# TODO: this was removed by the generator?
# base_url=base_url,
environment=environment,
api_key=api_key,
headers=headers,
Expand Down
6 changes: 6 additions & 0 deletions src/hume/expression_measurement/batch/types/inference_job.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was auto-generated by Fern from our API Definition.

import typing
from typing_extensions import deprecated

import pydantic
from ....core.pydantic_utilities import IS_PYDANTIC_V2
Expand All @@ -15,6 +16,11 @@ class InferenceJob(JobInference):
Jobs created with the Expression Measurement API will have this field set to `INFERENCE`.
"""

@property
@deprecated("Use .state.status instead")
def status(self) -> str:
return self.state.status

if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2
else:
Expand Down
4 changes: 2 additions & 2 deletions src/hume/expression_measurement/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def with_raw_response(self) -> RawExpressionMeasurementClient:
@property
def batch(self):
if self._batch is None:
from .batch.client import BatchClient # noqa: E402
from .batch.client_with_utils import BatchClientWithUtils # noqa: E402

self._batch = BatchClientWithUtils(client_wrapper=self._client_wrapper)
return self._batch
Expand Down Expand Up @@ -67,7 +67,7 @@ def with_raw_response(self) -> AsyncRawExpressionMeasurementClient:
@property
def batch(self):
if self._batch is None:
from .batch.client import AsyncBatchClient # noqa: E402
from .batch.client_with_utils import AsyncBatchClientWithUtils # noqa: E402

self._batch = AsyncBatchClientWithUtils(client_wrapper=self._client_wrapper)
return self._batch
Expand Down