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

docs: add support for mistral tool calling #467

Merged
merged 4 commits into from
Feb 26, 2024
Merged

Conversation

shanktt
Copy link
Contributor

@shanktt shanktt commented Feb 26, 2024

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


Ellipsis 🚀 This PR description was created by Ellipsis for commit 5c9bddd.

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:

  • Added a new mode, MISTRAL_TOOLS, in the Mode enum in function_calls.py.
  • Updated patch.py to handle the new MISTRAL_TOOLS mode when patching the client.
  • Added a new example of using the Mistral tool in mistral.py under the examples/mistral directory.
  • Added a new guide on using the Mistral tool with the Instructor library in mistral.md under the docs/hub directory.
  • Updated mkdocs.yml to include the new guide in the documentation navigation.

Generated with ❤️ by ellipsis.dev

@shanktt shanktt changed the title ... draft: Trying to add support for mistral tool calling Feb 26, 2024
from instructor.function_calls import Mode

client = MistralClient()
new_chat = patch(create=client.chat, mode=Mode.MIST_TOOLS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_chat = patch(create=client.chat, mode=Mode.MIST_TOOLS)
new_chat = patch(create=client.chat, mode=Mode.MISTRAL)

@@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode in

Suggested change
elif mode == Mode.TOOLS or mode == Mode.MIST_TOOLS:
elif mode in {Mode.TOOLS, Mode.MISTRAL_TOOLS}:

@@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif mode == Mode.TOOLS or mode == Mode.MIST_TOOLS:
elif mode in {Mode.TOOLS, Mode.MISTRAL_TOOLS}

@@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Collaborator

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

@jxnl
Copy link
Collaborator

jxnl commented Feb 26, 2024

beautiful, but no need to shorten MISTRAL

@shanktt shanktt changed the title draft: Trying to add support for mistral tool calling Add support for mistral tool calling Feb 26, 2024
@shanktt shanktt marked this pull request as ready for review February 26, 2024 17:31
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a 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 in 5 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 of 85%.
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 the patch.py and function_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.

@jxnl jxnl changed the title Add support for mistral tool calling docs: add support for mistral tool calling Feb 26, 2024
@jxnl jxnl merged commit 043a51e into instructor-ai:main Feb 26, 2024
4 of 7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants