From dc4a29a97c13df9c99c0e9703ccd9033b795ab26 Mon Sep 17 00:00:00 2001 From: "Lennart J. Kurzweg (Nx2)" Date: Fri, 30 Aug 2024 18:09:16 +0200 Subject: [PATCH] otca unkown tool fix --- libs/runnables.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/runnables.py b/libs/runnables.py index b6cec9d..f0dca65 100644 --- a/libs/runnables.py +++ b/libs/runnables.py @@ -82,8 +82,12 @@ def one_tool_call_answer(model: Model, seed: int, test: Test, technique: Techniq assert isinstance(ai_msg, AIMessage) calls = ai_msg.tool_calls for call in calls: - selected_tool = tools_dict[call["name"].lower()] - tool_msg = selected_tool.invoke(call) + try: + selected_tool = tools_dict[call["name"].lower()] + tool_msg = selected_tool.invoke(call) + except KeyError: + tool_msg = SystemMessage(f"Tool '{call['name'].lower()}' does not exist. Available are {tools_dict.keys()}") + messages.append(tool_msg) ai_msg = llm.invoke(messages) i = 0