Added check for unknown tool names (#1924)

* answer.py

* Let it continue if broken
This commit is contained in:
hagen-danswer 2024-07-24 17:19:08 -07:00 committed by GitHub
parent 546bfbd24b
commit a4d71e08aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -240,9 +240,22 @@ class Answer:
# if we have a tool call, we need to call the tool
tool_call_requests = tool_call_chunk.tool_calls
for tool_call_request in tool_call_requests:
tool = [
known_tools_by_name = [
tool for tool in self.tools if tool.name == tool_call_request["name"]
][0]
]
if not known_tools_by_name:
logger.error(
"Tool call requested with unknown name field. \n"
f"self.tools: {self.tools}"
f"tool_call_request: {tool_call_request}"
)
if self.tools:
tool = self.tools[0]
else:
continue
else:
tool = known_tools_by_name[0]
tool_args = (
self.force_use_tool.args
if self.force_use_tool.tool_name == tool.name