lobehub / lobe-chat

🤯 Lobe Chat - an open-source, modern-design AI chat framework. Supports Multi AI Providers( OpenAI / Claude 3 / Gemini / Ollama / Azure / DeepSeek), Knowledge Base (file upload / knowledge management / RAG ), Multi-Modals (Vision/TTS) and plugin system. One-click FREE deployment of your private ChatGPT/ Claude application.
https://chat-preview.lobehub.com
Other
43.82k stars 9.82k forks source link

[Bug] GPT 4o上传图片失败,context length exceeded #4546

Open sonnyding1 opened 5 hours ago

sonnyding1 commented 5 hours ago

📦 Environment

Official Preview

📌 Version

v1.26.11

💻 Operating System

macOS

🌐 Browser

Other

🐛 Bug Description

原来可以正常上传图片,现在不行了,可能是因为把图片作为byte stream直接上传到OpenAI API,而不是根据https://platform.openai.com/docs/guides/vision 的方法上传。我得到的error是context length exceeded,也就是说上传一张~170kb的图片直接让一个request超过了128k的context window。具体的log如下:

{
  "error": {
    "message": "This model's maximum context length is 128000 tokens. However, your messages resulted in 174643 tokens. Please reduce the length of the messages.",
    "type": "invalid_request_error",
    "param": "messages",
    "code": "context_length_exceeded"
  },
  "endpoint": "https://api.openai.com/v1",
  "provider": "openai"
}

请尽快修复,我尝试上传~40kb的图片,结果一条request就花了~$0.2,显然是把这40kb的图片算成request中的40k了。

📷 Recurrence Steps

No response

🚦 Expected Behavior

No response

📝 Additional Information

No response

lobehubbot commented 5 hours ago

👀 @sonnyding1

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. Please make sure you have given us as much context as possible.\ 非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

dosubot[bot] commented 4 hours ago

@sonnyding1 你好!我是Dosu,一个可以帮助您解决bug、回答问题并成为贡献者的机器人。在等待人类维护者的过程中,我会尽力帮助您。

I found a similar closed issue regarding image upload problems with the GPT-4o model. The issue was resolved by upgrading to the latest version and clearing the browser's data and history. It was suggested that there might have been a bug related to the search and adding an online model not originally supported. Additionally, refreshing the model list in the settings allowed the user to upload images again [1].

In your case, the error message indicates that the context length exceeded the model's maximum limit of 128,000 tokens. This could be due to the way images are being uploaded as byte streams, which might be inflating the token count. You might want to check if the image is being converted to base64 format before sending it to the OpenAI API, as this is the method used in the lobe-chat framework [2][3].

To address the issue, consider the following steps:

  1. Ensure that the image is being converted to base64 format before uploading.
  2. Check if there are any recent updates or changes in the codebase related to image processing that might affect this behavior [4].
  3. Try reducing the image size or resolution to see if it helps in staying within the context length limit.

These steps might help in resolving the issue with image uploads exceeding the context length.

To continue talking to Dosu, mention @dosu.

arvinxx commented 32 minutes ago

图片是啥样的?

lobehubbot commented 32 minutes ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


What does the picture look like? You haven't changed this recently, right?

arvinxx commented 18 minutes ago

知道为啥了,我修下

lobehubbot commented 17 minutes ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I know why, I'll fix it