From f3a4e5499615ceab493aa9f76e70f7a3cc2dd99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Sun, 18 Aug 2024 20:48:20 -0700 Subject: [PATCH] function calling: start callback should have function name first --- examples/foundational/14-function-calling.py | 2 +- examples/patient-intake/bot.py | 8 ++++---- src/pipecat/processors/frameworks/rtvi.py | 4 ++-- src/pipecat/services/ai_services.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/foundational/14-function-calling.py b/examples/foundational/14-function-calling.py index 66c3f4219..1cdd364c6 100644 --- a/examples/foundational/14-function-calling.py +++ b/examples/foundational/14-function-calling.py @@ -32,7 +32,7 @@ logger.remove(0) logger.add(sys.stderr, level="DEBUG") -async def start_fetch_weather(llm, context, function_name): +async def start_fetch_weather(function_name, llm, context): await llm.push_frame(TextFrame("Let me check on that.")) diff --git a/examples/patient-intake/bot.py b/examples/patient-intake/bot.py index 3cf65e95c..bfa1de9b8 100644 --- a/examples/patient-intake/bot.py +++ b/examples/patient-intake/bot.py @@ -122,7 +122,7 @@ class IntakeProcessor: # The user provided an incorrect birthday; ask them to try again await result_callback([{"role": "system", "content": "The user provided an incorrect birthday. Ask them for their birthday again. When they answer, call the verify_birthday function."}]) - async def start_prescriptions(self, llm, context, function_name): + async def start_prescriptions(self, function_name, llm, context): print(f"!!! doing start prescriptions") # Move on to allergies context.set_tools( @@ -157,7 +157,7 @@ class IntakeProcessor: await llm.process_frame(OpenAILLMContextFrame(context), FrameDirection.DOWNSTREAM) print(f"!!! past await process frame in start prescriptions") - async def start_allergies(self, llm, context, function_name): + async def start_allergies(self, function_name, llm, context): print("!!! doing start allergies") # Move on to conditions context.set_tools( @@ -191,7 +191,7 @@ class IntakeProcessor: "content": "Now ask the user if they have any medical conditions the doctor should know about. Once they've answered the question, call the list_conditions function."}) await llm.process_frame(OpenAILLMContextFrame(context), FrameDirection.DOWNSTREAM) - async def start_conditions(self, llm, context, function_name): + async def start_conditions(self, function_name, llm, context): print("!!! doing start conditions") # Move on to visit reasons context.set_tools( @@ -224,7 +224,7 @@ class IntakeProcessor: "content": "Finally, ask the user the reason for their doctor visit today. Once they answer, call the list_visit_reasons function."}) await llm.process_frame(OpenAILLMContextFrame(context), FrameDirection.DOWNSTREAM) - async def start_visit_reasons(self, llm, context, function_name): + async def start_visit_reasons(self, function_name, llm, context): print("!!! doing start visit reasons") # move to finish call context.set_tools([]) diff --git a/src/pipecat/processors/frameworks/rtvi.py b/src/pipecat/processors/frameworks/rtvi.py index 01bc6947a..0e8822486 100644 --- a/src/pipecat/processors/frameworks/rtvi.py +++ b/src/pipecat/processors/frameworks/rtvi.py @@ -323,9 +323,9 @@ class RTVIProcessor(FrameProcessor): async def handle_function_call_start( self, + function_name: str, llm: FrameProcessor, - context: OpenAILLMContext, - function_name: str): + context: OpenAILLMContext): fn = RTVILLMFunctionCallStartMessageData(function_name=function_name) message = RTVILLMFunctionCallStartMessage(data=fn) await self._push_transport_message(message, exclude_none=False) diff --git a/src/pipecat/services/ai_services.py b/src/pipecat/services/ai_services.py index a4e9fd4d6..197a73bac 100644 --- a/src/pipecat/services/ai_services.py +++ b/src/pipecat/services/ai_services.py @@ -140,9 +140,9 @@ class LLMService(AIService): # QUESTION FOR CB: maybe this isn't needed anymore? async def call_start_function(self, context: OpenAILLMContext, function_name: str): if function_name in self._start_callbacks.keys(): - await self._start_callbacks[function_name](self, context, function_name) + await self._start_callbacks[function_name](function_name, self, context) elif None in self._start_callbacks.keys(): - return await self._start_callbacks[None](self, context, function_name) + return await self._start_callbacks[None](function_name, self, context) async def request_image_frame(self, user_id: str, *, text_content: str | None = None): await self.push_frame(UserImageRequestFrame(user_id=user_id, context=text_content),