Skip to content

Commit

Permalink
Use the tool with the highest similarity instead of the first one ove…
Browse files Browse the repository at this point in the history
…r 75% (#3100)
  • Loading branch information
someone13574 authored May 10, 2023
1 parent 4c2e484 commit e662a8a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions inference/worker/chat_chain_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,13 @@ def prepare_json(json_str: str) -> str:


def use_tool(tool_name: str, tool_input: str, tools: list) -> str:
for tool in tools:
# This should become stricter and stricter as we get better models
if tool.name in tool_name or similarity(tool.name, tool_name) > 0.75:
# check if tool_input is valid json, and if not, try to fix it
tool_input = prepare_json(tool_input)
return tool.func(tool_input)
best_match, best_similarity = max(
((tool, similarity(tool.name, tool_name)) for tool in tools), key=lambda x: x[1], default=(None, 0)
)
# This should become stricter and stricter as we get better models
if best_match is not None and best_similarity > 0.75:
tool_input = prepare_json(tool_input)
return best_match.func(tool_input)
return f"ERROR! {tool_name} is not a valid tool. Try again with different tool!"


Expand Down

0 comments on commit e662a8a

Please sign in to comment.