Skip to content

Commit 50409f8

Browse files
committed
Restore websockets onto clients and fix tests
1 parent 044cb55 commit 50409f8

File tree

8 files changed

+152
-107
lines changed

8 files changed

+152
-107
lines changed

poetry.lock

Lines changed: 90 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pydantic = ">= 1.9.2"
6868
pydantic-core = ">=2.18.2"
6969
sounddevice = { version = "^0.4.6", optional = true}
7070
typing_extensions = ">= 4.0.0"
71-
websockets = ">=12.0"
71+
websockets = ">=12.0,<14.0"
7272

7373
[tool.poetry.group.dev.dependencies]
7474
mypy = "==1.13.0"

src/hume/client.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66

77
from .base_client import AsyncBaseHumeClient, BaseHumeClient
88

9-
from .empathic_voice.socket_client import AsyncEmpathicVoiceClientWithWebsocket, EmpathicVoiceClientWithWebsocket
109
from .environment import HumeClientEnvironment
11-
from .expression_measurement.socket_client import (
12-
AsyncExpressionMeasurementClientWithWebsocket,
13-
ExpressionMeasurementClientWithWebsocket
14-
)
1510

1611

1712
class HumeClient(BaseHumeClient):
@@ -71,14 +66,6 @@ def __init__(
7166
follow_redirects=follow_redirects,
7267
httpx_client=httpx_client,
7368
)
74-
self.empathic_voice: EmpathicVoiceClientWithWebsocket = (
75-
EmpathicVoiceClientWithWebsocket(client_wrapper=self._client_wrapper)
76-
)
77-
self.expression_measurement: ExpressionMeasurementClientWithWebsocket = (
78-
ExpressionMeasurementClientWithWebsocket(
79-
client_wrapper=self._client_wrapper
80-
)
81-
)
8269

8370

8471
class AsyncHumeClient(AsyncBaseHumeClient):
@@ -126,12 +113,3 @@ def __init__(
126113
follow_redirects=follow_redirects,
127114
httpx_client=httpx_client,
128115
)
129-
self._empathic_voice: AsyncEmpathicVoiceClientWithWebsocket = (
130-
AsyncEmpathicVoiceClientWithWebsocket(client_wrapper=self._client_wrapper)
131-
) # noqa
132-
self._expression_measurement: AsyncExpressionMeasurementClientWithWebsocket = (
133-
AsyncExpressionMeasurementClientWithWebsocket(
134-
client_wrapper=self._client_wrapper
135-
)
136-
) # noqa
137-

