letta
letta copied to clipboard
fix: various breaking bugs with local LLM implementation and postgres docker.
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
- memgpt/agent_store/db.py
See Issue #1347
Fix 2.1. Change the order of arguments to fix the mismatch. I think it would be better to be consistent with names of the arguments, but this was the simplest change.
Fix 2.2. Added filters to exclude the system prompts and tool from conversation searches. Fix 2.3. Fix, at least for PostGres, the format of the date in query_date SQL command. See #1343
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.
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.
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.
Tests should be OK on main (probs have a bug in our tests @sarahwooders). Thank you for the PR @madgrizzle !!