Simplify _connect_websocket guard and remove unused State import

This commit is contained in:
Paul Kompfner
2026-03-30 22:32:08 -04:00
parent 712e42533d
commit 04882f6f2a

View File

@@ -54,7 +54,6 @@ from pipecat.utils.tracing.service_decorators import traced_llm
try: try:
from websockets.asyncio.client import connect as websocket_connect from websockets.asyncio.client import connect as websocket_connect
from websockets.exceptions import ConnectionClosed from websockets.exceptions import ConnectionClosed
from websockets.protocol import State
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
logger.error(f"Exception: {e}") logger.error(f"Exception: {e}")
logger.error("In order to use OpenAI, you need to `pip install pipecat-ai[openai]`.") logger.error("In order to use OpenAI, you need to `pip install pipecat-ai[openai]`.")
@@ -404,7 +403,7 @@ class OpenAIResponsesLLMService(_BaseOpenAIResponsesLLMService, WebsocketLLMServ
async def _connect_websocket(self): async def _connect_websocket(self):
"""Establish the WebSocket connection.""" """Establish the WebSocket connection."""
try: try:
if self._websocket and self._websocket.state is not State.CLOSED: if self._websocket:
return return
self._websocket = await websocket_connect( self._websocket = await websocket_connect(
uri=self._ws_url, uri=self._ws_url,