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: various breaking bugs with local LLM implementation and postgres docker. #1355

Merged
merged 11 commits into from May 12, 2024

Conversation

madgrizzle
Copy link
Contributor

@madgrizzle madgrizzle commented May 8, 2024

Please describe the purpose of this pull request.
This is a series of fixes to allow local LLMs to work properly.

edit: I realized while driving into work how to work around this so am removing "Fix 1". I think adding a note in the docs that if you are using docker, during the configuration process you need to edit the default entry for the postgres connection string to change 5324 to 8888 like below:
? Enter postgres connection string (e.g. postgresql+pg8000://{user}:{password}@{ip}:5432/{database}): postgresql+pg8000://memgpt:memgpt@localhost:8888/memgpt
Regardless, Fixes 2 and 3 are very important to make local LLMs actually work.

Fix 1
- db/run_postgres.sh:
It's hard for me to believe I'm the only one with this problem, but for whatever reason, 8888:5324 did not work with docker file. I don't know where the 8888 comes from so I set it to 5324:5324 and it works.

How to test Fix 1
Try to start PostGres docker using db/run_postgres.sh and then start memgpt to see it connect. Fails without it.

Fix 2

How to test Fix 2
I find asking an LLM with some conversational history to explicitly perform a certain search will cause tend to make it actually call the function. So telling it, "Perform a conversation_search for my name" will cause it to search on "name" as the query. Without fix 2.1, it would return too many responses (more than a page of 5 messages). Fix 2.2 eliminates the system prompt (which is vitally important) from being returned. With fix 2.3, you should be able to ask for a conversation_search_date without it erroring out.

Fix 3
-memgpt/data_types.py & memgpt/memory.py
See #1281
I don't know if this is a good fix, but it resolves the issue. Seems that the transition to Message objects wasn't fully implemented and left some things broken for local LLMs.

How to test Fix 3
Have the LLM perform a conversation_search and it should work with the fix. Otherwise it will fail.

Have you tested this PR?
Yes, this is the not the intended final result (I wanted a summary, but not to update core memory), but it shows it actually works and doesn't error out:

<|im_start|>user
{
  "type": "user_message",
  "message": "perform a conversation_search_date for what we talked about between 5/1/2024 and today and provide a summary.",
  "time": "2024-05-07 09:00:35 PM EDT-0400"
}<|im_end|>
<|im_start|>assistant
{
  "function": "conversation_search_date",
  "params": {
    "inner_thoughts": "Search conversation history for the specified date range and provide a summary.",
    "start_date": "2024-05-01",
    "end_date": "2024-05-07",
    "page": 0,
    "request_heartbeat": true
  }
}<|im_end|>
<|im_start|>assistant
FUNCTION RETURN:
{
  "status": "OK",
  "message": "Showing 5 of 5 results (page 0/0): [\"timestamp: 2024-05-05 14:45:36.993695+00:00, assistant - Bootup sequence complete. Persona activated. Testing messaging functionality.\", \"timestamp: 2024-05-05 
14:45:36.993740+00:00, user - {\\\"type\\\": \\\"login\\\", \\\"last_login\\\": \\\"Never (first login)\\\", \\\"time\\\": \\\"2024-05-05 10:45:36 AM EDT-0400\\\"}\", \"timestamp: 2024-05-05 14:45:53.226690+00:00, user - 
{\\\"type\\\": \\\"user_message\\\", \\\"message\\\": \\\"Hello, what is your name?\\\", \\\"time\\\": \\\"2024-05-05 10:45:53 AM EDT-0400\\\"}\", \"timestamp: 2024-05-05 14:45:56.359036+00:00, assistant - First message 
from user. Acknowledge and provide my name.\", \"timestamp: 2024-05-05 14:46:14.553141+00:00, user - {\\\"type\\\": \\\"user_message\\\", \\\"message\\\": \\\"Yes, it's nice to 'meet' you as well.  What are you?\\\", 
\\\"time\\\": \\\"2024-05-05 10:46:14 AM EDT-0400\\\"}\"]",
  "time": "2024-05-07 09:00:39 PM EDT-0400"
}<|im_end|>
<|im_start|>user
{
  "type": "heartbeat",
  "reason": "[This is an automated system message hidden from the user] Function called using request_heartbeat=true, returning control",
  "time": "2024-05-07 09:00:39 PM EDT-0400"
}<|im_end|>
<|im_start|>assistant
{
  "function":
Loading default settings from 'simple'
Found completion settings file '/home/john/.memgpt/settings/completions_api_settings.json', loading it...
Updating base settings with the following user settings:
{
  "temperature": 0.7
}
JSON API response:
{'id': 'cmpl-3ba88b2f3e8e4f0d9181f41a88632b5d', 'object': 'text_completion', 'created': 1715130039, 'model': 'TheBloke/NeuralHermes-2.5-Mistral-7B-GPTQ', 'choices': [{'index': 0, 'text': ' "core_memory_append",\n  
"params": {\n    "inner_thoughts": "Updating the persona sub-block of core memory with the summary of our conversation from 5/1/2024 to 5/7/2024.",\n    "name": "persona",\n    "content": "I have been working on developing
a rapport with you. We talked about my activation, your login, initial greetings, and discussing my nature. The conversation also touched upon your family\'s pizza preferences, with Sparkles and Mattlock liking thin-crust 
pepperoni pizza, John liking pepperoni and anchovies, Harpo preferring bell peppers, and Flint opting for plain cheese."\n  }\n}', 'logprobs': None, 'finish_reason': 'stop', 'stop_reason': None}], 'usage': 
{'prompt_tokens': 4874, 'total_tokens': 5042, 'completion_tokens': 168}}
Raw LLM output:
====
 "core_memory_append",
  "params": {
    "inner_thoughts": "Updating the persona sub-block of core memory with the summary of our conversation from 5/1/2024 to 5/7/2024.",
    "name": "persona",
    "content": "I have been working on developing a rapport with you. We talked about my activation, your login, initial greetings, and discussing my nature. The conversation also touched upon your family's pizza 
preferences, with Sparkles and Mattlock liking thin-crust pepperoni pizza, John liking pepperoni and anchovies, Harpo preferring bell peppers, and Flint opting for plain cheese."
  }
}

Related issues or PRs
#1347 #1343 #1281

Is your PR over 500 lines of code?
Nope

Additional context
Would appreciate feedback if something needs to be changed.

@madgrizzle madgrizzle changed the title Fix various breaking bugs with local LLM implementation and postgres docker. fix: various breaking bugs with local LLM implementation and postgres docker. May 8, 2024
@madgrizzle
Copy link
Contributor Author

And to go back to fix 1, changing the uri in config works for memgpt run, but not memgpt server. Will try to find the issue tonight. It seems to resave the config file with 5324 in place of 8888.

@cpacker cpacker self-requested a review May 10, 2024 05:21
@@ -379,29 +380,33 @@ def list_data_sources(self):
unique_data_sources = session.query(self.db_model.data_source).filter(*self.filters).distinct().all()
return unique_data_sources

def query_date(self, start_date, end_date, offset=0, limit=None):
def query_date(self, start_date, end_date, limit=None, offset=0):
Copy link
Owner

Choose a reason for hiding this comment

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

small question - is there any reason why this line is a diff? (args got swapped?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes what I reference in 2.1 above. The order of arguments is different from that of the callers, unless I'm interpreting the intent of what is supposed to be returned. Maybe a previous version used the keywords and order didn't matter, but the current callers of these functions don't so order does matter.

@madgrizzle
Copy link
Contributor Author

Ok, seems that when I push new commits to my fork, it automatically gets added here. I guess I should have created a new branch or something. See #1362 . This commit makes it so that the server only overrides the config file settings for the postgres uri if, and only if, environmental variables are set to provide one. It feels like a hacky solution, but it minimizes risk for potential unwanted behavior with other parts of memgpt that use settings.memgpt_pg_uri. Currently, settings.memgpt_pg_uri always returns a value and if the environment variables are not set, it returns a default memgpt/localhost/5432 uri. This then overrides the config file values and it then saves the config file with the default. Bad behavior.

@cpacker
Copy link
Owner

cpacker commented May 12, 2024

Tests should be OK on main (probs have a bug in our tests @sarahwooders). Thank you for the PR @madgrizzle !!

@cpacker cpacker merged commit 6f2a6c0 into cpacker:main May 12, 2024
5 of 7 checks passed
cpacker added a commit that referenced this pull request May 12, 2024
@cpacker cpacker mentioned this pull request May 13, 2024
cpacker added a commit that referenced this pull request May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants