You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is especially important because HuggingFace TGI changed their API to match OpenAI's schema of having "required" as the default and "auto" be a secondary option.
This discrepancy in HuggingFace's API vs OpenAI's has caused a number of people confusion & issues and they've finally fixed it. It would be great to have this updated properly in LangChain as well.
I think the code could look something like this:
defbind_tools(
self,
tools: Sequence[Union[Dict[str, Any], Type, Callable, BaseTool]],
*,
tool_choice: Optional[
Union[dict, str, Literal["auto", "required", "none"]]
] =None,
**kwargs: Any,
) ->Runnable[LanguageModelInput, BaseMessage]:
""" ... tool_choice: Which tool to require the model to call. Must be the name of the single provided function, "auto" (default if tools are provided) to automatically determine which function to call (if any), "required" to force the LLM to determine which function to call (similar to strict), or a dict of the form: {"type": "function", "function": {"name": <<tool_name>>}}. ... """formatted_tools= [convert_to_openai_tool(tool) fortoolintools]
iftools:
ifisinstance(tool_choice, str):
iftool_choicenotin ("auto", "required", "none"):
iflen(formatted_tools) !=1:
raiseValueError(
"When specifying `tool_choice`, you must provide exactly one "f"tool. Received {len(formatted_tools)} tools."
)
else:
tool_choice= {
"type": "function",
"function": {"name": tool_choice},
}
elifisinstance(tool_choice, dict) andtool_choice!= {}:
tool_names= [ft["function"]["name"] forftinformatted_tools]
iftool_choice["function"]["name"] notintool_names:
raiseValueError(
f"Tool choice {tool_choice} was specified, but the only "f"provided tools were {tool_names}."
)
else:
raiseValueError(
f"Unrecognized tool_choice type. Expected str or dict. "f"Received: {tool_choice}"
)
kwargs["tool_choice"] =tool_choicereturnsuper().bind(tools=formatted_tools, **kwargs)
In addition, there are a few other tweaks in the class that would be helpful:
Adding tool call id and type ("tool_call_type") to tool_calls in _convert_message_to_chat_message
Alternative roles for ToolMessages. Many model tokenizer configs can only support user/assistant/user/assistant workflows even if the models can call tools
Also, for HuggingFaceEndpoints, please allow us to match HuggingFace's API spec for API keys ('-'):
huggingfacehub_api_token default shouldn't throw an error
System Info
System Information
OS: Linux
OS Version: #129-Ubuntu SMP Fri Aug 2 19:25:20 UTC 2024
Python Version: 3.11.4 (main, Jun 7 2023, 18:32:58) [GCC 10.2.1 20210110]
The text was updated successfully, but these errors were encountered:
dosubotbot
added
Ɑ: models
Related to LLMs or chat model modules
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
labels
Dec 20, 2024
Checked other resources
Example Code
The following code
Error Message and Stack Trace (if applicable)
huggingface_hub.errors.HfHubHTTPError: 422 Client Error: Unprocessable Entity for url: private_url Tool error: Tool with name required not found
Description
ChatHuggingFace should have support for the new
tool_choice
= "required" parameter from HuggingFace TGI v3.0.Docs:
https://huggingface.co/docs/text-generation-inference/basic_tutorials/using_guidance#tool-choice-configuration
This is especially important because HuggingFace TGI changed their API to match OpenAI's schema of having "required" as the default and "auto" be a secondary option.
This discrepancy in HuggingFace's API vs OpenAI's has caused a number of people confusion & issues and they've finally fixed it. It would be great to have this updated properly in LangChain as well.
I think the code could look something like this:
In addition, there are a few other tweaks in the class that would be helpful:
Also, for HuggingFaceEndpoints, please allow us to match HuggingFace's API spec for API keys ('-'):
System Info
System Information
Package Information
The text was updated successfully, but these errors were encountered: