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

Maximum context length exceeded after browse_website #796

Closed
1 task done
TheAIAdopter opened this issue Apr 11, 2023 · 18 comments · Fixed by #2542
Closed
1 task done

Maximum context length exceeded after browse_website #796

TheAIAdopter opened this issue Apr 11, 2023 · 18 comments · Fixed by #2542

Comments

@TheAIAdopter
Copy link

Duplicates

  • I have searched the existing issues

Steps to reproduce 🕹

When it goes trough long documentation, it seems to reach a cap
It is trying to summarize a 486620 characters486620 characters text and give this error

I'm not sure i'm reporting this correctly. Pease let me know what i can do to improve futur bug report

Current behavior 😯

Command browse_website returned: Error: This model's maximum context length is 4097 tokens. However, your messages resulted in 5314 tokens. Please reduce the length of the messages.

Expected behavior 🤔

split the text so it can be summarized with 4790 tokens

Your prompt 📝

Welcome to Auto-GPT!  Enter the name of your AI and its role below. Entering nothing will load defaults.
Name your AI:  For example, 'Entrepreneur-GPT'
AI Name: chartgenius-GPT
chartgenius-GPT here! I am at your service.
Describe your AI's role:  For example, 'an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.'
chartgenius-GPT is: an ai design to create and test script algorythm for trading view that would trade autonomously to make money with stock trading. You will create and test these algorythm on the past year market to test it's rentability.  You need to develop algorythm that will generate as much revenus as possible. once you have the algo created and tested for profitability, you will save it in local with filename script1.txt  if you do multiple algo that we can use, name it script2.txt, script3.txt etc
Enter up to 5 goals for your AI:  For example: Increase net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'
Enter nothing to load defaults, enter nothing when finished.
Goal 1: develop 3 different profitable algorythm
Goal 2:
Using memory of type: LocalCache
CHARTGENIUS-GPT THOUGHTS: Before we begin creating trading algorithms, it's important to understand the basics and have a solid understanding of stock market analysis. Let's first start with a Google search to find introductory resources on stock market analysis.
REASONING: I need to make sure that I have a solid foundation of knowledge on stock market analysis to develop profitable trading algorithms.
PLAN:
-  Perform a Google search for introductory resources on stock market analysis
CRITICISM: I should have already had a base knowledge of stock market analysis before beginning to develop trading algorithms. I'll need to make sure I learn quickly to make up for lost time.
NEXT ACTION:  COMMAND = google ARGUMENTS = {'input': 'introductory resources for stock market analysis'}
Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for chartgenius-GPT...
Input:y -10
NEXT ACTION:  COMMAND = do_nothing ARGUMENTS = {}
SYSTEM:  Command do_nothing returned: No action performed.
CHARTGENIUS-GPT THOUGHTS: Now that we have found the Alpha Vantage API, let's check the API documentation and data limitations to make sure it has the necessary data for our testing. We will need to ensure that we are obtaining historical stock data for at least the last year for a few different companies.
REASONING: I need to make sure that the Alpha Vantage API has the necessary data for my momentum strategy
PLAN:
-  Browse the Alpha Vantage API documentation
-  Find the data limitations and requirements for historical stock data
-  Ensure that the API provides data for at least the last year for a few different companies
CRITICISM: I'll need to make sure that the API can provide enough data for our testing purposes. I'll also need to pay attention to any limitations or requirements for using the API to gather historical stock data.
NEXT ACTION:  COMMAND = browse_website ARGUMENTS = {'url': 'https://www.alphavantage.co/documentation/', 'question': 'What are the limitations and requirements for obtaining historical stock data?'}
Text length: 486620 characters
Summarizing chunk 1 / 60
Summarizing chunk 2 / 60
Summarizing chunk 3 / 60
Summarizing chunk 4 / 60
Summarizing chunk 5 / 60
Summarizing chunk 6 / 60
Summarizing chunk 7 / 60
Summarizing chunk 8 / 60
Summarizing chunk 9 / 60
Summarizing chunk 10 / 60
Summarizing chunk 11 / 60
Summarizing chunk 12 / 60
Summarizing chunk 13 / 60
Summarizing chunk 14 / 60
Summarizing chunk 15 / 60
Summarizing chunk 16 / 60
Summarizing chunk 17 / 60
Summarizing chunk 18 / 60
Summarizing chunk 19 / 60
Summarizing chunk 20 / 60
Summarizing chunk 21 / 60
Summarizing chunk 22 / 60
Summarizing chunk 23 / 60
Summarizing chunk 24 / 60
Summarizing chunk 25 / 60
Summarizing chunk 26 / 60
Summarizing chunk 27 / 60
Summarizing chunk 28 / 60
Summarizing chunk 29 / 60
Summarizing chunk 30 / 60
Summarizing chunk 31 / 60
Summarizing chunk 32 / 60
Summarizing chunk 33 / 60
Summarizing chunk 34 / 60
Summarizing chunk 35 / 60
Summarizing chunk 36 / 60
Summarizing chunk 37 / 60
Summarizing chunk 38 / 60
Summarizing chunk 39 / 60
Summarizing chunk 40 / 60
Summarizing chunk 41 / 60
Summarizing chunk 42 / 60
Summarizing chunk 43 / 60
Summarizing chunk 44 / 60
Summarizing chunk 45 / 60
Summarizing chunk 46 / 60
Summarizing chunk 47 / 60
Summarizing chunk 48 / 60
Summarizing chunk 49 / 60
Summarizing chunk 50 / 60
Summarizing chunk 51 / 60
Summarizing chunk 52 / 60
Summarizing chunk 53 / 60
Summarizing chunk 54 / 60
Summarizing chunk 55 / 60
Summarizing chunk 56 / 60
Summarizing chunk 57 / 60
Summarizing chunk 58 / 60
Summarizing chunk 59 / 60
Summarizing chunk 60 / 60
Summarized 60 chunks.
SYSTEM:  Command browse_website returned: Error: This model's maximum context length is 4097 tokens. However, your messages resulted in 5314 tokens. Please reduce the length of the messages.
CHARTGENIUS-GPT THOUGHTS: Since accessing the Alpha Vantage API may require an API key, let's generate a new API key before we start testing. We'll need the key to access the data through the API.
REASONING: I need to generate a new API key for Alpha Vantage before testing
PLAN:
-  Create an account with Alpha Vantage
-  Generate a new API key
CRITICISM: I'll need to keep the API key secure and ensure that it is not shared or lost. I'll also need to make sure that the key is entered correctly when accessing the API.

