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

ChatMistralAI with chat history : Assistant message must have either content or tool_calls error #21196

Closed
5 tasks done
maximeperrindev opened this issue May 2, 2024 · 4 comments · Fixed by #21201
Closed
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: mistralai Primarily related to MistralAI integrations Ɑ: Tool Calling Related to Tool Calling

Comments

@maximeperrindev
Copy link
Contributor

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

Error Message and Stack Trace (if applicable)

httpx.HTTPStatusError: Error response 400 while fetching https://api.mistral.ai/v1/chat/completions: {"object":"error","message":"Assistant message must have either content or tool_calls, but not both.","type":"invalid_request_error","param":null,"code":null}

Description

I'm trying to send a chat completion request to MistralAI API. However, when I send multiple messages with a chat history persitence, the api returns an error saying that it is impossible to include tool_calls AND content in the request.

It is probably related to _convert_message_to_mistral_chat_message in the chat_models.py in langchain_mistrail package.
We shouldn't the tool_calls variable if it is empty or we shouldn't return the content variable if we're using tools.

I am going to fix this with a PR asap

System Info

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label May 2, 2024
@eyurtsev eyurtsev added 🔌: mistralai Primarily related to MistralAI integrations Ɑ: Tool Calling Related to Tool Calling labels May 2, 2024
maximeperrindev pushed a commit to maximeperrindev/langchain that referenced this issue May 2, 2024
ccurme added a commit that referenced this issue May 2, 2024
…using tool_calls or content) (#21201)

This PR fixes #21196.

The error was occurring when calling chat completion API with a chat
history. Indeed, the Mistral API does not accept both `content` and
`tool_calls` in the same body.

This PR removes one of theses variables depending on the necessity.

---------

Co-authored-by: Maxime Perrin <mperrin@doing.fr>
Co-authored-by: Chester Curme <chester.curme@gmail.com>
@ccurme
Copy link
Collaborator

ccurme commented May 2, 2024

This was patched in langchain-mistralai==0.1.6, please re-open if this is not fixed on upgrade.

Thank you for the catch.

jaceksan pushed a commit to jaceksan/langchain that referenced this issue May 3, 2024
…using tool_calls or content) (langchain-ai#21201)

This PR fixes langchain-ai#21196.

The error was occurring when calling chat completion API with a chat
history. Indeed, the Mistral API does not accept both `content` and
`tool_calls` in the same body.

This PR removes one of theses variables depending on the necessity.

---------

Co-authored-by: Maxime Perrin <mperrin@doing.fr>
Co-authored-by: Chester Curme <chester.curme@gmail.com>
@honzababarik
Copy link

I am encountering the same issue - invoking model with tools and chat history resulting in error message:

{"object":"error","message":"Assistant message must have either content or tool_calls, but not both."}

Using @langchain/mistralai 0.0.19. Is it possible that the logic was not fixed in the JS package?

@jacoblee93
Copy link
Contributor

Hey @honzababarik, apologies for missing this - will have a look and report back tomorrow!

@jacoblee93
Copy link
Contributor

@honzababarik fix is live in the latest version (@langchain/mistralai@0.0.22). Thanks again for reporting, and let me know in the JS repo if you see anything similar pop up again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature 🔌: mistralai Primarily related to MistralAI integrations Ɑ: Tool Calling Related to Tool Calling
Projects
None yet
5 participants