Comment out more and add more exception handling
This commit is contained in:
@@ -12,7 +12,6 @@ import asyncio
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import requests
|
import requests
|
||||||
@@ -22,10 +21,14 @@ from openai.types.chat import ChatCompletionToolParam
|
|||||||
from runner import configure
|
from runner import configure
|
||||||
|
|
||||||
from pipecat.audio.vad.silero import SileroVADAnalyzer, VADParams
|
from pipecat.audio.vad.silero import SileroVADAnalyzer, VADParams
|
||||||
from pipecat.frames.frames import (BotSpeakingFrame, EndFrame, Frame,
|
from pipecat.frames.frames import (
|
||||||
InputAudioRawFrame, LLMMessagesFrame,
|
EndFrame,
|
||||||
TextFrame, TTSAudioRawFrame,
|
Frame,
|
||||||
UserStoppedSpeakingFrame)
|
LLMMessagesFrame,
|
||||||
|
StartInterruptionFrame,
|
||||||
|
StopInterruptionFrame,
|
||||||
|
TextFrame,
|
||||||
|
)
|
||||||
from pipecat.pipeline.pipeline import Pipeline
|
from pipecat.pipeline.pipeline import Pipeline
|
||||||
from pipecat.pipeline.runner import PipelineRunner
|
from pipecat.pipeline.runner import PipelineRunner
|
||||||
from pipecat.pipeline.task import PipelineParams, PipelineTask
|
from pipecat.pipeline.task import PipelineParams, PipelineTask
|
||||||
@@ -86,14 +89,18 @@ class DebugProcessor(FrameProcessor):
|
|||||||
|
|
||||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
||||||
await super().process_frame(frame, direction)
|
await super().process_frame(frame, direction)
|
||||||
if not (
|
# if not (
|
||||||
isinstance(frame, InputAudioRawFrame)
|
# isinstance(frame, InputAudioRawFrame)
|
||||||
or isinstance(frame, BotSpeakingFrame)
|
# or isinstance(frame, BotSpeakingFrame)
|
||||||
or isinstance(frame, UserStoppedSpeakingFrame)
|
# or isinstance(frame, UserStoppedSpeakingFrame)
|
||||||
or isinstance(frame, TTSAudioRawFrame)
|
# or isinstance(frame, TTSAudioRawFrame)
|
||||||
or isinstance(frame, TextFrame)
|
# or isinstance(frame, TextFrame)
|
||||||
):
|
# ):
|
||||||
|
# logger.debug(f"--- DebugProcessor {self._name}: {frame} {direction}")
|
||||||
|
# StopInterruptionFrame
|
||||||
|
if isinstance(frame, StopInterruptionFrame) or isinstance(frame, StartInterruptionFrame):
|
||||||
logger.debug(f"--- DebugProcessor {self._name}: {frame} {direction}")
|
logger.debug(f"--- DebugProcessor {self._name}: {frame} {direction}")
|
||||||
|
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
|
|
||||||
@@ -331,17 +338,17 @@ async def main():
|
|||||||
|
|
||||||
llm = OpenAILLMService(api_key=os.environ["OPENAI_API_KEY"], model="gpt-4o")
|
llm = OpenAILLMService(api_key=os.environ["OPENAI_API_KEY"], model="gpt-4o")
|
||||||
llm.register_function("get_knowledge_base", get_knowledge_base)
|
llm.register_function("get_knowledge_base", get_knowledge_base)
|
||||||
llm.register_function(
|
# llm.register_function(
|
||||||
"end_call",
|
# "end_call",
|
||||||
partial(
|
# partial(
|
||||||
end_call,
|
# end_call,
|
||||||
transport=transport,
|
# transport=transport,
|
||||||
voice_provider="cartesia",
|
# voice_provider="cartesia",
|
||||||
voice_id="7360f116-6306-4e9a-b487-1235f35a0f21",
|
# voice_id="7360f116-6306-4e9a-b487-1235f35a0f21",
|
||||||
),
|
# ),
|
||||||
)
|
# )
|
||||||
llm.register_function("transfer_call", transfer_call)
|
# llm.register_function("transfer_call", transfer_call)
|
||||||
llm.register_function("voicemail", partial(voicemail, transport=transport))
|
# llm.register_function("voicemail", partial(voicemail, transport=transport))
|
||||||
llm.register_function("get_meeting_dates", get_meeting_dates)
|
llm.register_function("get_meeting_dates", get_meeting_dates)
|
||||||
|
|
||||||
tools = [
|
tools = [
|
||||||
@@ -374,56 +381,56 @@ async def main():
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ChatCompletionToolParam(
|
# ChatCompletionToolParam(
|
||||||
type="function",
|
# type="function",
|
||||||
function={
|
# function={
|
||||||
"name": "end_call",
|
# "name": "end_call",
|
||||||
"description": "Use this tool to end the call",
|
# "description": "Use this tool to end the call",
|
||||||
"strict": True, # type: ignore[typeddict-unknown-key]
|
# "strict": True, # type: ignore[typeddict-unknown-key]
|
||||||
"parameters": {
|
# "parameters": {
|
||||||
"type": "object",
|
# "type": "object",
|
||||||
"properties": {
|
# "properties": {
|
||||||
"end_call_sentence": {
|
# "end_call_sentence": {
|
||||||
"type": "string",
|
# "type": "string",
|
||||||
"description": "The End Call Sentence that needs to be utter by the AI",
|
# "description": "The End Call Sentence that needs to be utter by the AI",
|
||||||
}
|
# }
|
||||||
},
|
# },
|
||||||
"additionalProperties": False,
|
# "additionalProperties": False,
|
||||||
"required": ["end_call_sentence"],
|
# "required": ["end_call_sentence"],
|
||||||
},
|
# },
|
||||||
},
|
# },
|
||||||
),
|
# ),
|
||||||
ChatCompletionToolParam(
|
# ChatCompletionToolParam(
|
||||||
type="function",
|
# type="function",
|
||||||
function={
|
# function={
|
||||||
"name": "transfer_call",
|
# "name": "transfer_call",
|
||||||
"description": "Use this tool to transfer the call",
|
# "description": "Use this tool to transfer the call",
|
||||||
"strict": True, # type: ignore[typeddict-unknown-key]
|
# "strict": True, # type: ignore[typeddict-unknown-key]
|
||||||
"parameters": {
|
# "parameters": {
|
||||||
"type": "object",
|
# "type": "object",
|
||||||
"properties": {
|
# "properties": {
|
||||||
"transfer_number_sentence": {
|
# "transfer_number_sentence": {
|
||||||
"type": "string",
|
# "type": "string",
|
||||||
"description": "The sentence that AI needs to speak before transfering the call",
|
# "description": "The sentence that AI needs to speak before transfering the call",
|
||||||
},
|
# },
|
||||||
"transfer_number": {
|
# "transfer_number": {
|
||||||
"type": "string",
|
# "type": "string",
|
||||||
"description": "The number to use to which we need transfer the call",
|
# "description": "The number to use to which we need transfer the call",
|
||||||
},
|
# },
|
||||||
},
|
# },
|
||||||
"additionalProperties": False,
|
# "additionalProperties": False,
|
||||||
"required": ["transfer_number", "transfer_number_sentence"],
|
# "required": ["transfer_number", "transfer_number_sentence"],
|
||||||
},
|
# },
|
||||||
},
|
# },
|
||||||
),
|
# ),
|
||||||
ChatCompletionToolParam(
|
# ChatCompletionToolParam(
|
||||||
type="function",
|
# type="function",
|
||||||
function={
|
# function={
|
||||||
"name": "voicemail",
|
# "name": "voicemail",
|
||||||
"description": f"Use this tool if you reach voicemail. Here is some examples: {'\n'.join(VOICEMAIL_EXAMPLES)}",
|
# "description": f"Use this tool if you reach voicemail. Here is some examples: {'\n'.join(VOICEMAIL_EXAMPLES)}",
|
||||||
"parameters": {},
|
# "parameters": {},
|
||||||
},
|
# },
|
||||||
),
|
# ),
|
||||||
ChatCompletionToolParam(
|
ChatCompletionToolParam(
|
||||||
type="function",
|
type="function",
|
||||||
function={
|
function={
|
||||||
@@ -445,8 +452,8 @@ async def main():
|
|||||||
context = OpenAILLMContext(messages, tools)
|
context = OpenAILLMContext(messages, tools)
|
||||||
context_aggregator = llm.create_context_aggregator(context)
|
context_aggregator = llm.create_context_aggregator(context)
|
||||||
|
|
||||||
dp_post_llm = DebugProcessor('post_llm')
|
dp_post_llm = DebugProcessor("post_llm")
|
||||||
dp_post_tts = DebugProcessor('post_tts')
|
dp_post_tts = DebugProcessor("post_tts")
|
||||||
|
|
||||||
pipeline = Pipeline(
|
pipeline = Pipeline(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -165,7 +165,13 @@ class BaseOpenAILLMService(LLMService):
|
|||||||
|
|
||||||
params.update(self._settings["extra"])
|
params.update(self._settings["extra"])
|
||||||
|
|
||||||
chunks = await self._client.chat.completions.create(**params)
|
try:
|
||||||
|
chunks = await self._client.chat.completions.create(**params)
|
||||||
|
except aiohttp.ClientError as e:
|
||||||
|
logger.error(f"HTTP error occurred: {e}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Unexpected error occurred: {e}")
|
||||||
|
raise e
|
||||||
print(f"_____openai.py get_chat_completions * chunks: {chunks}")
|
print(f"_____openai.py get_chat_completions * chunks: {chunks}")
|
||||||
return chunks
|
return chunks
|
||||||
|
|
||||||
@@ -451,6 +457,9 @@ class OpenAITTSService(TTSService):
|
|||||||
yield TTSStoppedFrame()
|
yield TTSStoppedFrame()
|
||||||
except BadRequestError as e:
|
except BadRequestError as e:
|
||||||
logger.exception(f"{self} error generating TTS: {e}")
|
logger.exception(f"{self} error generating TTS: {e}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Unexpected error occurred in run_tts: {e}")
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
# internal use only -- todo: refactor
|
# internal use only -- todo: refactor
|
||||||
|
|||||||
Reference in New Issue
Block a user