mistralai / mistral-inference

Official inference library for Mistral models

Home Page:https://mistral.ai/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[MISTRAL AI ERROR] Mistral AI responding with Unexpected role RoleEnum.tool error

muhammadfaizan027915 opened this issue · comments

I am using Mistral AI client in my javascript project and Mistral Ai is giving me a tool_calls response. When I call the tool and push response in messages array. And Then I call a send a second request to the Mistral AI it gives me this error:
MistralAPIError: HTTP error! status: 400 Response:
{"object":"error","message":"Unexpected role RoleEnum.tool","type":"invalid_request_error","param":null,"code":null}

My messages array contains:
Messages: [
{
"role": "user",
"name": "User",
"content": "give me random cat image\n\n"
},
{
"role": "tool",
"name": "RandomCatImage",
"content": "{"data":{"id":"cpq","url":"[https://cdn2.thecatapi.com/images/cpq.png/",/"width/":1024,/"height/":765%7D],/"success/":true,/"message/":/"Successfully accomplished!"}"
}
]

My implementation for function calling:

for (const tool of toolCalls) {
      const functionName = tool.function.name;
      const functionArguments = JSON.parse(tool.function.arguments);

      const desiredTool = httpTools?.find((tool) => (tool?.config as HttpToolSchema["config"])?.name?.replaceAll(" ", "") === functionName);
      const httpResponse = await httpToolHandler(desiredTool?.config as HttpToolSchema["config"])(functionArguments);

      messages?.push({ role: "tool", name: functionName, content: httpResponse });
    }

I am unable to get chat response from Mistral AI after calling a tool.
Screenshot_1

I have found the bug causing this error.

I am also facing the same issue, what were your findings?