Closed pligor closed 10 months ago
Running main.py always causes an error, they havent' fixed it yet. However I have a workaround for this:
https://www.youtube.com/watch?v=zHtFuQiqhIo
Here's the bat file, make sure to change the file directories to where your python and venv folder will be: @echo off
:: Define the paths to Python and the venv set PYTHON_EXECUTABLE=C:\Users\ADMIN\AppData\Local\Programs\Python\Python310\python.exe set VENV_DIR=D:\AI\ChatBots\MemGPT_Setup\venv
:: Create the virtual environment "%PYTHON_EXECUTABLE%" -m venv "%VENV_DIR%"
:: Check if the virtual environment creation was successful if %errorlevel% neq 0 ( echo An error occurred while creating the virtual environment. Press any key to exit. pause >nul exit /b %errorlevel% )
:: Activate the virtual environment call "%VENV_DIR%\Scripts\activate"
:: Install pymemgpt using pip pip install pymemgpt pip install transformers pip install torch
:: Check if the installation was successful if %errorlevel% neq 0 ( echo An error occurred while installing pymemgpt. Press any key to exit. pause >nul exit /b %errorlevel% )
set OPENAI_API_BASE=http://localhost:1234 set BACKEND_TYPE=lmstudio cls
:: Run memgpt (replace this with your specific memgpt command) memgpt run --no_verify
:: Check if memgpt encountered an error if %errorlevel% neq 0 ( echo An error occurred while running memgpt. Press any key to exit. pause >nul exit /b %errorlevel% )
:: Deactivate the virtual environment deactivate
:: Pause to allow the user to review the output echo Press any key to exit. pause >nul
This also reduces the error when generating an output from LM Studio. It's not perfect as there are times you have to retry to get the correct format of the model response but for me it only happens 9 every 10 proper responses.
@ProjCRys the bug is described for MacOS. Either way translating your steps for Macos and trying them in terminal I eventually still ended up with this error in output of memgpt:
Warning: no wrapper specified for local LLM, using the default wrapper (you can remove this warning by specifying the wrapper with --model)
step() failed
user_message = None
error = Failed to parse JSON from local LLM response - error: Failed to decode JSON from LLM output:
{Hey, thanks for login! How can I assist you today? :D
### Inner Monologue: w00t! First time user! π
} - error
JSONDecodeError.__init__() missing 2 required positional arguments: 'doc' and 'pos'
Failed to parse JSON from local LLM response - error: Failed to decode JSON from LLM output:
{Hey, thanks for login! How can I assist you today? :D
### Inner Monologue: w00t! First time user! π
} - error
JSONDecodeError.__init__() missing 2 required positional arguments: 'doc' and 'pos'
An exception ocurred when running agent.step():
Traceback (most recent call last):
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/json_parser.py", line 53, in clean_json
data = json.loads(raw_llm_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/json_parser.py", line 56, in clean_json
data = json.loads(raw_llm_output + "}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/json_parser.py", line 18, in extract_first_json
return json.loads(string[start_index : i + 1])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py", line 397, in output_to_chat_completion_response
function_json_output = clean_json(raw_llm_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/json_parser.py", line 59, in clean_json
data = extract_first_json(raw_llm_output + "}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/json_parser.py", line 20, in extract_first_json
raise json.JSONDecodeError(f"Matched closing bracket, but decode failed with error: {str(e)}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: JSONDecodeError.__init__() missing 2 required positional arguments: 'doc' and 'pos'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/chat_completion_proxy.py", line 81, in get_chat_completion
chat_completion_result = llm_wrapper.output_to_chat_completion_response(result)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py", line 399, in output_to_chat_completion_response
raise Exception(f"Failed to decode JSON from LLM output:\n{raw_llm_output} - error\n{str(e)}")
Exception: Failed to decode JSON from LLM output:
{Hey, thanks for login! How can I assist you today? :D
### Inner Monologue: w00t! First time user! π
} - error
JSONDecodeError.__init__() missing 2 required positional arguments: 'doc' and 'pos'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/main.py", line 544, in run_agent_loop
new_messages, user_message, skip_next_user_input = await process_agent_step(user_message, no_verify)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/main.py", line 520, in process_agent_step
new_messages, heartbeat_request, function_failed, token_warning = await memgpt_agent.step(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/agent.py", line 1114, in step
raise e
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/agent.py", line 1059, in step
response = await get_ai_reply_async(model=self.model, message_sequence=input_message_sequence, functions=self.functions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/agent.py", line 163, in get_ai_reply_async
raise e
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/agent.py", line 144, in get_ai_reply_async
response = await acreate(
^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/openai_tools.py", line 115, in wrapper
raise e
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/openai_tools.py", line 95, in wrapper
return await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/openai_tools.py", line 124, in acompletions_with_backoff
return get_chat_completion(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/gp/anaconda3/lib/python3.11/site-packages/memgpt/local_llm/chat_completion_proxy.py", line 85, in get_chat_completion
raise LocalLLMError(f"Failed to parse JSON from local LLM response - error: {str(e)}")
memgpt.errors.LocalLLMError: Failed to parse JSON from local LLM response - error: Failed to decode JSON from LLM output:
{Hey, thanks for login! How can I assist you today? :D
### Inner Monologue: w00t! First time user! π
} - error
JSONDecodeError.__init__() missing 2 required positional arguments: 'doc' and 'pos'
Oh it think it must be the preprompt from the LM Studio preset. Since the response it generated didn't seem to match MemGPT's preferred format or probably may have generate a slightly different json output that caused an error.
This is what I did so that LM Studio would consistently give the correct format for memgpt response. It's not perfect as I it sometimes causes an error 1 out of 10 times. But you only need to retry to generate an output again.
https://m.youtube.com/watch?v=zHtFuQiqhIo&t=22s
If it still doesn't work, it's probably the model as it's probably not capable enough to follow memgpt output format. For me I used Mistral 7B dolphin and the 32k and 128k context length.
@ProjCRys the workaround that you suggested is not useful unfortunately as memgpt is constantly changing these days. It seems that regarding the configuration we have taken a step back as it can be seen from the setup and the error below:
memgpt configure
but upon execution of memgpt run
So this is still a valid bug that is not fixed, or need a better step by step help/manual to make it work
@pligor can you use set the default embedding endpoint to "local" instead?
Also, does your endpoint support embeddings?
Could you also share whats in your ~/.memgt/config
file (with any keys removed)
@ProjCRys the workaround that you suggested is not useful unfortunately as memgpt is constantly changing these days. It seems that regarding the configuration we have taken a step back as it can be seen from the setup and the error below:
memgpt configure
but upon execution ofmemgpt run
So this is still a valid bug that is not fixed, or need a better step by step help/manual to make it work
I made some updates on how I ran MemGPT. Instead of creating a vemv with 'memgpt run' I changed the bat file to this. Still using this and it's still working fine.
(change the directories where you want to place them.)
@echo off setlocal
REM Define the paths set VENV_PATH=D:\AI\ChatBots\MemGPT_Setup\venv set MEMGPT_PATH=D:\AI\ChatBots\MemGPT_Setup\MemGPT set PYTHON_PATH=C:\Users\ADMIN\AppData\Local\Programs\Python\Python310\python.exe
REM Create the virtual environment "%PYTHON_PATH%" -m venv "%VENV_PATH%"
if errorlevel 1 ( echo Error: Unable to create the virtual environment. Press any key to exit. pause >nul exit /b )
REM Activate the virtual environment call "%VENV_PATH%\Scripts\activate"
if errorlevel 1 ( echo Error: Unable to activate the virtual environment. Press any key to exit. pause >nul exit /b )
REM Install required dependencies from the correct directory pip install -r "%MEMGPT_PATH%\requirements-local.txt" set OPENAI_API_BASE=http://localhost:1234 set BACKEND_TYPE=lmstudio
if errorlevel 1 ( echo Error: Failed to install dependencies. Press any key to exit. pause >nul exit /b )
REM Run the 'python main.py' command python MemGPT/main.py
if errorlevel 1 ( echo Error: 'python -m memgpt' encountered an error. Press any key to exit. pause >nul exit /b )
REM Deactivate the virtual environment deactivate
REM Wait for the user to press any key before exiting pause >nul
Thanks @ProjCRys but your solution is out of scope as this defect is referring to MacOS and not Windows, no .bat files here.
@sarahwooders perhaps LMStudio cannot be used at all ? From this link it seems that LMStudio lacks supporting Grammar https://memgpt.readthedocs.io/en/latest/local_llm/
One can start experimenting when has at least something running.
Could you develop in the page above a longer step-by-step guide for dummies ?
There are lots of open questions of what to select in steps of memgpt configure and memgpt run to have a safe first run and then one can take from there to experiment with other options and other models.
LM Studio still does not have grammar support atm, however the JSON parsers should be more robust than they were a few weeks ago so you may have better luck.
Success of MemGPT will depend highly on how good the LLM is at generated structured outputs (eg JSON). Currently dolphin 2.2.1 and openhermes 2.5 are our recommendations for local/open LLMs. Check the #model-chat page on Discord for other notes on models we / the community have tested.
Describe the bug Basically when
To Reproduce Steps to reproduce the behavior:
python main.py --no_verify
Expected behavior A clear and concise description of what you expected to happen.
Screenshots
Additional context export OPENAI_API_BASE=http://127.0.0.1:5050 export BACKEND_TYPE=lmstudio
How did you install MemGPT? From source with
git clone git@github.com:cpacker/MemGPT.git
andpip install -r requirements.txt
Your setup (please complete the following information)
python --version
): 3.11.4git describe --tags
): 0.1.15-36-g54e5aefLocal LLM details
If you are trying to run MemGPT with local LLMs, please provide the following information:
Warning: no wrapper specified for local LLM, using the default wrapper step() failed user_message = None error = Failed to decode JSON from LLM output: {"Hello! Welcome to the Assistant, you've finally decided to join us. I'm so excited to help y..." }
An exception ocurred when running agent.step(): Traceback (most recent call last): File "/Users/gp/Desktop/MemGPT/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py", line 392, in output_to_chat_completion_response function_json_output = json.loads(raw_llm_output) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/anaconda3/lib/python3.11/json/init.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) ^^^^^^^^^^^^^^^^^^^^^^ json.decoder.JSONDecodeError: Expecting ':' delimiter: line 2 column 1 (char 99)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/gp/Desktop/MemGPT/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py", line 395, in output_to_chat_completion_response function_json_output = json.loads(raw_llm_output + "\n}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/anaconda3/lib/python3.11/json/init.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/anaconda3/lib/python3.11/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) ^^^^^^^^^^^^^^^^^^^^^^ json.decoder.JSONDecodeError: Expecting ':' delimiter: line 2 column 1 (char 99)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Users/gp/Desktop/MemGPT/memgpt/main.py", line 544, in run_agent_loop new_messages, user_message, skip_next_user_input = await process_agent_step(user_message, no_verify) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/Desktop/MemGPT/memgpt/main.py", line 520, in process_agent_step new_messages, heartbeat_request, function_failed, token_warning = await memgpt_agent.step( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/Desktop/MemGPT/memgpt/agent.py", line 1084, in step raise e File "/Users/gp/Desktop/MemGPT/memgpt/agent.py", line 1029, in step response = await get_ai_reply_async(model=self.model, message_sequence=input_message_sequence, functions=self.functions) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/Desktop/MemGPT/memgpt/agent.py", line 160, in get_ai_reply_async raise e File "/Users/gp/Desktop/MemGPT/memgpt/agent.py", line 141, in get_ai_reply_async response = await acreate( ^^^^^^^^^^^^^^ File "/Users/gp/Desktop/MemGPT/memgpt/openai_tools.py", line 115, in wrapper raise e File "/Users/gp/Desktop/MemGPT/memgpt/openai_tools.py", line 95, in wrapper return await func(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/Desktop/MemGPT/memgpt/openai_tools.py", line 124, in acompletions_with_backoff return get_chat_completion(kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/Desktop/MemGPT/memgpt/local_llm/chat_completion_proxy.py", line 62, in get_chat_completion chat_completion_result = llm_wrapper.output_to_chat_completion_response(result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/gp/Desktop/MemGPT/memgpt/local_llm/llm_chat_completion_wrappers/airoboros.py", line 397, in output_to_chat_completion_response raise Exception(f"Failed to decode JSON from LLM output:\n{raw_llm_output}") Exception: Failed to decode JSON from LLM output: {"Hello! Welcome to the Assistant, you've finally decided to join us. I'm so excited to help y..." }