-
-
Notifications
You must be signed in to change notification settings - Fork 730
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
docs: add support for mistral tool calling #467
Conversation
from instructor.function_calls import Mode | ||
|
||
client = MistralClient() | ||
new_chat = patch(create=client.chat, mode=Mode.MIST_TOOLS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new_chat = patch(create=client.chat, mode=Mode.MIST_TOOLS) | |
new_chat = patch(create=client.chat, mode=Mode.MISTRAL) |
instructor/function_calls.py
Outdated
@@ -114,7 +115,7 @@ def from_response( | |||
context=validation_context, | |||
strict=strict, | |||
) | |||
elif mode == Mode.TOOLS: | |||
elif mode == Mode.TOOLS or mode == Mode.MIST_TOOLS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode in
elif mode == Mode.TOOLS or mode == Mode.MIST_TOOLS: | |
elif mode in {Mode.TOOLS, Mode.MISTRAL_TOOLS}: |
instructor/patch.py
Outdated
@@ -116,17 +116,20 @@ def handle_response_model( | |||
if mode == Mode.FUNCTIONS: | |||
new_kwargs["functions"] = [response_model.openai_schema] # type: ignore | |||
new_kwargs["function_call"] = {"name": response_model.openai_schema["name"]} # type: ignore | |||
elif mode == Mode.TOOLS: | |||
elif mode == Mode.TOOLS or mode == Mode.MIST_TOOLS: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif mode == Mode.TOOLS or mode == Mode.MIST_TOOLS: | |
elif mode in {Mode.TOOLS, Mode.MISTRAL_TOOLS} |
instructor/function_calls.py
Outdated
@@ -15,6 +15,7 @@ class Mode(enum.Enum): | |||
FUNCTIONS: str = "function_call" | |||
PARALLEL_TOOLS: str = "parallel_tool_call" | |||
TOOLS: str = "tool_call" | |||
MIST_TOOLS: str = "mistral_tools" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MIST_TOOLS: str = "mistral_tools" | |
MISTRAL_TOOLS: str = "mistral_tools" |
from instructor.function_calls import Mode | ||
|
||
client = MistralClient() | ||
new_chat = patch(create=client.chat, mode=Mode.MIST_TOOLS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can make an example in the hub!
and update patch.md
beautiful, but no need to shorten MISTRAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me!
- Reviewed the entire pull request up to 5c9bddd
- Looked at
182
lines of code in5
files - Took 1 minute and 54 seconds to review
More info
- Skipped
0
files when reviewing. - Skipped posting
1
additional comments because they didn't meet confidence threshold of85%
.
1. examples/mistral/mistral.py:26
:
- Assessed confidence :
90%
- Grade:
0%
- Comment:
It's a good practice to end your file with a newline. Please add a newline at the end of this file. - Reasoning:
The PR author has added support for the Mistral tool calling mode in the Instructor library. The changes include modifications to thepatch.py
andfunction_calls.py
files to handle the new mode, and the creation of a new example and documentation file to demonstrate the usage of the new feature. The changes seem to be logically correct and follow the existing patterns in the codebase. However, there is a minor issue with the new example file,mistral.py
, where a newline is missing at the end of the file. This is a common convention in Python and many other languages to ensure that the file ends with a newline character. This is not a critical issue but it's a good practice to follow this convention.
Workflow ID: wflow_gPWPboCIefej40cH
Not what you expected? You can customize the content of the reviews using rules. Learn more here.
Mistral tool calling doesn't let you force the model to call a specific tool: https://docs.mistral.ai/guides/function-calling/#tool_choice
"auto": default mode. Model decides if it uses the tool or not.
"any": forces tool use.
"none": prevents tool use.
The new tool choice I added is pretty jank ngl so open to better suggestions
Summary:
This PR adds support for the Mistral tool in the Instructor library, including a new mode in the
Mode
enum, updates to the client patching process, a new example, and a detailed guide.Key points:
MISTRAL_TOOLS
, in theMode
enum infunction_calls.py
.patch.py
to handle the newMISTRAL_TOOLS
mode when patching the client.mistral.py
under theexamples/mistral
directory.mistral.md
under thedocs/hub
directory.mkdocs.yml
to include the new guide in the documentation navigation.Generated with ❤️ by ellipsis.dev