diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff842b1f..0fe52e1da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ stt = DeepgramSTTService(..., live_options=LiveOptions(model="nova-2-general")) ### Fixed +- Fixed an issue that `start_callback` was not invoked for some LLM services. + - Fixed an issue that would cause `DeepgramSTTService` to stop working after an error occurred (e.g. sudden network loss). If the network recovered we would not reconnect. diff --git a/examples/foundational/14e-function-calling-gemini.py b/examples/foundational/14e-function-calling-gemini.py index a05ad7f75..ad5d82b6a 100644 --- a/examples/foundational/14e-function-calling-gemini.py +++ b/examples/foundational/14e-function-calling-gemini.py @@ -14,6 +14,7 @@ from loguru import logger from runner import configure from pipecat.audio.vad.silero import SileroVADAnalyzer +from pipecat.frames.frames import TTSSpeakFrame from pipecat.pipeline.pipeline import Pipeline from pipecat.pipeline.runner import PipelineRunner from pipecat.pipeline.task import PipelineParams, PipelineTask @@ -30,6 +31,12 @@ logger.add(sys.stderr, level="DEBUG") video_participant_id = None +async def start_fetch_weather(function_name, llm, context): + """Push a frame to the LLM; this is handy when the LLM response might take a while.""" + await llm.push_frame(TTSSpeakFrame("Let me check on that.")) + logger.debug(f"Starting fetch_weather_from_api with function_name: {function_name}") + + async def get_weather(function_name, tool_call_id, arguments, llm, context, result_callback): location = arguments["location"] await result_callback(f"The weather in {location} is currently 72 degrees and sunny.") @@ -63,7 +70,7 @@ async def main(): ) llm = GoogleLLMService(api_key=os.getenv("GOOGLE_API_KEY"), model="gemini-2.0-flash-001") - llm.register_function("get_weather", get_weather) + llm.register_function("get_weather", get_weather, start_fetch_weather) llm.register_function("get_image", get_image) tools = [ diff --git a/src/pipecat/services/ai_services.py b/src/pipecat/services/ai_services.py index c5adc89e0..6b739163a 100644 --- a/src/pipecat/services/ai_services.py +++ b/src/pipecat/services/ai_services.py @@ -175,6 +175,7 @@ class LLMService(AIService): f = self._callbacks[None] else: return None + await self.call_start_function(context, function_name) await context.call_function( f, function_name=function_name, diff --git a/src/pipecat/services/openai.py b/src/pipecat/services/openai.py index 3114b6920..15c1a197a 100644 --- a/src/pipecat/services/openai.py +++ b/src/pipecat/services/openai.py @@ -266,7 +266,6 @@ class BaseOpenAILLMService(LLMService): if tool_call.function and tool_call.function.name: function_name += tool_call.function.name tool_call_id = tool_call.id - await self.call_start_function(context, function_name) if tool_call.function and tool_call.function.arguments: # Keep iterating through the response to collect all the argument fragments arguments += tool_call.function.arguments