SYSTEM:  Command do_nothing returned: No action performed.
\```
@blankster
Copy link
Contributor

+1 from my side - I'm facing this problem very often too

@SuperYeti
Copy link

It has to do with when it's tryijng to create the embeddings. I went down a rabbit hole with this trying to chunk the embeddings which got past that error, but then AutoGPT got into a never ending loop as it was loading too much context and having to prune it seemingly forever. I think we need to come up with a better solution to reading, summarizing, and reviewing large documentation, but haven't come up with a good solution yet. I had already started going down the path of model training to deal with this before AutoGPT was released, and I think will probably end up being the correct solution. Any suggestions how best to implement it?

@joaovitor2763
Copy link

+1 here, and can't find a way to solve it

@javableu
Copy link
Contributor

same here.

The prompt is too large when the AI use COMMAND = read_file ARGUMENTS = {'file': 'file_name.txt'} and the file is too large

I get this error :

Traceback (most recent call last):
...
This model's maximum context length is 8191 tokens, however, you requested 12122 tokens (12122 in your prompt; 0 for the completion). Please reduce your prompt; or completion length.

# Paste your prompt here

ai_goals:

  • Ask me for the text to be improved if you don't have the text.
  • Select the part of the text you want to improve (chapters)
  • improve it and save it.
  • merge the texts together into a final document.
    ai_name: improve text
    ai_role: improve a text and save it in a text file

@BlaisePx
Copy link

BlaisePx commented Apr 13, 2023

Same problem. I am trying to get it to read a text file, and there are just a few lines in the file, so I know it is not too much text.

The text file is in the workspace folder. It just won't read it, but it can make files there.

@SuperYeti
Copy link

SuperYeti commented Apr 14, 2023 via email

@SlistInc
Copy link

I noticed the same thing for not only large text files. I got a the following error in two distinct situations as well

openai.error.InvalidRequestError: This model's maximum context length is 8191 tokens, however you requested 17031 tokens (17031 in your prompt; 0 for the completion). Please reduce your prompt; or completion length.

on a

  • NEXT ACTION: COMMAND = execute_shell ARGUMENTS = {'command_line': 'pip install opencv-python-headless deepface face_recognition'} > I was experimenting with sorting photos in a folder by face.
  • NEXT ACTION: COMMAND = search_files ARGUMENTS = {'directory': 'Staging/', 'extension': 'jpg'} > if the folder has more than a few hundred files

I can understand that GPT is fed too many tokens by the outputs of those calls, however I would appreciate it if the exception was somehow handled without shutting auto-GPT down. Currently it stops the whole exectuion and I have to start with my project over, hoping that 30 minutes in it won't exit again.

esurharun pushed a commit to esurharun/Auto-GPT that referenced this issue Apr 14, 2023
@esurharun
Copy link

I am not an expert and I just checked out OpenAI's cookbok and I think the commit below can be a good start for a workaround;

esurharun@c36f44f

@SlistInc
Copy link

It could indeed. I would welcome it if you could post it as a PR and get the other devs involved!

@Qnected
Copy link

Qnected commented Apr 16, 2023

I tried restarting AutoGPT, but the

openai.error.InvalidRequestError: This model's maximum context length is 4097 tokens. However, you requested 9997 tokens (965 in the messages, 9032 in the completion). Please reduce the length of the messages or completion.

Does anyone know how to get rid of this notification?

@socialmedialabs
Copy link

I tried restarting AutoGPT, but the

openai.error.InvalidRequestError: This model's maximum context length is 4097 tokens. However, you requested 9997 tokens (965 in the messages, 9032 in the completion). Please reduce the length of the messages or completion.

Does anyone know how to get rid of this notification?

Restarting Auto-GPT won't help as this is a bug. If you carefully read the error message you'll find that Auto-GPT chokes on strings that exceed a particular length.

@mihail-yartsev
Copy link

It seems the problem might be inside the split_text function.
I replaced it by the following and the problem disappeared:

def split_text(text, max_length=3800, max_chunks=5):
    """Split text into chunks of a maximum length and limit the number of chunks"""
    paragraphs = text.split("\n")
    current_length = 0
    current_chunk = []
    chunk_count = 0

    for paragraph in paragraphs:
        if chunk_count >= max_chunks:
            break

        if current_length + len(paragraph) + 1 <= max_length:
            current_chunk.append(paragraph)
            current_length += len(paragraph) + 1
        else:
            yield "\n".join(current_chunk)
            current_chunk = [paragraph]
            current_length = len(paragraph) + 1
            chunk_count += 1

    if current_chunk:
        yield "\n".join(current_chunk)

@SlistInc
Copy link

It might be that there are different problems with a similar error. I applied your proposed change but my error persists.

To reproduce:

  • Put a directory (e.g. Staging/) into auto_gpt_workspace
  • Make sure the directory contains many files (I have around 1'000 text files)
  • Start Auto-GPT and give it the goal to "List all files in Staging/"
    As soon as Auto-GPT does a
    NEXT ACTION: COMMAND = search_files ARGUMENTS = {'directory': 'Staging/'}

it will crash with a

Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/.../Auto-GPT/autogpt/__main__.py", line 53, in <module> main() File "/.../Auto-GPT/autogpt/__main__.py", line 49, in main agent.start_interaction_loop() File "/.../Auto-GPT/autogpt/agent/agent.py", line 170, in start_interaction_loop self.memory.add(memory_to_add) File "/.../Auto-GPT/autogpt/memory/redismem.py", line 91, in add vector = create_embedding_with_ada(data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/.../Auto-GPT/autogpt/llm_utils.py", line 137, in create_embedding_with_ada return openai.Embedding.create( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/autogpt/lib/python3.11/site-packages/openai/api_resources/embedding.py", line 33, in create response = super().create(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/autogpt/lib/python3.11/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create response, _, api_key = requestor.request( ^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/autogpt/lib/python3.11/site-packages/openai/api_requestor.py", line 226, in request resp, got_stream = self._interpret_response(result, stream) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/homebrew/Caskroom/miniforge/base/envs/autogpt/lib/python3.11/site-packages/openai/api_requestor.py", line 619, in _interpret_response self._interpret_response_line( File "/opt/homebrew/Caskroom/miniforge/base/envs/autogpt/lib/python3.11/site-packages/openai/api_requestor.py", line 682, in _interpret_response_line raise self.handle_error_response( openai.error.InvalidRequestError: This model's maximum context length is 8191 tokens, however you requested 180144 tokens (180144 in your prompt; 0 for the completion). Please reduce your prompt; or completion length.

@mihail-yartsev
Copy link

I see, thanks for checking this.

I guess it's best to see what happens with the already opened PRs. I've also tried the option from #2088, it works for me, for now.

PS One of the problems here is that the function and the PR above focuses on splitting text into paragraphs of particular symbols count, while the error is talking about limit in tokens. And, according to google, "For text in English, 1 token is approximately 4 characters or 0.75 words". Does it mean that make this very stable one will have to tokenise the text on the client side?

@Pwuts Pwuts changed the title This model's maximum context length is 4097 tokens. Maximum context length exceeded after browse_website Apr 22, 2023
@Pwuts
Copy link
Member

Pwuts commented Apr 22, 2023

@SlistInc see #2801

@Pwuts Pwuts removed a link to a pull request Apr 22, 2023
5 tasks
@SlistInc
Copy link

@SlistInc see #2801

Thanks, unfortunately my case relates to search_files as well, which seems to be another issue than the one discussed in #2801

Should I open a separate ticket for search_files?

The issue appears when search_files is called on a folder with too many files

@Pwuts
Copy link
Member

Pwuts commented Apr 26, 2023

unfortunately my case relates to search_files as well, which seems to be another issue than the one discussed in #2801

Should I open a separate ticket for search_files?

#2801 covers search_files as well, see the title

@Pwuts Pwuts closed this as completed Apr 26, 2023
@hdmbn
Copy link

hdmbn commented Jun 19, 2023

This error still happens when the target website is using UTF-8 and has characters in the Arabic/Persian language.
Today in the latest version I got this error when next command was browse_website:
NEXT ACTION: COMMAND = browse_website
openai.error.InvalidRequestError: This model's maximum context length is 4097 tokens. However, your messages resulted in 7679 tokens. Please reduce the length of the messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.