This commit is contained in:
Chester Curme 2025-04-25 14:57:52 -04:00
parent 97a0431874
commit 36db3212a9

View File

@ -359,18 +359,20 @@ class ChatLlamaCpp(BaseChatModel):
f"provided tools were {tool_names}." f"provided tools were {tool_names}."
) )
elif isinstance(tool_choice, str): elif isinstance(tool_choice, str):
if tool_choice == 'any': if tool_choice == "any":
if len(formatted_tools) == 1: if len(formatted_tools) == 1:
tool_choice = formatted_tools[0] tool_choice = formatted_tools[0]
else: else:
raise ValueError( raise ValueError(
"tool_choice `'any'` only supported if one tool is provided." "tool_choice `'any'` only supported if one tool is provided."
) )
elif tool_choice == 'auto': elif tool_choice == "auto":
tool_choice = None tool_choice = None
else: else:
chosen = [ chosen = [
f for f in formatted_tools if f["function"]["name"] == tool_choice f
for f in formatted_tools
if f["function"]["name"] == tool_choice
] ]
if not chosen: if not chosen:
raise ValueError( raise ValueError(