cpacker / MemGPT

Create LLM agents with long-term memory and custom tools 📚🦙
https://memgpt.readme.io
Apache License 2.0
11.37k stars 1.23k forks source link

Docker - Startup script throws No such file or directory: '/.memgpt/logs' error #1627

Open raolak opened 1 month ago

raolak commented 1 month ago

Describe the bug I tried building docker image by closing source code and also building using pip pymemgpt and additionally copying memgpt config and credentials from working ~/.memgpt folder. But in both cases I am getting this error

kubectl logs astra-gpt-78c5bf5878-2fqrm --namespace memgpt-test

Traceback (most recent call last): File "/usr/local/lib/python3.12/pathlib.py", line 1311, in mkdir os.mkdir(self, mode) FileNotFoundError: [Errno 2] No such file or directory: '/.memgpt/logs'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/bin/memgpt", line 5, in from memgpt.main import app File "/usr/local/lib/python3.12/site-packages/memgpt/init.py", line 3, in from memgpt.client.admin import Admin File "/usr/local/lib/python3.12/site-packages/memgpt/client/admin.py", line 9, in from memgpt.server.rest_api.admin.tools import ( File "/usr/local/lib/python3.12/site-packages/memgpt/server/rest_api/admin/tools.py", line 8, in from memgpt.server.server import SyncServer File "/usr/local/lib/python3.12/site-packages/memgpt/server/server.py", line 13, in import memgpt.presets.presets as presets File "/usr/local/lib/python3.12/site-packages/memgpt/presets/presets.py", line 9, in from memgpt.metadata import MetadataStore File "/usr/local/lib/python3.12/site-packages/memgpt/metadata.py", line 27, in from memgpt.config import MemGPTConfig File "/usr/local/lib/python3.12/site-packages/memgpt/config.py", line 19, in from memgpt.log import get_logger File "/usr/local/lib/python3.12/site-packages/memgpt/log.py", line 43, in "filename": _setup_logfile(), ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/memgpt/log.py", line 18, in _setup_logfile logfile.parent.mkdir(parents=True, exist_ok=True) File "/usr/local/lib/python3.12/pathlib.py", line 1315, in mkdir self.parent.mkdir(parents=True, exist_ok=True) File "/usr/local/lib/python3.12/pathlib.py", line 1311, in mkdir os.mkdir(self, mode) PermissionError: [Errno 13] Permission denied: '/.memgpt'

Please describe your setup

Install necessary build tools

