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

JSON Parsing Error with Mistral Azure using tools and chain #5101

Closed
5 tasks done
alenoir opened this issue Apr 15, 2024 · 2 comments
Closed
5 tasks done

JSON Parsing Error with Mistral Azure using tools and chain #5101

alenoir opened this issue Apr 15, 2024 · 2 comments
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@alenoir
Copy link

alenoir commented Apr 15, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain.js 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.js 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

https://github.com/langchain-ai/langgraphjs/blob/main/examples/multi_agent/agent_supervisor.ipynb

Error Message and Stack Trace (if applicable)

Error Encountered:

Function "route" arguments:

[object Object]

are not valid JSON.
Error: Unexpected token o in JSON at position 1

Description

I am encountering an issue when running code from the agent_supervisor.ipynb file while using the Mistral Azure model. I receive a JSON parsing error.

Error Encountered:

Function "route" arguments:

[object Object]

are not valid JSON.
Error: Unexpected token o in JSON at position 1

Expected Behavior:
The arguments passed to the function should be interpreted as a valid JSON string, similar to the behavior when using the Mistral API.

Observed Behavior:
With the Azure SDK, arguments appear to be passed as an object, which does not meet expectations and causes a JSON parsing error.

Azure SDK Response Example:

{
   "lc": 1,
   "type": "constructor",
   "id": ["langchain_core", "messages", "AIMessage"],
   "kwargs": {
     "content": "",
     "tool_calls": [],
     "invalid_tool_calls": [
       {
         "name": "route",
         "args": {
           "next": "Researcher"
         },
         "id": "call_route_0",
         "error": "Function \"route\" arguments:\n\n[object Object]\n\nare not valid JSON.\nError: Unexpected token o in JSON at position 1"
       }
     ],
     "additional_kwargs": {
       "tool_calls": [
         {
           "function": {
             "arguments": {
               "next": "Researcher"
             },
             "call_id": null,
             "name": "route"
           },
           "id": "call_route_0",
           "type": "function"
         }
       ]
     },
     "response_metadata": {
       "tokenUsage": {
         "completionTokens": 23,
         "promptTokens": 228,
         "totalTokens": 251
       },
       "finish_reason": "tool_calls"
     }
   }
}

Mistral API Response Example:

{
   "lc": 1,
   "type": "constructor",
   "id": ["langchain_core", "messages", "AIMessage"],
   "kwargs": {
     "content": "",
     "tool_calls": [
       {
         "name": "route",
         "args": {
           "next": "Researcher"
         },
         "id": "d850f8fa32c14af1933b6986e2f997cd"
       }
     ],
     "invalid_tool_calls": [],
     "additional_kwargs": {
       "tool_calls": [
         {
           "function": {
             "name": "route",
             "arguments": "{\"next\": \"Researcher\"}"
           }
         }
       ]
     },
     "response_metadata": {
       "tokenUsage": {
         "completionTokens": 22,
         "promptTokens": 227,
         "totalTokens": 249
       },
       "finish_reason": "tool_calls"
     }
   }
}

Steps to Reproduce the Bug:

  1. Set up the environment with the Azure SDK.
  2. Run the agent_supervisor.ipynb notebook using the Mistral Azure model.
  3. Observe the error during the route function call.

System Info

pnpm info langchain

[email protected] | MIT | deps: 17 | versions: 264
Typescript bindings for langchain
https://github.com/langchain-ai/langchainjs/tree/main/langchain/

keywords: llm, ai, gpt3, chain, prompt, prompt engineering, chatgpt, machine learning, ml, openai, embeddings, vectorstores

dist
.tarball: https://registry.npmjs.org/langchain/-/langchain-0.1.33.tgz
.shasum: 959f0f023975092569b49f1f07fe60c11c643530
.integrity: sha512-IrRd839x8eAmDutHNDMHGzIjufyWt/ckJrnRB2WifIJmtLWNRNQo5jZd7toeBU0UOVOQxoPtQGYf8lR0ar7vIQ==
.unpackedSize: 4.1 MB

dependencies:
@anthropic-ai/sdk: ^0.9.1 @langchain/openai: ~0.0.28 js-yaml: ^4.1.0 langsmith: ~0.1.7 p-retry: 4 zod-to-json-schema: ^3.22.3
@langchain/community: ~0.0.47 binary-extensions: ^2.2.0 jsonpointer: ^5.0.1 ml-distance: ^4.0.0 uuid: ^9.0.0 zod: ^3.22.4
@langchain/core: ~0.1.56 js-tiktoken: ^1.0.7 langchainhub: ~0.0.8 openapi-types: ^12.1.3 yaml: ^2.2.1

maintainers:

dist-tags:
latest: 0.1.33 next: 0.1.29-rc.0

published 4 days ago by jacoblee93 [email protected]

platform : mac
Node version : v18.17.0
pnpm version : 8.15.5

Copy link

dosubot bot commented Apr 15, 2024

The error you're encountering, "Unexpected token o in JSON at position 1," typically indicates an issue with JSON parsing, where the route function expects a JSON string but receives an object instead. To resolve this, ensure that any arguments passed to the route function are serialized into a JSON string using JSON.stringify(). For example:

const args = { next: "Researcher" }; // Example arguments object
const serializedArgs = JSON.stringify(args); // Serialize the object
route(serializedArgs); // Pass the serialized string to the function

This approach ensures that the data passed to functions expecting JSON strings are correctly serialized, avoiding the parsing error you're experiencing. If the function might receive an already parsed object, consider checking the data type before parsing to handle it appropriately.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Apr 15, 2024
@jacoblee93
Copy link
Collaborator

Can you share how you're calling the Mistral Azure model?

@alenoir alenoir closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants