Skip to content

Commit bc6b30d

Browse files
committed
fix websocket clients
1 parent 2e0eba3 commit bc6b30d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/hume/empathic_voice/chat/socket_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
import websockets.protocol
1111
from json.decoder import JSONDecodeError
1212

13+
try:
14+
from websockets.legacy.client import connect as websockets_client_connect # type: ignore
15+
except ImportError:
16+
from websockets import connect as websockets_client_connect # type: ignore
17+
1318
from hume.core.websocket import (
1419
OnErrorHandlerType,
1520
OnMessageHandlerType,
@@ -356,7 +361,7 @@ async def connect(
356361
ws_uri = await self._construct_ws_uri(options)
357362

358363
try:
359-
async with websockets.connect(
364+
async with websockets_client_connect(
360365
ws_uri,
361366
extra_headers=exclude_auth_headers(self.client_wrapper.get_headers()),
362367
max_size=self.DEFAULT_MAX_PAYLOAD_SIZE_BYTES,
@@ -448,7 +453,7 @@ async def connect_with_callbacks(
448453
background_task: typing.Optional[asyncio.Task[None]] = None
449454

450455
try:
451-
async with websockets.connect(
456+
async with websockets_client_connect(
452457
ws_uri,
453458
extra_headers=exclude_auth_headers(self.client_wrapper.get_headers()),
454459
max_size=self.DEFAULT_MAX_PAYLOAD_SIZE_BYTES,

src/hume/expression_measurement/stream/socket_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import websockets
1010
import websockets.protocol
1111

12+
try:
13+
from websockets.legacy.client import connect as websockets_client_connect # type: ignore
14+
except ImportError:
15+
from websockets import connect as websockets_client_connect # type: ignore
16+
1217
from hume.core.api_error import ApiError
1318

1419
from .stream.types.config import Config
@@ -216,7 +221,7 @@ async def connect(
216221

217222
base = self.client_wrapper.get_environment().base.replace('https://', 'wss://').replace('http://', 'ws://')
218223
try:
219-
async with websockets.connect( # type: ignore[attr-defined]
224+
async with websockets_client_connect(
220225
f"{base}/v0/stream/models",
221226
extra_headers={
222227
**exclude_auth_headers(self.client_wrapper.get_headers()),

0 commit comments

Comments
 (0)