[Bug]: Function Calling With Deepseek-chat

by ADMIN 43 views

Introduction

In this article, we will be discussing a bug that occurs when using function calling with the deepseek-chat model in LibreChat v0.7.7. The bug causes the first function call to work successfully, but subsequent interactions result in an error. We will delve into the details of the bug, including the steps to reproduce it, relevant log output, and potential solutions.

What Happened?

When trying to use function calling with the deepseek-chat model, the first function call works as expected. However, each interaction afterwards breaks with an error. The error message indicates that there is an issue with deserializing the JSON body into the target type.

Version Information

The bug was encountered in LibreChat v0.7.7. The relevant Docker images used are:

  • ghcr.io/danny-avila/librechat-dev: latest (06e87a09ddf6)
  • ghcr.io/danny-avila/librechat-rag-api-dev-lite: latest (49a785a50986)

Steps to Reproduce

To reproduce the bug, follow these steps:

  1. Use the deepseek-chat model and make a function call.
  2. The first function call should work successfully.
  3. Make another function call.
  4. The model should break with an error.

Error Message

The error message encountered is:

422 Failed to deserialize the JSON body into the target type: messages[6]: invalid type: sequence, expected a string at line 127 column 4

Relevant Log Output

The relevant log output is:

2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Establishing new connection
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Creating SSE transport: https://[removed].ngrok-free.app/mcp/sse
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Establishing new connection
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Creating SSE transport: https://[removed].ngrok-free.app/mcp/sse
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Connection successfully established
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Connection successfully established
2025-04-29 10:41:31 info: [api/server/controllers/agents/client.js #checkVisionRequest] not implemented
2025-04-29 10:43:00 error: [api/server/controllers/agents/client.js #sendCompletion] Operation aborted 422 Failed to deserialize the JSON body into the target type: messages6]: invalid type: sequence, expected a string at line 127 column 4
2025-04-29 10:43:00 error: [api/server/controllers/agents/client.js #sendCompletion] Unhandled error type 422 Failed to deserialize the JSON body into the target type: messages[6]: invalid type: sequence, expected a string at line 127 column 4

Screenshots

No screenshots are available for this bug.

Code of Conduct

I agree to follow this project's Code of Conduct.

Potential Solutions

Based on the error message and log output, it appears that there is an issue with deserializing the JSON body into the target type. Potential solutions include:

  • Checking the JSON body for any errors or inconsistencies.
  • Verifying that the target type is correct and matches the expected type.
  • Updating the deepseek-chat model to handle sequences correctly.

Conclusion

Q: What is the bug in function calling with Deepseek-Chat?

A: The bug causes the first function call to work successfully, but subsequent interactions result in an error. The error message indicates that there is an issue with deserializing the JSON body into the target type.

Q: What is the error message encountered?

A: The error message is:

422 Failed to deserialize the JSON body into the target type: messages[6]: invalid type: sequence, expected a string at line 127 column 4

Q: What are the steps to reproduce the bug?

A: To reproduce the bug, follow these steps:

  1. Use the deepseek-chat model and make a function call.
  2. The first function call should work successfully.
  3. Make another function call.
  4. The model should break with an error.

Q: What is the relevant log output for the bug?

A: The relevant log output is:

2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Establishing new connection
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Creating SSE transport: https://[removed].ngrok-free.app/mcp/sse
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Establishing new connection
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Creating SSE transport: https://[removed].ngrok-free.app/mcp/sse
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Connection successfully established
2025-04-29 10:40:05 info: [MCP][User: 6755f8a647fbe36db6ef2ec0][ngrok] Connection successfully established
2025-04-29 10:41:31 info: [api/server/controllers/agents/client.js #checkVisionRequest] not implemented
2025-04-29 10:43:00 error: [api/server/controllers/agents/client.js #sendCompletion] Operation aborted 422 Failed to deserialize the JSON body into the target type: messages[6]: invalid type: sequence, expected a string at line 127 column 4
2025-04-29 10:43:00 error: [api/server/controllers/agents/client.js #sendCompletion] Unhandled error type 422 Failed to deserialize the JSON body into the target type: messages[6]: invalid type: sequence, expected a string at line 127 column 4

Q: What are the potential solutions for the bug?

A: Potential solutions include:

  • Checking the JSON body for any errors or inconsistencies.
  • Verifying that the target type is correct and matches the type.
  • Updating the deepseek-chat model to handle sequences correctly.

Q: Is there any relevant code that can be shared?

A: Yes, the relevant code is:

// api/server/controllers/agents/client.js

// ...

// ...

// ...

// ...

Q: Can this bug be fixed by updating the deepseek-chat model?

A: Yes, updating the deepseek-chat model to handle sequences correctly may fix the bug.

Q: Are there any other potential causes for this bug?

A: Yes, other potential causes for this bug include:

  • Issues with the JSON body or target type.
  • Problems with the deepseek-chat model or its dependencies.
  • Conflicts with other libraries or frameworks used in the project.

Q: How can I report this bug or request help?

A: You can report this bug or request help by:

  • Creating an issue on the project's GitHub page.
  • Reaching out to the project's maintainers or contributors.
  • Joining the project's community or forums to discuss the issue.