src/hume/empathic_voice/chat/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async def connect(
186186
resumed_chat_group_id: typing.Optional[str] = None,
187187
verbose_transcription: typing.Optional[bool] = None,
188188
api_key: typing.Optional[str] = None,
189-
session_settings: ConnectSessionSettings,
189+
session_settings: typing.Optional[ConnectSessionSettings] = None,
190190
request_options: typing.Optional[RequestOptions] = None,
191191
) -> typing.AsyncIterator[AsyncChatSocketClient]:
192192
"""

src/hume/empathic_voice/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import typing
66

7+
from hume.empathic_voice.chat.client import AsyncChatClient, ChatClient
8+
79
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
810
from .raw_client import AsyncRawEmpathicVoiceClient, RawEmpathicVoiceClient
911

@@ -24,6 +26,7 @@ def __init__(self, *, client_wrapper: SyncClientWrapper):
2426
self._configs: typing.Optional[ConfigsClient] = None
2527
self._chats: typing.Optional[ChatsClient] = None
2628
self._chat_groups: typing.Optional[ChatGroupsClient] = None
29+
self._chat: typing.Optional[ChatClient] = None
2730

2831
@property
2932
def with_raw_response(self) -> RawEmpathicVoiceClient:
@@ -86,6 +89,7 @@ def __init__(self, *, client_wrapper: AsyncClientWrapper):
8689
self._configs: typing.Optional[AsyncConfigsClient] = None
8790
self._chats: typing.Optional[AsyncChatsClient] = None
8891
self._chat_groups: typing.Optional[AsyncChatGroupsClient] = None
92+
self._chat: typing.Optional[AsyncChatClient] = None
8993

9094
@property
9195
def with_raw_response(self) -> AsyncRawEmpathicVoiceClient:
@@ -137,3 +141,11 @@ def chat_groups(self):
137141

138142
self._chat_groups = AsyncChatGroupsClient(client_wrapper=self._client_wrapper)
139143
return self._chat_groups
144+
145+
@property
146+
def chat(self):
147+
if self._chat is None:
148+
from .chat.client import AsyncChatClient # noqa: E402
149+
150+
self._chat = AsyncChatClient(client_wrapper=self._client_wrapper)
151+
return self._chat

src/hume/expression_measurement/client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99

1010
if typing.TYPE_CHECKING:
1111
from .batch.client import AsyncBatchClient, BatchClient
12+
from .stream.stream.client import StreamClient, AsyncStreamClient
1213

1314

1415
class ExpressionMeasurementClient:
1516
def __init__(self, *, client_wrapper: SyncClientWrapper):
1617
self._raw_client = RawExpressionMeasurementClient(client_wrapper=client_wrapper)
1718
self._client_wrapper = client_wrapper
1819
self._batch: typing.Optional[BatchClient] = None
20+
self._stream: typing.Optional[StreamClient] = None
1921

2022
@property
2123
def with_raw_response(self) -> RawExpressionMeasurementClient:
@@ -36,12 +38,20 @@ def batch(self):
3638
self._batch = BatchClient(client_wrapper=self._client_wrapper)
3739
return self._batch
3840

41+
@property
42+
def stream(self):
43+
if self._stream is None:
44+
from .stream.stream.client import StreamClient # noqa: E402
45+
self._stream = StreamClient(client_wrapper=self._client_wrapper)
46+
return self._batch
47+
3948

4049
class AsyncExpressionMeasurementClient:
4150
def __init__(self, *, client_wrapper: AsyncClientWrapper):
4251
self._raw_client = AsyncRawExpressionMeasurementClient(client_wrapper=client_wrapper)
4352
self._client_wrapper = client_wrapper
4453
self._batch: typing.Optional[AsyncBatchClient] = None
54+
self._stream: typing.Optional[AsyncStreamClient] = None
4555

4656
@property
4757
def with_raw_response(self) -> AsyncRawExpressionMeasurementClient:
@@ -61,3 +71,11 @@ def batch(self):
6171

6272
self._batch = AsyncBatchClient(client_wrapper=self._client_wrapper)
6373
return self._batch
74+
75+
@property
76+
def stream(self):
77+
if self._stream is None:
78+
from .stream.stream.client import AsyncStreamClient # noqa: E402
79+
80+
self._stream = AsyncStreamClient(client_wrapper=self._client_wrapper)
81+
return self._stream

src/hume/tts/client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import typing
66

7+
from hume.tts.stream_input.client import StreamInputClient
8+
79
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
810
from ..core.request_options import RequestOptions
911
from .raw_client import AsyncRawTtsClient, RawTtsClient
@@ -17,6 +19,7 @@
1719

1820
if typing.TYPE_CHECKING:
1921
from .voices.client import AsyncVoicesClient, VoicesClient
22+
from .stream_input.client import AsyncStreamInputClient, StreamInputClient
2023
# this is used as the default value for optional parameters
2124
OMIT = typing.cast(typing.Any, ...)
2225

@@ -26,6 +29,7 @@ def __init__(self, *, client_wrapper: SyncClientWrapper):
2629
self._raw_client = RawTtsClient(client_wrapper=client_wrapper)
2730
self._client_wrapper = client_wrapper
2831
self._voices: typing.Optional[VoicesClient] = None
32+
self._stream_input: typing.Optional[StreamInputClient] = None
2933

3034
@property
3135
def with_raw_response(self) -> RawTtsClient:
@@ -475,12 +479,20 @@ def voices(self):
475479
self._voices = VoicesClient(client_wrapper=self._client_wrapper)
476480
return self._voices
477481

482+
@property
483+
def stream_input(self):
484+
if self._stream_input is None:
485+
from .stream_input.client import StreamInputClient # noqa: E402
486+
self._stream_input = StreamInputClient(client_wrapper=self._client_wrapper)
487+
return self._stream_input
488+
478489

479490
class AsyncTtsClient:
480491
def __init__(self, *, client_wrapper: AsyncClientWrapper):
481492
self._raw_client = AsyncRawTtsClient(client_wrapper=client_wrapper)
482493
self._client_wrapper = client_wrapper
483494
self._voices: typing.Optional[AsyncVoicesClient] = None
495+
self._stream_input: typing.Optional[AsyncStreamInputClient] = None
484496

485497
@property
486498
def with_raw_response(self) -> AsyncRawTtsClient:
@@ -964,3 +976,13 @@ def voices(self):
964976

965977
self._voices = AsyncVoicesClient(client_wrapper=self._client_wrapper)
966978
return self._voices
979+
980+
@property
981+
def stream_input(self):
982+
if self._stream_input is None:
983+
from .stream_input.client import AsyncStreamInputClient
984+
985+
self._stream_input = AsyncStreamInputClient(
986+
client_wrapper=self._client_wrapper,
987+
)
988+
return self._stream_input

tests/custom/test_hume_wss_client.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
from typing import AsyncContextManager, AsyncIterator, Optional, Any
44
from unittest.mock import Mock
55

6-
import websockets
6+
import websockets.legacy.client
7+
from hume.expression_measurement.stream.stream.socket_client import AsyncStreamSocketClient
78
from pytest import MonkeyPatch
89

910
from hume.client import AsyncHumeClient
10-
from hume.empathic_voice.chat.socket_client import ChatWebsocketConnection
11-
from hume.expression_measurement.stream.socket_client import StreamWebsocketConnection
11+
from hume.empathic_voice.chat.socket_client import AsyncChatSocketClient
1212

1313
logger = logging.getLogger(__name__)
1414

1515

1616
# pylint: disable=unused-argument
17-
def get_mock_connect(connection_string: str, assert_max_size: bool = False) -> Any:
17+
def get_mock_connect(connection_string: str) -> Any:
1818
def mock_connect(
1919
uri: str,
2020
extra_headers: Optional[dict[str, str]] = None,
@@ -26,8 +26,6 @@ def mock_connect(
2626
assert isinstance(extra_headers, dict)
2727
assert extra_headers.get("X-Fern-Language") == "Python"
2828
assert isinstance(extra_headers.get("X-Fern-SDK-Version"), str)
29-
if assert_max_size:
30-
assert max_size == 16777216
3129

3230
@asynccontextmanager
3331
async def mock_connection() -> AsyncIterator[Mock]:
@@ -40,12 +38,12 @@ async def mock_connection() -> AsyncIterator[Mock]:
4038

4139
async def test_chat_connect_basic(monkeypatch: MonkeyPatch) -> None:
4240
hu = AsyncHumeClient(api_key="0000-0000-0000-0000")
43-
monkeypatch.setattr(websockets, "connect", get_mock_connect("wss://api.hume.ai/v0/evi/chat", assert_max_size=True))
41+
monkeypatch.setattr(websockets.legacy.client, "connect", get_mock_connect("wss://api.hume.ai/v0/evi/chat"))
4442
async with hu.empathic_voice.chat.connect() as socket:
45-
assert isinstance(socket, ChatWebsocketConnection)
43+
assert isinstance(socket, AsyncChatSocketClient)
4644

4745
async def test_stream_models_connect_basic(monkeypatch: MonkeyPatch) -> None:
4846
hu = AsyncHumeClient(api_key="0000-0000-0000-0000")
49-
monkeypatch.setattr(websockets, "connect", get_mock_connect("wss://api.hume.ai/v0/stream/models"))
47+
monkeypatch.setattr(websockets.legacy.client, "connect", get_mock_connect("wss://api.hume.ai/v0/stream/models"))
5048
async with hu.expression_measurement.stream.connect() as socket:
51-
assert isinstance(socket, StreamWebsocketConnection)
49+
assert isinstance(socket, AsyncStreamSocketClient)

0 commit comments

Comments
 (0)