Skip to content

Commit

Permalink
chore: Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTom101 committed Jun 3, 2024
1 parent 7085b1e commit d462c03
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/pipecat/services/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,39 @@
from loguru import logger
from PIL import Image

from pipecat.frames.frames import (AudioRawFrame, ErrorFrame, Frame,
LLMFullResponseEndFrame,
LLMFullResponseStartFrame, LLMMessagesFrame,
LLMResponseEndFrame, LLMResponseStartFrame,
TextFrame, URLImageRawFrame,
VisionImageRawFrame)
from pipecat.frames.frames import (
AudioRawFrame,
ErrorFrame,
Frame,
LLMFullResponseEndFrame,
LLMFullResponseStartFrame,
LLMMessagesFrame,
LLMResponseEndFrame,
LLMResponseStartFrame,
TextFrame,
URLImageRawFrame,
VisionImageRawFrame
)
from pipecat.processors.aggregators.openai_llm_context import (
OpenAILLMContext, OpenAILLMContextFrame)
OpenAILLMContext,
OpenAILLMContextFrame
)
from pipecat.processors.frame_processor import FrameDirection
from pipecat.services.ai_services import (ImageGenService, LLMService,
TTSService)
from pipecat.services.ai_services import (
ImageGenService,
LLMService,
TTSService
)

try:
from openai import AsyncOpenAI, AsyncStream, BadRequestError
from openai.types.chat import (ChatCompletion, ChatCompletionChunk,
ChatCompletionFunctionMessageParam,
ChatCompletionMessageParam,
ChatCompletionToolParam)
from openai.types.chat import (
ChatCompletion,
ChatCompletionChunk,
ChatCompletionFunctionMessageParam,
ChatCompletionMessageParam,
ChatCompletionToolParam
)
except ModuleNotFoundError as e:
logger.error(f"Exception: {e}")
logger.error(
Expand Down Expand Up @@ -265,7 +280,7 @@ async def run_image_gen(self, prompt: str) -> AsyncGenerator[Frame, None]:

class OpenAITTSService(TTSService):
"""This service uses the OpenAI TTS API to generate audio from text.
The returned audio is PCM encoded at 24kHz. When using the DailyTransport, set the sample rate in the DailyParams:
The returned audio is PCM encoded at 24kHz. When using the DailyTransport, set the sample rate in the DailyParams accordingly:
```
DailyParams(
audio_out_enabled=True,
Expand Down Expand Up @@ -308,5 +323,4 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
frame = AudioRawFrame(chunk, 24_000, 1)
yield frame
except BadRequestError as e:
logger.exception(f"Error generating TTS: {e}")
raise
logger.error(f"Error generating TTS: {e}")

0 comments on commit d462c03

Please sign in to comment.