Skip to content

Commit

Permalink
services: revert optional aiohttp.ClientSession
Browse files Browse the repository at this point in the history
  • Loading branch information
aconchillo committed Aug 2, 2024
1 parent 6376c2f commit c891168
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 53 deletions.
4 changes: 0 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
10 changes: 2 additions & 8 deletions src/pipecat/services/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()

Expand All @@ -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}"
Expand Down
10 changes: 2 additions & 8 deletions src/pipecat/services/deepgram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/pipecat/services/elevenlabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/pipecat/services/fal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
12 changes: 3 additions & 9 deletions src/pipecat/services/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
10 changes: 2 additions & 8 deletions src/pipecat/services/xtts.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ def __init__(
voice_id: str,
language: str,
base_url: str,
aiohttp_session: aiohttp.ClientSession | None = None,
aiohttp_session: aiohttp.ClientSession,
**kwargs):
super().__init__(**kwargs)

self._voice_id = voice_id
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
Expand All @@ -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
Expand Down

0 comments on commit c891168

Please sign in to comment.