Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tool_choice parameter does not match OpenAI API #78

Open
jackmpcollins opened this issue Mar 25, 2024 · 1 comment
Open

tool_choice parameter does not match OpenAI API #78

jackmpcollins opened this issue Mar 25, 2024 · 1 comment

Comments

@jackmpcollins
Copy link

The the Mistral docs Azure AI page links to a notebook that shows that Mistral on Azure is compatible with the openai python package https://github.com/Azure/azureml-examples/blob/main/sdk/python/foundation-models/mistral/openaisdk.ipynb Do you also intend for the Mistral-hosted API to be compatible with the openai python package?

If so, the tool_choice parameter in the API and this package needs to be updated to support choosing a specific tool. According to the openai docs the allowed options for tool_choice are "none", "auto", or {"type": "function", "function": {"name": "my_function"}}.

tool_choice
string or object

Optional
Controls which (if any) function is called by the model. none means the model will not call a function and instead generates a message. auto means the model can pick between generating a message or calling a function. Specifying a particular function via {"type": "function", "function": {"name": "my_function"}} forces the model to call that function.

none is the default when no functions are present. auto is the default if functions are present.

https://platform.openai.com/docs/api-reference/chat/create#chat-create-tool_choice

It appears that the Mistral API does not support the {"type": "function", "function": {"name": "my_function"}} format, returning error

UnprocessableEntityError: Error code: 422 - {'object': 'error', 'message': {'detail': [{'type': 'string_type', 'loc': ['body', 'tool_choice'], 'msg': 'Input should be a valid string', 'input': {'type': 'function', 'function': {'name': 'return_list_of_str'}}, 'url': 'https://errors.pydantic.dev/2.6/v/string_type'}]}, 'type': 'invalid_request_error', 'param': None, 'code': None}

This package shows just the string options (with additional "any")

class ToolChoice(str, Enum):
auto: str = "auto"
any: str = "any"
none: str = "none"

While the openai python package includes the option for a specific tool

https://github.com/openai/openai-python/blob/5cfb125acce0e8304d12bdd39b405071021db658/src/openai/types/chat/chat_completion_tool_choice_option_param.py#L12

Lack of support for tool_choice in the Mistral API makes it incompatible with the openai python package, which means tools like https://github.com/jackmpcollins/magentic have to add custom support for it.

@mnicstruwig
Copy link

mnicstruwig commented Apr 2, 2024

Gently bumping this, since there hasn't been a response from the maintainers, and this is a blocker for us in adopting / evaluating Mistral.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants