diff --git a/examples/foundational/14d-function-calling-anthropic-video.py b/examples/foundational/14d-function-calling-anthropic-video.py index 8097ee988..c9dacaa75 100644 --- a/examples/foundational/14d-function-calling-anthropic-video.py +++ b/examples/foundational/14d-function-calling-anthropic-video.py @@ -48,14 +48,16 @@ async def fetch_user_image(params: FunctionCallParams): When called, this function pushes a UserImageRequestFrame upstream to the transport. As a result, the transport will request the user image and push a UserImageRawFrame downstream which will be added to the context by the LLM - assistant aggregator. + assistant aggregator. The result_callback will be invoked once the image is + retrieved and processed. """ user_id = params.arguments["user_id"] question = params.arguments["question"] logger.debug(f"Requesting image with user_id={user_id}, question={question}") # Request a user image frame and indicate that it should be added to the - # context. Also associate it to the function call. + # context. Also associate it to the function call. Pass the result_callback + # so it can be invoked when the image is actually retrieved. await params.llm.push_frame( UserImageRequestFrame( user_id=user_id, @@ -63,16 +65,11 @@ async def fetch_user_image(params: FunctionCallParams): append_to_context=True, function_name=params.function_name, tool_call_id=params.tool_call_id, + result_callback=params.result_callback, ), FrameDirection.UPSTREAM, ) - await params.result_callback(None) - - # Instead of None, it's possible to also provide a tool call answer to - # tell the LLM that we are grabbing the image to analyze. - # await params.result_callback({"result": "Image is being captured."}) - # We store functions so objects (e.g. SileroVADAnalyzer) don't get # instantiated. The function will be called when the desired transport gets diff --git a/examples/foundational/14d-function-calling-aws-video.py b/examples/foundational/14d-function-calling-aws-video.py index b972f4097..9faa925aa 100644 --- a/examples/foundational/14d-function-calling-aws-video.py +++ b/examples/foundational/14d-function-calling-aws-video.py @@ -48,14 +48,16 @@ async def fetch_user_image(params: FunctionCallParams): When called, this function pushes a UserImageRequestFrame upstream to the transport. As a result, the transport will request the user image and push a UserImageRawFrame downstream which will be added to the context by the LLM - assistant aggregator. + assistant aggregator. The result_callback will be invoked once the image is + retrieved and processed. """ user_id = params.arguments["user_id"] question = params.arguments["question"] logger.debug(f"Requesting image with user_id={user_id}, question={question}") # Request a user image frame and indicate that it should be added to the - # context. Also associate it to the function call. + # context. Also associate it to the function call. Pass the result_callback + # so it can be invoked when the image is actually retrieved. await params.llm.push_frame( UserImageRequestFrame( user_id=user_id, @@ -63,16 +65,11 @@ async def fetch_user_image(params: FunctionCallParams): append_to_context=True, function_name=params.function_name, tool_call_id=params.tool_call_id, + result_callback=params.result_callback, ), FrameDirection.UPSTREAM, ) - await params.result_callback(None) - - # Instead of None, it's possible to also provide a tool call answer to - # tell the LLM that we are grabbing the image to analyze. - # await params.result_callback({"result": "Image is being captured."}) - # We store functions so objects (e.g. SileroVADAnalyzer) don't get # instantiated. The function will be called when the desired transport gets diff --git a/examples/foundational/14d-function-calling-gemini-flash-video.py b/examples/foundational/14d-function-calling-gemini-flash-video.py index ba9dcd266..857eb92b6 100644 --- a/examples/foundational/14d-function-calling-gemini-flash-video.py +++ b/examples/foundational/14d-function-calling-gemini-flash-video.py @@ -48,14 +48,16 @@ async def fetch_user_image(params: FunctionCallParams): When called, this function pushes a UserImageRequestFrame upstream to the transport. As a result, the transport will request the user image and push a UserImageRawFrame downstream which will be added to the context by the LLM - assistant aggregator. + assistant aggregator. The result_callback will be invoked once the image is + retrieved and processed. """ user_id = params.arguments["user_id"] question = params.arguments["question"] logger.debug(f"Requesting image with user_id={user_id}, question={question}") # Request a user image frame and indicate that it should be added to the - # context. Also associate it to the function call. + # context. Also associate it to the function call. Pass the result_callback + # so it can be invoked when the image is actually retrieved. await params.llm.push_frame( UserImageRequestFrame( user_id=user_id, @@ -63,16 +65,11 @@ async def fetch_user_image(params: FunctionCallParams): append_to_context=True, function_name=params.function_name, tool_call_id=params.tool_call_id, + result_callback=params.result_callback, ), FrameDirection.UPSTREAM, ) - await params.result_callback(None) - - # Instead of None, it's possible to also provide a tool call answer to - # tell the LLM that we are grabbing the image to analyze. - # await params.result_callback({"result": "Image is being captured."}) - # We store functions so objects (e.g. SileroVADAnalyzer) don't get # instantiated. The function will be called when the desired transport gets diff --git a/examples/foundational/14d-function-calling-moondream-video.py b/examples/foundational/14d-function-calling-moondream-video.py index 0b10854ea..3e64d5bd8 100644 --- a/examples/foundational/14d-function-calling-moondream-video.py +++ b/examples/foundational/14d-function-calling-moondream-video.py @@ -57,7 +57,8 @@ async def fetch_user_image(params: FunctionCallParams): When called, this function pushes a UserImageRequestFrame upstream to the transport. As a result, the transport will request the user image and push a - UserImageRawFrame downstream. + UserImageRawFrame downstream. The result_callback will be invoked once the + image is retrieved and processed. """ user_id = params.arguments["user_id"] question = params.arguments["question"] @@ -65,7 +66,8 @@ async def fetch_user_image(params: FunctionCallParams): # Request a user image frame. In this case, we don't want the requested # image to be added to the context because we will process it with - # Moondream. Also associate it to the function call. + # Moondream. Also associate it to the function call. Pass the result_callback + # so it can be invoked when the image is actually retrieved. await params.llm.push_frame( UserImageRequestFrame( user_id=user_id, @@ -73,16 +75,11 @@ async def fetch_user_image(params: FunctionCallParams): append_to_context=False, function_name=params.function_name, tool_call_id=params.tool_call_id, + result_callback=params.result_callback, ), FrameDirection.UPSTREAM, ) - await params.result_callback(None) - - # Instead of None, it's possible to also provide a tool call answer to - # tell the LLM that we are grabbing the image to analyze. - # await params.result_callback({"result": "Image is being captured."}) - class MoondreamTextFrameWrapper(FrameProcessor): """Wraps Moondream-provided TextFrames with LLM response start/end frames. diff --git a/examples/foundational/14d-function-calling-openai-video.py b/examples/foundational/14d-function-calling-openai-video.py index 3afebe7bb..ec201cc3a 100644 --- a/examples/foundational/14d-function-calling-openai-video.py +++ b/examples/foundational/14d-function-calling-openai-video.py @@ -49,14 +49,16 @@ async def fetch_user_image(params: FunctionCallParams): When called, this function pushes a UserImageRequestFrame upstream to the transport. As a result, the transport will request the user image and push a UserImageRawFrame downstream which will be added to the context by the LLM - assistant aggregator. + assistant aggregator. The result_callback will be invoked once the image is + retrieved and processed. """ user_id = params.arguments["user_id"] question = params.arguments["question"] logger.debug(f"Requesting image with user_id={user_id}, question={question}") # Request a user image frame and indicate that it should be added to the - # context. Also associate it to the function call. + # context. Also associate it to the function call. Pass the result_callback + # so it can be invoked when the image is actually retrieved. await params.llm.push_frame( UserImageRequestFrame( user_id=user_id, @@ -64,16 +66,11 @@ async def fetch_user_image(params: FunctionCallParams): append_to_context=True, function_name=params.function_name, tool_call_id=params.tool_call_id, + result_callback=params.result_callback, ), FrameDirection.UPSTREAM, ) - await params.result_callback(None) - - # Instead of None, it's possible to also provide a tool call answer to - # tell the LLM that we are grabbing the image to analyze. - # await params.result_callback({"result": "Image is being captured."}) - # We store functions so objects (e.g. SileroVADAnalyzer) don't get # instantiated. The function will be called when the desired transport gets diff --git a/examples/foundational/14e-function-calling-google.py b/examples/foundational/14e-function-calling-google.py index 4e7abf997..56cdd53c1 100644 --- a/examples/foundational/14e-function-calling-google.py +++ b/examples/foundational/14e-function-calling-google.py @@ -58,14 +58,16 @@ async def get_image(params: FunctionCallParams): When called, this function pushes a UserImageRequestFrame upstream to the transport. As a result, the transport will request the user image and push a UserImageRawFrame downstream which will be added to the context by the LLM - assistant aggregator. + assistant aggregator. The result_callback will be invoked once the image is + retrieved and processed. """ user_id = params.arguments["user_id"] question = params.arguments["question"] logger.debug(f"Requesting image with user_id={user_id}, question={question}") # Request a user image frame and indicate that it should be added to the - # context. Also associate it to the function call. + # context. Also associate it to the function call. Pass the result_callback + # so it can be invoked when the image is actually retrieved. await params.llm.push_frame( UserImageRequestFrame( user_id=user_id, @@ -73,16 +75,11 @@ async def get_image(params: FunctionCallParams): append_to_context=True, function_name=params.function_name, tool_call_id=params.tool_call_id, + result_callback=params.result_callback, ), FrameDirection.UPSTREAM, ) - await params.result_callback(None) - - # Instead of None, it's possible to also provide a tool call answer to - # tell the LLM that we are grabbing the image to analyze. - # await params.result_callback({"result": "Image is being captured."}) - # We store functions so objects (e.g. SileroVADAnalyzer) don't get # instantiated. The function will be called when the desired transport gets diff --git a/examples/foundational/20d-persistent-context-gemini.py b/examples/foundational/20d-persistent-context-gemini.py index e0e2949a3..4b434c4c1 100644 --- a/examples/foundational/20d-persistent-context-gemini.py +++ b/examples/foundational/20d-persistent-context-gemini.py @@ -66,7 +66,8 @@ async def get_image(params: FunctionCallParams): logger.debug(f"Requesting image with user_id={user_id}, question={question}") # Request a user image frame and indicate that it should be added to the - # context. Also associate it to the function call. + # context. Also associate it to the function call. Pass the result_callback + # so it can be invoked when the image is actually retrieved. await params.llm.push_frame( UserImageRequestFrame( user_id=user_id, @@ -74,16 +75,11 @@ async def get_image(params: FunctionCallParams): append_to_context=True, function_name=params.function_name, tool_call_id=params.tool_call_id, + result_callback=params.result_callback, ), FrameDirection.UPSTREAM, ) - await params.result_callback(None) - - # Instead of None, it's possible to also provide a tool call answer to - # tell the LLM that we are grabbing the image to analyze. - # await params.result_callback({"result": "Image is being captured."}) - async def get_saved_conversation_filenames(params: FunctionCallParams): # Construct the full pattern including the BASE_FILENAME