RUN echo "Updating package list..." RUN apt-get update RUN echo "Installing necessary build tools..." RUN apt-get install -y build-essential gcc g++ RUN echo "Cleaning up package list..." RUN rm -rf /var/lib/apt/lists/*

Install pymemgpt and necessary dependencies

RUN echo "Installing pymemgpt and necessary dependencies..." RUN pip install pymemgpt pymemgpt[postgres] RUN echo "pymemgpt and dependencies installed."

Create the directory for memgpt config

RUN echo "Creating memgpt config directory..." RUN mkdir -p /root/.memgpt RUN echo "memgpt config directory created."

Create the directory for logs under both /.memgpt and /root/.memgpt

RUN echo "Creating logs directories..." RUN mkdir -p /.memgpt/logs RUN mkdir -p /root/.memgpt/logs RUN echo "Logs directories created."

Copy the local config and credentials files to the container

RUN echo "Copying config file..." COPY ./config/config /root/.memgpt/config RUN echo "Config file copied."

RUN echo "Copying credentials file..." COPY ./config/credentials /root/.memgpt/credentials RUN echo "Credentials file copied."

Expose the necessary port (only admin port as per current setup)

RUN echo "Exposing port 8283..." EXPOSE 8283

Start the memgpt server in debug mode

RUN echo "Starting memgpt server in debug mode..." CMD ["memgpt", "server", "--debug"]

** Note , I have added mkdir as I was getting above error

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Trying to create docker image and use that to deploy in k8s. The memgpt/memgpt-server:latest from docker hub is not not compatible with Mac Arm architecture and it fails. Thats the reason I am trying to build the docker image. Also docker start up script throwing error.

MemGPT Config Please attach your ~/.memgpt/config file or copy past it below.

[defaults] preset = memgpt_chat persona = sam_pov human = basic

[model] model = gpt-4o model_endpoint = https://api.openai.com/v1 model_endpoint_type = openai context_window = 8192

[embedding] embedding_endpoint_type = openai embedding_endpoint = https://api.openai.com/v1 embedding_model = text-embedding-ada-002 embedding_dim = 1536 embedding_chunk_size = 300

[archival_storage] type = postgres path = /root/.memgpt/chroma uri = postgresql+pg8000://memgpt:memgpt@127.0.0.1:5432/memgpt

[recall_storage] type = postgres path = /root.memgpt uri = postgresql+pg8000://memgpt:memgpt@127.0.0.1:5432/memgpt

[metadata_storage] type = postgres path = /root.memgpt uri = postgresql+pg8000://memgpt:memgpt@127.0.0.1:5432/memgpt

[version] memgpt_version = 0.3.22

[client] anon_clientid = 00000000-0000-0000-0000-000000000000


If you're not using OpenAI, please provide additional information on your local LLM setup:

Local LLM details

If you are trying to run MemGPT with local LLMs, please provide the following information:

raolak commented 1 month ago

After debugging this is what worked for me. Startup script is not working...hence i had to fix this way

# Base image with Python
FROM python:3.12.2-slim-bookworm

# Install necessary build tools
RUN apt-get update && apt-get install -y \
    build-essential \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /root

# Create the necessary directories
RUN mkdir -p /root/.memgpt/logs 

# Copy the configuration files to the container (copy config and credentials files from ./config to /root/.memgpt)
COPY ./config /root/.memgpt

# Install the necessary Python packages
RUN pip install pymemgpt pymemgpt[postgres]

# Expose the necessary port
EXPOSE 8083

# Command to start the uvicorn server
CMD ["uvicorn", "memgpt.server.rest_api.server:app", "--host", "0.0.0.0", "--port", "8083"]

[model] model = gpt-4o model_endpoint = https://api.openai.com/v1 model_endpoint_type = openai context_window = 8192

[embedding] embedding_endpoint_type = openai embedding_endpoint = https://api.openai.com/v1 embedding_model = text-embedding-ada-002 embedding_dim = 1536 embedding_chunk_size = 300

[archival_storage] type = postgres path = /root/.memgpt/chroma uri = postgresql+pg8000://memgpt:memgpt@memgpt_postgres:5432/memgpt

[recall_storage] type = postgres path = /root.memgpt uri = postgresql+pg8000://memgpt:memgpt@memgpt_postgres:5432/memgpt

[metadata_storage] type = postgres path = /root/.memgpt uri = postgresql+pg8000://memgpt:memgpt@memgpt_postgres:5432/memgpt

[version] memgpt_version = 0.3.22

[client] anon_clientid = 00000000-0000-0000-0000-000000000000

### Steps
1. Create network

docker network create memgpt-network

2. init.sql

-- init.sql CREATE EXTENSION IF NOT EXISTS vector;

3. run postgres container

docker run --name memgpt_postgres \ --network memgpt-network \ -e POSTGRES_USER=memgpt \ -e POSTGRES_PASSWORD=memgpt \ -e POSTGRES_DB=memgpt \ -p 5433:5432 \ -v $(pwd)/init.sql:/docker-entrypoint-initdb.d/init.sql \ -d ankane/pgvector:v0.5.1


4. Run docker memgpt server (memgpt/debug-container:latest - change the name while building the docker)

docker run --name memgpt_server \ --network memgpt-network \ -e MEMGPT_SERVER_PASS=YourServerPass \ -p 8083:8083 \ -d memgpt/debug-container:latest