diff --git a/CHANGELOG.md b/CHANGELOG.md index 70d8947b7..768c9b38f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,10 +17,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- A few services required an `aiohttp.ClientSession` to be passed to the - constructor. This is now option an a new session will be created if none is - given. - - `BotSpeakingFrame` is now a control frame. - `StartFrame` is now a control frame similar to `EndFrame`. diff --git a/src/pipecat/services/azure.py b/src/pipecat/services/azure.py index 17ec34051..24de2d5b2 100644 --- a/src/pipecat/services/azure.py +++ b/src/pipecat/services/azure.py @@ -175,8 +175,8 @@ def __init__( api_key: str, endpoint: str, model: str, + aiohttp_session: aiohttp.ClientSession, api_version="2023-06-01-preview", - aiohttp_session: aiohttp.ClientSession | None = None, ): super().__init__() @@ -185,13 +185,7 @@ def __init__( self._api_version = api_version self._model = model self._image_size = image_size - self._aiohttp_session = aiohttp_session or aiohttp.ClientSession() - self._close_aiohttp_session = aiohttp_session is None - - async def cleanup(self): - await super().cleanup() - if self._close_aiohttp_session: - await self._aiohttp_session.close() + self._aiohttp_session = aiohttp_session async def run_image_gen(self, prompt: str) -> AsyncGenerator[Frame, None]: url = f"{self._azure_endpoint}openai/images/generations:submit?api-version={self._api_version}" diff --git a/src/pipecat/services/deepgram.py b/src/pipecat/services/deepgram.py index 1cc69ca5a..05e05f074 100644 --- a/src/pipecat/services/deepgram.py +++ b/src/pipecat/services/deepgram.py @@ -46,11 +46,11 @@ def __init__( self, *, api_key: str, + aiohttp_session: aiohttp.ClientSession, voice: str = "aura-helios-en", base_url: str = "https://api.deepgram.com/v1/speak", sample_rate: int = 16000, encoding: str = "linear16", - aiohttp_session: aiohttp.ClientSession | None = None, **kwargs): super().__init__(**kwargs) @@ -59,17 +59,11 @@ def __init__( self._base_url = base_url self._sample_rate = sample_rate self._encoding = encoding - self._aiohttp_session = aiohttp_session or aiohttp.ClientSession() - self._close_aiohttp_session = aiohttp_session is None + self._aiohttp_session = aiohttp_session def can_generate_metrics(self) -> bool: return True - async def cleanup(self): - await super().cleanup() - if self._close_aiohttp_session: - await self._aiohttp_session.close() - async def set_voice(self, voice: str): logger.debug(f"Switching TTS voice to: [{voice}]") self._voice = voice diff --git a/src/pipecat/services/elevenlabs.py b/src/pipecat/services/elevenlabs.py index b81773346..798de2973 100644 --- a/src/pipecat/services/elevenlabs.py +++ b/src/pipecat/services/elevenlabs.py @@ -21,25 +21,19 @@ def __init__( *, api_key: str, voice_id: str, + aiohttp_session: aiohttp.ClientSession, model: str = "eleven_turbo_v2", - aiohttp_session: aiohttp.ClientSession | None = None, **kwargs): super().__init__(**kwargs) self._api_key = api_key self._voice_id = voice_id self._model = model - self._aiohttp_session = aiohttp_session or aiohttp.ClientSession() - self._close_aiohttp_session = aiohttp_session is None + self._aiohttp_session = aiohttp_session def can_generate_metrics(self) -> bool: return True - async def cleanup(self): - await super().cleanup() - if self._close_aiohttp_session: - await self._aiohttp_session.close() - async def set_voice(self, voice: str): logger.debug(f"Switching TTS voice to: [{voice}]") self._voice_id = voice diff --git a/src/pipecat/services/fal.py b/src/pipecat/services/fal.py index f4811e4d5..4d99f6066 100644 --- a/src/pipecat/services/fal.py +++ b/src/pipecat/services/fal.py @@ -40,23 +40,17 @@ def __init__( self, *, params: InputParams, + aiohttp_session: aiohttp.ClientSession, model: str = "fal-ai/fast-sdxl", key: str | None = None, - aiohttp_session: aiohttp.ClientSession | None = None, ): super().__init__() self._model = model self._params = params - self._aiohttp_session = aiohttp_session or aiohttp.ClientSession() - self._close_aiohttp_session = aiohttp_session is None + self._aiohttp_session = aiohttp_session if key: os.environ["FAL_KEY"] = key - async def cleanup(self): - await super().cleanup() - if self._close_aiohttp_session: - await self._aiohttp_session.close() - async def run_image_gen(self, prompt: str) -> AsyncGenerator[Frame, None]: logger.debug(f"Generating image from prompt: {prompt}") diff --git a/src/pipecat/services/openai.py b/src/pipecat/services/openai.py index 574021273..e3113ae8b 100644 --- a/src/pipecat/services/openai.py +++ b/src/pipecat/services/openai.py @@ -254,21 +254,15 @@ def __init__( self, *, api_key: str, - model: str = "dall-e-3", + aiohttp_session: aiohttp.ClientSession, image_size: Literal["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"], - aiohttp_session: aiohttp.ClientSession | None = None, + model: str = "dall-e-3", ): super().__init__() self._model = model self._image_size = image_size self._client = AsyncOpenAI(api_key=api_key) - self._aiohttp_session = aiohttp_session or aiohttp.ClientSession() - self._close_aiohttp_session = aiohttp_session is None - - async def cleanup(self): - await super().cleanup() - if self._close_aiohttp_session: - await self._aiohttp_session.close() + self._aiohttp_session = aiohttp_session async def run_image_gen(self, prompt: str) -> AsyncGenerator[Frame, None]: logger.debug(f"Generating image from prompt: {prompt}") diff --git a/src/pipecat/services/xtts.py b/src/pipecat/services/xtts.py index d69f013b7..151a48e74 100644 --- a/src/pipecat/services/xtts.py +++ b/src/pipecat/services/xtts.py @@ -39,7 +39,7 @@ def __init__( voice_id: str, language: str, base_url: str, - aiohttp_session: aiohttp.ClientSession | None = None, + aiohttp_session: aiohttp.ClientSession, **kwargs): super().__init__(**kwargs) @@ -47,8 +47,7 @@ def __init__( self._language = language self._base_url = base_url self._studio_speakers: Dict[str, Any] | None = None - self._aiohttp_session = aiohttp_session or aiohttp.ClientSession() - self._close_aiohttp_session = aiohttp_session is None + self._aiohttp_session = aiohttp_session def can_generate_metrics(self) -> bool: return True @@ -65,11 +64,6 @@ async def start(self, frame: StartFrame): return self._studio_speakers = await r.json() - async def cleanup(self): - await super().cleanup() - if self._close_aiohttp_session: - await self._aiohttp_session.close() - async def set_voice(self, voice: str): logger.debug(f"Switching TTS voice to: [{voice}]") self._voice_id = voice