langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
93.04k stars 14.95k forks source link

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

Closed maximeperrindev closed 5 months ago

maximeperrindev commented 5 months ago

Checked other resources

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

-

ccurme commented 5 months ago

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

Thank you for the catch.

honzababarik commented 5 months ago

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 commented 4 months ago

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

jacoblee93 commented 4 months ago

@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?

deramos commented 2 months ago

Getting the same error with langchain-mistralai python

langsmith
langchain-mistralai
langchain-community
langchain==0.2.2
langchain-core==0.2.4
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}
baskaryan commented 2 months ago

Getting the same error with langchain-mistralai python

langsmith
langchain-mistralai
langchain-community
langchain==0.2.2
langchain-core==0.2.4
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}

what version? was patched in langchain-mistralai>=0.1.6, are you seeing this issue in a later version?

deramos commented 2 months ago

@baskaryan

Name: langchain-mistralai
Version: 0.1.7
Benjaminrivard commented 2 months ago

Same error with latest (0.1.10) langchain-mistralai version