Refactored on_function_calls_cancelled to use FunctionCallFromLLM.
This commit is contained in:
@@ -141,8 +141,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@llm.event_handler("on_function_calls_cancelled")
|
@llm.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls):
|
||||||
for item in cancelled:
|
for item in function_calls:
|
||||||
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
||||||
|
|
||||||
location_function = FunctionSchema(
|
location_function = FunctionSchema(
|
||||||
|
|||||||
@@ -94,8 +94,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
llm.register_function("get_restaurant_recommendation", fetch_restaurant_recommendation)
|
llm.register_function("get_restaurant_recommendation", fetch_restaurant_recommendation)
|
||||||
|
|
||||||
@llm.event_handler("on_function_calls_cancelled")
|
@llm.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls):
|
||||||
for item in cancelled:
|
for item in function_calls:
|
||||||
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
||||||
|
|
||||||
weather_function = FunctionSchema(
|
weather_function = FunctionSchema(
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
await tts.queue_frame(TTSSpeakFrame("Sure, tracking your location now."))
|
await tts.queue_frame(TTSSpeakFrame("Sure, tracking your location now."))
|
||||||
|
|
||||||
@llm.event_handler("on_function_calls_cancelled")
|
@llm.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls):
|
||||||
for item in cancelled:
|
for item in function_calls:
|
||||||
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
||||||
|
|
||||||
location_function = FunctionSchema(
|
location_function = FunctionSchema(
|
||||||
|
|||||||
@@ -142,8 +142,8 @@ indicate you should use the get_image tool are:
|
|||||||
await tts.queue_frame(TTSSpeakFrame("Let me check on that."))
|
await tts.queue_frame(TTSSpeakFrame("Let me check on that."))
|
||||||
|
|
||||||
@llm.event_handler("on_function_calls_cancelled")
|
@llm.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls):
|
||||||
for item in cancelled:
|
for item in function_calls:
|
||||||
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
||||||
|
|
||||||
weather_function = FunctionSchema(
|
weather_function = FunctionSchema(
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
await tts.queue_frame(TTSSpeakFrame("Sure, tracking your location now."))
|
await tts.queue_frame(TTSSpeakFrame("Sure, tracking your location now."))
|
||||||
|
|
||||||
@llm.event_handler("on_function_calls_cancelled")
|
@llm.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls):
|
||||||
for item in cancelled:
|
for item in function_calls:
|
||||||
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
||||||
|
|
||||||
location_function = FunctionSchema(
|
location_function = FunctionSchema(
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
await tts.queue_frame(TTSSpeakFrame("Let me check on that."))
|
await tts.queue_frame(TTSSpeakFrame("Let me check on that."))
|
||||||
|
|
||||||
@llm.event_handler("on_function_calls_cancelled")
|
@llm.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls):
|
||||||
for item in cancelled:
|
for item in function_calls:
|
||||||
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
||||||
|
|
||||||
weather_function = FunctionSchema(
|
weather_function = FunctionSchema(
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
await tts.queue_frame(TTSSpeakFrame("Sure, tracking your location now."))
|
await tts.queue_frame(TTSSpeakFrame("Sure, tracking your location now."))
|
||||||
|
|
||||||
@llm.event_handler("on_function_calls_cancelled")
|
@llm.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls):
|
||||||
for item in cancelled:
|
for item in function_calls:
|
||||||
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
||||||
|
|
||||||
location_function = FunctionSchema(
|
location_function = FunctionSchema(
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
await tts.queue_frame(TTSSpeakFrame("Let me check on that.", append_to_context=False))
|
await tts.queue_frame(TTSSpeakFrame("Let me check on that.", append_to_context=False))
|
||||||
|
|
||||||
@llm.event_handler("on_function_calls_cancelled")
|
@llm.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls):
|
||||||
for item in cancelled:
|
for item in function_calls:
|
||||||
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
logger.info(f"Function call cancelled: {item.function_name} [{item.tool_call_id}]")
|
||||||
|
|
||||||
weather_function = FunctionSchema(
|
weather_function = FunctionSchema(
|
||||||
|
|||||||
@@ -195,12 +195,12 @@ class LLMService(UserTurnCompletionLLMServiceMixin, AIService):
|
|||||||
logger.warning("LLM completion timed out")
|
logger.warning("LLM completion timed out")
|
||||||
|
|
||||||
@task.event_handler("on_function_calls_started")
|
@task.event_handler("on_function_calls_started")
|
||||||
async def on_function_calls_started(service, function_calls):
|
async def on_function_calls_started(service, function_calls: List[FunctionCallFromLLM]):
|
||||||
logger.info(f"Starting {len(function_calls)} function calls")
|
logger.info(f"Starting {len(function_calls)} function calls")
|
||||||
|
|
||||||
@task.event_handler("on_function_calls_cancelled")
|
@task.event_handler("on_function_calls_cancelled")
|
||||||
async def on_function_calls_cancelled(service, cancelled):
|
async def on_function_calls_cancelled(service, function_calls: List[FunctionCallFromLLM]):
|
||||||
logger.info(f"Cancelled {len(cancelled)} async function calls")
|
logger.info(f"Cancelled {len(function_calls)} function calls")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_settings: LLMSettings
|
_settings: LLMSettings
|
||||||
@@ -987,7 +987,14 @@ class LLMService(UserTurnCompletionLLMServiceMixin, AIService):
|
|||||||
FunctionCallCancelFrame, function_name=name, tool_call_id=tool_call_id
|
FunctionCallCancelFrame, function_name=name, tool_call_id=tool_call_id
|
||||||
)
|
)
|
||||||
|
|
||||||
cancelled_items.append(runner_item)
|
cancelled_items.append(
|
||||||
|
FunctionCallFromLLM(
|
||||||
|
function_name=runner_item.function_name,
|
||||||
|
tool_call_id=runner_item.tool_call_id,
|
||||||
|
arguments=runner_item.arguments,
|
||||||
|
context=runner_item.context,
|
||||||
|
)
|
||||||
|
)
|
||||||
logger.debug(f"{self} Async function call [{name}:{tool_call_id}] cancelled")
|
logger.debug(f"{self} Async function call [{name}:{tool_call_id}] cancelled")
|
||||||
|
|
||||||
for task in cancelled_tasks:
|
for task in cancelled_tasks:
|
||||||
@@ -1018,7 +1025,14 @@ class LLMService(UserTurnCompletionLLMServiceMixin, AIService):
|
|||||||
FunctionCallCancelFrame, function_name=name, tool_call_id=tool_call_id
|
FunctionCallCancelFrame, function_name=name, tool_call_id=tool_call_id
|
||||||
)
|
)
|
||||||
|
|
||||||
cancelled_items.append(runner_item)
|
cancelled_items.append(
|
||||||
|
FunctionCallFromLLM(
|
||||||
|
function_name=runner_item.function_name,
|
||||||
|
tool_call_id=runner_item.tool_call_id,
|
||||||
|
arguments=runner_item.arguments,
|
||||||
|
context=runner_item.context,
|
||||||
|
)
|
||||||
|
)
|
||||||
logger.debug(f"{self} Function call [{name}:{tool_call_id}] has been cancelled")
|
logger.debug(f"{self} Function call [{name}:{tool_call_id}] has been cancelled")
|
||||||
|
|
||||||
# Remove all cancelled tasks from our set.
|
# Remove all cancelled tasks from our set.
|
||||||
|
|||||||
Reference in New Issue
Block a user