Zain-ul-din / whatsapp-ai-bot

This is a WhatsApp AI bot that uses various AI models, including Gemini, GPT, DALL-E, Flux and StabilityAI, to generate responses to user input.
https://wa-ai-seven.vercel.app/
MIT License
185 stars 104 forks source link

Model's maximum context length exceed #16

Closed yiwaixiao closed 11 months ago

yiwaixiao commented 11 months ago

Thank you for providing the whatsapp-ai-bot. I tested it and it's a great application. However, I encountered the following issue during the trial. Whenever I engage in a few rounds of chat, I receive the following error. Is this a bug in the program or is there something that needs to be adjusted? Please advise.

 ✖ CustomModel request fail | An error occur, at CustomModel.ts sendMessage(prompt, msg) err: Error: OpenAI error 400: {
    | ^
  2 | "error": {
  3 | "message": "This model's maximum context length is 4097 tokens. However, you requested 4246 tokens (1246 in the messages, 3000 in the completion). Please reduce the length of the messages or completion.",
  4 | "type": "invalid_request_error",
Zain-ul-din commented 11 months ago

Thank you for checking out our whatsapp-ai-bot

@yiwaixiao this error is saying your maximum text limit has been exceeded. check this error

- "message": "This model's maximum context length is 4097 tokens. 
- However, you requested 4246 tokens (1246 in the messages, 3000 in the completion). 
- Please reduce the length of the messages or completion."

Possible Solution

  1. Please reduce the length of the messages if your sending too long message.
  2. Use chat-gpt latest models that have more token limit check out more here

To change the default model

image

image

Disclaimer ⚠

it is essential to note that these operations come at a cost charged by OpenAI and Stability AI for every request made. Please be aware that WhatsApp does not support bots or unofficial clients on its platform, so using this method is not entirely secure and could lead to getting blocked.

yiwaixiao commented 11 months ago

Thank you very much. The problem has been resolved Also, may I ask if I could find a way to configure the openai API URL? I would like to use WhatsApp ai bot to connect with GPTs with knowledge base capabilities to enhance WhatsApp AI's customer service capabilities. The existing knowledge base GPT aligns with the official capabilities of the openai API, and only needs to be able to configure the openai API URL. For example, add a base URL field in:. env to customize the configuration of the openai API URL, without filling in the default support for the official openai API May I ask if it is possible to support it? Please provide guidance. If not, can I upgrade and make changes? I can pay the appropriate fee. Thank you!

zain-ul-din-zafar commented 11 months ago

I cannot understand your problem please can you provide some more details what do you means by I could find a way to configure the openai API URL??

also provide some examples to make me understand.

Zain-ul-din commented 11 months ago

Your question seems like XY Problem please clearly describe what you exactly want to achieve also provide some examples if possible.

yiwaixiao commented 11 months ago

QQ截图20231101095311 As shown in the example in the figure, add a 'BASE' URL. If this value is not filled in, it defaults to apiopenai.com. If it is filled in, use 'BASE' URL to request openai

Zain-ul-din commented 11 months ago

Check this package chatgpt i'm using in this repository.

yiwaixiao commented 11 months ago

As shown in the example in the figure, add a 'BASE' URL. If this value is not filled in, it defaults to apiopenai.com. If it is filled in, use 'BASE' URL to request openai

QQ截图20231101095311 As shown in the example in the figure, add a 'BASE' URL. If this value is not filled in, it defaults to apiopenai.com. If it is filled in, use 'BASE' URL to request openai

zain-ul-din-zafar commented 11 months ago

still, I'm not getting please explain what exactly you want to achieve. You're thinking if you managed to achieve X your Y problem will be solved automatically. So, Instead of describing X problem explain exactly what you want to achieve.

read about XY problem

yiwaixiao commented 11 months ago

Simply put, to be able to customize the OpenAI API endpoint in the .env file. By default, the whatsapp-ai-bot communicates with the OpenAI API using https://api.openai.com/v1. Now, I need to be able to customize the OpenAI API address in the .env file, for example, change it to https://api.abc.com/v1.

As shown in the following figure, add an OPENAI in. env BASE URL used to proxy access to openai QQ截图20231102210705

Zain-ul-din commented 11 months ago

I'm using chat-gpt package. This package is responsible for sending requests to OPEN AI you can go to their repo and ask same question i think they can help you