langchain-ai / open-canvas

📃 A better UX for chat, writing content, and coding with LLMs.
https://opencanvas.langchain.com/
MIT License
2.43k stars 353 forks source link

Is it possible to run Open-Canvas on Linux fully-local using a local LangGraph CLI instead of LangGraph Studio cloud? #181

Open PieBru opened 3 days ago

PieBru commented 3 days ago

Said all in the title. Thank you.

lanesky commented 2 days ago

I shared an approach for running Open-Canvas on Windows. This method might also work on Linux, so feel free to check it out—it could be useful! However, it still requires a LangSmith API key to push trace information to the cloud, unfortunately.

https://github.com/langchain-ai/open-canvas/issues/114#issuecomment-2458440368

PieBru commented 1 day ago

@lanesky Thank you. I just tried with the staging branch, because it seems to be the preferred one for eventual PR. I'm new with tools like Uvicorn & Co., thus some help will be appreciated to save me from entering the rabbit hole.

This is the log tail, it's on a Arch Linux LXC container on Proxmox VE 8.2.

2024-11-06T18:29:30.308511Z [info     ] Started server process [1]     [uvicorn.error] api_revision=f2b62eb api_variant=local color_message=Started server process [%d]
2024-11-06T18:29:30.308637Z [info     ] Waiting for application startup. [uvicorn.error] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:30.308847Z [warning  ] No license key found, running in test mode with LangSmith API key. For production use, set LANGGRAPH_CLOUD_LICENSE_KEY in environment. [langgraph_license.validation] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:30.753507Z [info     ] HTTP Request: GET https://api.smith.langchain.com/auth?langgraph-api=true "HTTP/1.1 200 OK" [httpx] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:30.851005Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:31.931555Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:34.091808Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:38.409794Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:47.041806Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:30:00.804040Z [error    ] Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 693, in lifespan
    async with self.lifespan_context(app) as maybe_state:
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/api/langgraph_api/lifespan.py", line 29, in lifespan
  File "/usr/local/lib/python3.12/site-packages/langgraph_storage/database.py", line 113, in start_pool
    await _pg_pool.open(wait=True)
  File "/usr/local/lib/python3.12/site-packages/psycopg_pool/pool_async.py", line 383, in open
    await self.wait(timeout=timeout)
  File "/usr/local/lib/python3.12/site-packages/psycopg_pool/pool_async.py", line 170, in wait
    raise PoolTimeout(f"pool initialization incomplete after {timeout} sec")
psycopg_pool.PoolTimeout: pool initialization incomplete after 30.0 sec
 [uvicorn.error] api_revision=f2b62eb api_variant=local
2024-11-06T18:30:00.804185Z [error    ] Application startup failed. Exiting. [uvicorn.error] api_revision=f2b62eb api_variant=local

These are the installation commands, starting from a clean ArchLinux-base template with the admin user added and ssh enabled.

# Install prerequisites
sudo pacman -S git wget less python python-pip docker
sudo systemctl enable --now docker
sudo systemctl status docker

# Clone repo
cd && mkdir Github && cd Github
git clone https://github.com/langchain-ai/open-canvas/

# Update repo
cd && cd Github/open-canvas
git branch
git switch staging
git branch
git pull

# Install LangGraph-CLI
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -U langgraph-cli
langgraph dockerfile -c langgraph.json Dockerfile
docker build -t open-canvas .

# Install & run Redis: https://hub.docker.com/_/redis/
sudo docker run --name some-redis -d redis redis-server --save 60 1 --loglevel warning

# Install & run Postgres: https://hub.docker.com/_/postgres
sudo docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres

# Install & run Open-Canvas
touch .env
# Production: export LANGGRAPH_CLOUD_LICENSE_KEY="***************"
docker run \
    --env-file .env \
    -p 57318:8000 \
    -e REDIS_URI="redis://host.docker.internal:6379/0" \
    -e DATABASE_URI="postgresql://myuser:mypassword@host.docker.internal:5432/mydatabase" \
    -e LANGSMITH_API_KEY="lsv2_pt_*******************" \
    open-canvas

To eventually replicate exactly, this is my test LXC housekeeping before the above installation:

# On the PVE server, "Create CT" using archlinux-base template
# RAM=4GB+, CPU=1+, DISK=16GB+

# LXC  housekeeping, login as root:
pacman-key --init && pacman-key --populate
pacman -Sy archlinux-keyring --noconfirm && pacman -Su --noconfirm
sync && reboot

# Add admin account
pacman -S sudo --noconfirm      # In Debian: apt install sudo
useradd --create-home admin
passwd admin
usermod -aG wheel admin         # In Debian: use sudo instead of wheel

visudo
  # Uncomment to allow members of group wheel to execute any command
  %wheel ALL=(ALL:ALL) ALL      # In Debian: it's %sudo instead of %wheel

# Enable sshd
nano /etc/ssh/sshd_config
    PasswordAuthentication yes
systemctl enable --now sshd

# Get the IP address
ip a | grep 'inet ' 
echo $HOSTNAME

# Access via ssh from another computer
$ ssh admin@<hostname_or_ip>

sudo nano /etc/pacman.conf
  # Misc options
  #UseSyslog
  Color
  ILoveCandy
  #NoProgressBar
  #CheckSpace
  VerbosePkgLists
  ParallelDownloads = 5

sudo poweroff
# Backup now the fresh installation,
# then start the LXC.
lanesky commented 1 day ago

@PieBru Welcome!

Based on the error you posted, it looks like this is likely caused by a name resolution issue — meaning the connection to PostgreSQL failed because the hostname couldn’t be resolved.

2024-11-06T18:29:30.851005Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:31.931555Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:34.091808Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:38.409794Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:29:47.041806Z [warning  ] error connecting in 'pool-1': [Errno -2] Name or service not known [psycopg.pool] api_revision=f2b62eb api_variant=local
2024-11-06T18:30:00.804040Z [error    ] Traceback (most recent call last):
...
...
  File "/usr/local/lib/python3.12/site-packages/langgraph_storage/database.py", line 113, in start_pool
    await _pg_pool.open(wait=True)
...
...

Looking at the install commands you posted:

# Install & run Redis: https://hub.docker.com/_/redis/
sudo docker run --name some-redis -d redis redis-server --save 60 1 --loglevel warning

# Install & run Postgres: https://hub.docker.com/_/postgres
sudo docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres

I think the names for Redis and PostgreSQL in your environment variables should be some-redis and some-postgres respectively.

docker run \
    --env-file .env \
    -p 57318:8000 \
    -e REDIS_URI="redis://some-redis:6379/0" \
    -e DATABASE_URI="postgresql://postgres:mysecretpassword@some-postgres:5432/postgres" \
    -e LANGSMITH_API_KEY="lsv2_pt_*******************" \
    open-canvas