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

async def summarize_messages_inplace(). Fail to summarize the text #353

Closed
XjoeX opened this issue Nov 7, 2023 · 2 comments
Closed

async def summarize_messages_inplace(). Fail to summarize the text #353

XjoeX opened this issue Nov 7, 2023 · 2 comments

Comments

@XjoeX
Copy link

XjoeX commented Nov 7, 2023

Describe the bug
When I put a huge doc (like main.py code) into conversation. MemGPT keeping throw out error :

error = This model's maximum context length is 4097 tokens. However, your messages resulted in 8638 tokens (7919 in the messages, 719 in the functions). Please reduce the length of the messages or functions.

and the code (https://github.com/cpacker/MemGPT/blob/7d6aa4096d5118abc1d9bc2c9a298ed88a9e0da8/memgpt/agent.py#L1117) run in
`

        # If we got a context alert, try trimming the messages length, then try again
        if "maximum context length" in str(e):
            # A separate API call to run a summarizer
            await self.summarize_messages_inplace()

            # Try step again
            return await self.step(user_message, first_message=first_message)

`

and then in the code (https://github.com/cpacker/MemGPT/blob/7d6aa4096d5118abc1d9bc2c9a298ed88a9e0da8/memgpt/agent.py#L1126)
`

async def summarize_messages_inplace(self, cutoff=None, preserve_last_N_messages=True):
    assert self.messages[0]["role"] == "system", f"self.messages[0] should be system (instead got {self.messages[0]})"

    # Start at index 1 (past the system message),
    # and collect messages for summarization until we reach the desired truncation token fraction (eg 50%)
    # Do not allow truncation of the last N messages, since these are needed for in-context examples of function calling
    token_counts = [count_tokens(str(msg)) for msg in self.messages]
    message_buffer_token_count = sum(token_counts[1:])  # no system message
    token_counts = token_counts[1:]
    desired_token_count_to_summarize = int(message_buffer_token_count * MESSAGE_SUMMARY_TRUNC_TOKEN_FRAC)
    candidate_messages_to_summarize = self.messages[1:]
    if preserve_last_N_messages:
        candidate_messages_to_summarize = candidate_messages_to_summarize[:-MESSAGE_SUMMARY_TRUNC_KEEP_N_LAST]
        token_counts = token_counts[:-MESSAGE_SUMMARY_TRUNC_KEEP_N_LAST]

`

Can not find the latest message (main.py code which I type as input), so it can't summarise the message.

To Reproduce
Steps to reproduce the behavior:

  1. set model as gpt-3.5-trubo
  2. set multiline_input = True
    at (https://github.com/cpacker/MemGPT/blob/7d6aa4096d5118abc1d9bc2c9a298ed88a9e0da8/memgpt/main.py#L391C5-L391C28)
  3. CLI run: python main.py
  4. Typing huge text as input, such as, all code string in main.py itself.
  5. Alt+Enter to finish input.
  6. get error loop.

Expected behavior
The overlength text should be trunc and summarized as acceptable pices of text and saving them.

Screenshots
image


How did you install MemGPT?

  • With git clone [email protected]:cpacker/MemGPT.git and pip install -r requirements.txt

Your setup (please complete the following information)

  • Windows
  • cmd.exe
  • python 3.8
  • 0.1.15-83-gfd045ba
This was referenced Nov 8, 2023
@sarahwooders
Copy link
Collaborator

Could you please try installing the package and following these instructions https://memgpt.readthedocs.io/en/latest/quickstart/ and see if you have the same issue?

@cpacker
Copy link
Collaborator

cpacker commented Dec 2, 2023

Closing b/c this should not be a problem with the current version, please reopen if you're still having this issue

@cpacker cpacker closed this as completed Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants