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

mistral: read tool calls from AIMessage #20554

Merged
merged 10 commits into from
Apr 17, 2024
Merged

mistral: read tool calls from AIMessage #20554

merged 10 commits into from
Apr 17, 2024

Conversation

ccurme
Copy link
Collaborator

@ccurme ccurme commented Apr 17, 2024

No description provided.

@efriis efriis added the partner label Apr 17, 2024
@efriis efriis self-assigned this Apr 17, 2024
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 17, 2024
Copy link

vercel bot commented Apr 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Apr 17, 2024 3:16pm

@dosubot dosubot bot added the 🤖:improvement Medium size change to existing code to handle new use-cases label Apr 17, 2024
@eyurtsev eyurtsev self-requested a review April 17, 2024 14:13
libs/partners/mistralai/langchain_mistralai/chat_models.py Outdated Show resolved Hide resolved
@@ -216,8 +247,15 @@ def _convert_message_to_mistral_chat_message(
if _id := tc.get("id"):
chunk["id"] = _id
tool_calls.append(chunk)
elif message.tool_calls or message.invalid_tool_calls:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be prioritized over additional_kwargs? The latter should be the source of truth if swapping providers etc

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm open to either. I actually implemented it that way first, but it introduces small issues with casting to/from Mistral dicts, since the additional_kwargs contain (1) information on order of tool calls (we lose that with the separation into valid and invalid tool call lists), and (2) JSON formatting, since we parse and then dumps the args. Our unit tests maintain that we can go back/forth so I wasn't sure if we wanted to lose that. These are small issues; if we think there's a compensating benefit to prioritizing .tool_calls then happy to change it.

Copy link
Collaborator Author

@ccurme ccurme Apr 17, 2024

Choose a reason for hiding this comment

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

ah yeah if we have a provider that (1) formats tool_calls into additional_kwargs, and (2) does not use OpenAI-style formatting then this will break. updated this. see changes to unit tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@efriis see above - is it OK to lose the behavior maintained in unit tests, in which applying _convert_message_to_mistral_chat_message and _convert_mistral_chat_message_to_message returns the original message identically?

@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Apr 17, 2024
@ccurme ccurme merged commit 4a17951 into master Apr 17, 2024
29 of 31 checks passed
@ccurme ccurme deleted the cc/update_mistral branch April 17, 2024 17:38
hinthornw pushed a commit that referenced this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. partner size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants