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

fix: #3673 - API responds with Request body is too large #3729

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

louis-jan
Copy link
Contributor

Describe Your Changes

This addresses the issue where the Jan API server gates requests based on body size, rejecting any larger than 1MB. This PR increases the accepted request body size and also handles errors gracefully.

I'm trying to integrate OpenAI LLMs like, gpt-4-turbo, gpt-4o...etc to integrate with LaVague-QA framework for Test Automation. While LaVague is sending request to the LLM running in Jan.AI is responding with "Request body is too large" error.

Steps to Reproduce

1.Download the LLM gpt-4-turbo OR gpt-4o using Jan.AI interface
2.Make an API call to LLM (gpt-4-turbo OR gpt-4o)
3.Observe the response returned "Request body is too large"
Note: Attaching the API request body.

Screenshots

Error handling
28536
Succeed
97740

Fixes Issues

Code changes

  1. core/src/node/api/restful/helper/builder.test.ts:

    • Added a new test case to check error handling when the status is not OK (400).
    • The test mocks a 400 status response and verifies that the error is properly forwarded.
  2. core/src/node/api/restful/helper/builder.ts:

    • Modified the error handling in the chatCompletions function.
    • Instead of just logging the error and sending a 400 status, it now forwards the complete error response (including status code, headers, and body) to the client.
  3. server/index.ts:

    • Added a bodyLimit configuration to the Fastify server initialization.
    • Set the body limit to 100MB (104,857,600 bytes), up from the default 1MB.
    • Added comments explaining the rationale for this limit, citing OpenAI's file size limits for various endpoints.

These changes improve error handling and reporting in the API, and increase the maximum allowed request body size to accommodate larger file uploads for certain AI model endpoints.

Copy link
Contributor

Barecheck - Code coverage report

Total: 62.61%

Your code coverage diff: 0.05% ▴

Uncovered files and lines
FileLines
core/src/node/api/restful/helper/builder.ts45, 52-53, 61, 100, 116-117, 131-132, 175, 205, 250, 271, 284, 287, 290, 326-327, 335-336, 341, 346

Copy link
Contributor

@dan-menlo dan-menlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - this allows us to accept Vision and Speech in the future. Thanks @louis-jan!

@louis-jan louis-jan merged commit dbc4bed into dev Sep 24, 2024
21 checks passed
@louis-jan louis-jan deleted the fix/3673-request-body-is-too-large branch September 24, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: API responds with "Request body is too large"
2 participants