Merge pull request #3343 from omChauhanDev/fix/auto-resolve-function-result
fix: keeping the Aggregator and Service states synchronized.
This commit is contained in:
@@ -595,10 +595,14 @@ class LLMService(AIService):
|
|||||||
cancel_on_interruption=item.cancel_on_interruption,
|
cancel_on_interruption=item.cancel_on_interruption,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
callback_executed = False
|
||||||
|
|
||||||
# Define a callback function that pushes a FunctionCallResultFrame upstream & downstream.
|
# Define a callback function that pushes a FunctionCallResultFrame upstream & downstream.
|
||||||
async def function_call_result_callback(
|
async def function_call_result_callback(
|
||||||
result: Any, *, properties: Optional[FunctionCallResultProperties] = None
|
result: Any, *, properties: Optional[FunctionCallResultProperties] = None
|
||||||
):
|
):
|
||||||
|
nonlocal callback_executed
|
||||||
|
callback_executed = True
|
||||||
await self.broadcast_frame(
|
await self.broadcast_frame(
|
||||||
FunctionCallResultFrame,
|
FunctionCallResultFrame,
|
||||||
function_name=runner_item.function_name,
|
function_name=runner_item.function_name,
|
||||||
@@ -609,6 +613,7 @@ class LLMService(AIService):
|
|||||||
properties=properties,
|
properties=properties,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
if isinstance(item.handler, DirectFunctionWrapper):
|
if isinstance(item.handler, DirectFunctionWrapper):
|
||||||
# Handler is a DirectFunctionWrapper
|
# Handler is a DirectFunctionWrapper
|
||||||
await item.handler.invoke(
|
await item.handler.invoke(
|
||||||
@@ -643,6 +648,13 @@ class LLMService(AIService):
|
|||||||
result_callback=function_call_result_callback,
|
result_callback=function_call_result_callback,
|
||||||
)
|
)
|
||||||
await item.handler(params)
|
await item.handler(params)
|
||||||
|
except Exception as e:
|
||||||
|
error_message = f"Error executing function call [{runner_item.function_name}]: {e}"
|
||||||
|
logger.error(f"{self} {error_message}")
|
||||||
|
await self.push_error(error_msg=error_message, exception=e, fatal=False)
|
||||||
|
finally:
|
||||||
|
if not callback_executed:
|
||||||
|
await function_call_result_callback(None)
|
||||||
|
|
||||||
async def _cancel_function_call(self, function_name: Optional[str]):
|
async def _cancel_function_call(self, function_name: Optional[str]):
|
||||||
cancelled_tasks = set()
|
cancelled_tasks = set()
|
||||||
|
|||||||
Reference in New Issue
Block a user