User Tools

Site Tools


computing:librechat

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
computing:librechat [2026/10/17 18:37] – oemb1905computing:librechat [2026/10/17 19:46] (current) – oemb1905
Line 13: Line 13:
 === Introduction === === Introduction ===
 ~~NOTOC~~ ~~NOTOC~~
-This is a tutorial for Debian users to setup Librechat and attach a custom API to it. I chose to use Deepinfra for cost and speed reasons, but/and used the open weight DeepSeek v4 Flash model via the Deepinfra API. I also built an MCP server to create docx, xlsx, pptx, and pdf files using python under the hood. Lastly, I used the built-in and free keenable service so that the chat could scrape websites. I've tested some common tasks that from other fully proprietary offerings and so far, so good. I prefer apache reverse proxies over nginx so I also included the vhost config I'm using, which includes the download directory for the MCP server and tooling. Librechat has two installation methods: npm or docker and I chose npm. Service management and systemd unit building is handled by pm2, an npm-based service manager that automatically cuts your systemd unit.+This is a tutorial for Debian users to setup Librechat and attach a custom API to it. I chose to use Deepinfra for cost and speed reasons, but/and used the open weight DeepSeek v4 Flash model via the Deepinfra API. I also built an MCP server to create docx, xlsx, pptx, and pdf files using python under the hood. Lastly, I used the built-in and free keenable service so that the chat could scrape websites.To begin with, let's install required dependencies, webserver, database, and service manager.
  
-===== 1. Prerequisites ===== +<code>
- +
-<code bash>+
 sudo apt update && sudo apt upgrade -y sudo apt update && sudo apt upgrade -y
 sudo apt install -y git build-essential curl gnupg python3-pip python3-venv sudo apt install -y git build-essential curl gnupg python3-pip python3-venv
-</code> 
- 
-==== Node.js 24 ==== 
  
-<code bash> 
 curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash - curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
 sudo apt install -y nodejs sudo apt install -y nodejs
 sudo npm install -g npm@11 sudo npm install -g npm@11
 node -v && npm -v node -v && npm -v
-</code> 
- 
-==== MongoDB 8.0 (Debian 13 uses Bookworm repo) ==== 
  
-<code bash> 
 wget -qO - https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg wget -qO - https://www.mongodb.org/static/pgp/server-8.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg
 echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
Line 39: Line 29:
 sudo apt install -y mongodb-org sudo apt install -y mongodb-org
 sudo systemctl enable --now mongod sudo systemctl enable --now mongod
-</code> 
- 
-==== PM2 ==== 
  
-<code bash> 
 sudo npm install -g pm2 sudo npm install -g pm2
 </code> </code>
  
-===== 2. Install LibreChat =====+Now, let's clone the librechat repo and setup the virtual environment and the server configuration.
  
-<code bash>+<code>
 cd /opt cd /opt
 sudo git clone https://github.com/LibreChat-AI/LibreChat.git sudo git clone https://github.com/LibreChat-AI/LibreChat.git
Line 58: Line 44:
 </code> </code>
  
-Essential ''.env'' values:+Email and other add-ons and other niceties and such can all be set up later to one's liking and as they see fit. The bare bones requirements are:
  
-<code env>+<code>
 MONGO_URI=mongodb://127.0.0.1:27017/LibreChat MONGO_URI=mongodb://127.0.0.1:27017/LibreChat
  
Line 74: Line 60:
 HOST=127.0.0.1 HOST=127.0.0.1
  
 +# This creates an env variable for your deepinfra key, which gets called in librechat.yaml
 DEEPINFRA_API_KEY=sk-di-your_key_here DEEPINFRA_API_KEY=sk-di-your_key_here
 </code> </code>
  
-Generate secrets with ''openssl rand -hex 32'' (and ''openssl rand -hex 16'' for the IV).+Use ''openssl rand -hex 32'' and ''openssl rand -hex 16'' for the IV in order to generate secrets. Start service for first time and debug. Once it is functional and working - not before - then run the pm2 commands which will auto-generate systemd units and give you control of them with pm2 commands.
  
-<code bash>+<code>
 npm run reinstall npm run reinstall
-npm run backend          # test once, then Ctrl+C+npm run backend #test, debug, then use pm2 instead       
 pm2 start npm --name librechat -- run backend pm2 start npm --name librechat -- run backend
 pm2 save pm2 save
-pm2 startup              # follow the printed command+pm2 startup          
 </code> </code>
  
-===== 3. Apache Reverse Proxy + HTTPS =====+You can optionally setup a firewall:
  
-==== Modules ====+<code> 
 +sudo ufw allow OpenSSH 
 +sudo ufw allow 'Apache Full' 
 +sudo ufw enable 
 +</code> 
 + 
 + 
 +Create or edit ''/opt/LibreChat/librechat.yaml'': 
 + 
 +<code> 
 + 
 +# minimum information and parameters 
 +version: 1.3.17 
 +cache: true 
 + 
 +endpoints: 
 +  custom: 
 +    - name: "DeepInfra DeepSeek" 
 +      apiKey: "${DEEPINFRA_API_KEY}" 
 +      baseURL: "https://api.deepinfra.com/v1/openai" 
 +      models: 
 +        default: ["deepseek-ai/DeepSeek-V4-Flash"] 
 +        fetch: false 
 +      titleConvo: true 
 +      titleModel: "deepseek-ai/DeepSeek-V4-Flash" 
 +      modelDisplayLabel: "DeepSeek V4 Flash" 
 + 
 +# this is a built in and free in cost web scraper  
 +webSearch: 
 +  searchProvider: "keenable" 
 +  scraperProvider: "keenable" 
 +  rerankerType: "none" 
 + 
 +# don't add this block until after initial setup and when you later create the mcp server 
 +mcpServers: 
 +  document-tools: 
 +    type: stdio 
 +    command: /opt/mcp-docs/venv/bin/python 
 +    args: 
 +      - /opt/mcp-docs/server.py 
 +    timeout: 60000 
 +</code> 
 + 
 +pm2 restart librechat 
  
-<code bash>+Once librechat is running properly under pm2, the next most important step is setting up the apache reverse proxy and setting up the admin account. I just use the default apache virtual host for the domain, let apache cut and generate the cert using the non-RP vhost config, and then once the librechat service is running locally, I swap the virtual hosts with the reverse proxy versions instead and then restart the service. Here are the packages and the cert cutting commands: 
 + 
 +<code>
 sudo a2enmod proxy proxy_http proxy_wstunnel ssl rewrite headers socache_shmcb sudo a2enmod proxy proxy_http proxy_wstunnel ssl rewrite headers socache_shmcb
 sudo systemctl restart apache2 sudo systemctl restart apache2
 +sudo apt install certbot letsencrypt python3-certbot-apache
 +sudo certbot --authenticator standalone --installer apache -d chat.haacksnetworking.org --pre-hook "systemctl stop apache2" --post-hook "systemctl start apache2"
 </code> </code>
  
-==== Certificate ====+Here is your http vhost ''nano /etc/apache2/sites-available/chat.haacksnetworking.org.conf''
  
-<code bash> +<code> 
-sudo apt install -y certbot python3-certbot-apache +<VirtualHost *:80> 
-sudo certbot --apache -d chat.haacksnetworking.org+    ServerName chat.haacksnetworking.org 
 +    Redirect permanent / https://chat.haacksnetworking.org/ 
 +</VirtualHost>
 </code> </code>
  
-==== VirtualHost ====+Here is your https vhost ''nano /etc/apache2/sites-available/chat.haacksnetworking.org-le-ssl.conf''
  
-<code apache>+<code>
 <VirtualHost *:443> <VirtualHost *:443>
     ServerName chat.haacksnetworking.org     ServerName chat.haacksnetworking.org
Line 116: Line 152:
     ProxyRequests Off     ProxyRequests Off
  
-    # Exclude downloads from proxy (must come before ProxyPass /)+    # Exclude downloads from proxy - must come before ProxyPass / 
 +    # You create this down below for MCP downloads
     ProxyPass /downloads !     ProxyPass /downloads !
     Alias /downloads /opt/LibreChat/generated_docs     Alias /downloads /opt/LibreChat/generated_docs
Line 143: Line 180:
     ErrorLog ${APACHE_LOG_DIR}/librechat-error.log     ErrorLog ${APACHE_LOG_DIR}/librechat-error.log
     CustomLog ${APACHE_LOG_DIR}/librechat-access.log combined     CustomLog ${APACHE_LOG_DIR}/librechat-access.log combined
-</VirtualHost> 
- 
-<VirtualHost *:80> 
-    ServerName chat.haacksnetworking.org 
-    Redirect permanent / https://chat.haacksnetworking.org/ 
 </VirtualHost> </VirtualHost>
 </code> </code>
  
-<code bash>+Once you swap the vhosts with the reverse proxy configs you enable the vhosts, check the config, and reload the latest apache2 config for the currently running service. 
 + 
 +<code>
 sudo a2ensite librechat sudo a2ensite librechat
 sudo apache2ctl configtest sudo apache2ctl configtest
Line 157: Line 191:
 </code> </code>
  
-==== Firewall ====+You can now go to your domain.com in your web browser and setup your admin account. Make sure to verify it with mongodb on the backend. After setting up the account, run
  
-<code bash> +<code> 
-sudo ufw allow OpenSSH +mongosh --quiet --eval 'db = db.getSiblingDB("LibreChat"); db.users.find({}, {email:1, role:1}).pretty()'
-sudo ufw allow 'Apache Full' +
-sudo ufw enable+
 </code> </code>
  
-===== 4. librechat.yaml (DeepSeek + Web Search + MCP) =====+If you want to disable public registration, add the following to ''/opt/LibreChat/.env'':
  
-Create or edit ''/opt/LibreChat/librechat.yaml'': +<code> 
- +ALLOW_REGISTRATION=false
-<code yaml> +
-version: 1.3.17 +
-cache: true +
- +
-endpoints: +
-  custom: +
-    - name: "DeepInfra DeepSeek" +
-      apiKey: "${DEEPINFRA_API_KEY}" +
-      baseURL: "https://api.deepinfra.com/v1/openai" +
-      models: +
-        default: ["deepseek-ai/DeepSeek-V4-Flash"] +
-        fetch: false +
-      titleConvo: true +
-      titleModel: "deepseek-ai/DeepSeek-V4-Flash" +
-      modelDisplayLabel: "DeepSeek V4 Flash" +
- +
-webSearch: +
-  searchProvider: "keenable" +
-  scraperProvider: "keenable" +
-  rerankerType: "none" +
- +
-mcpServers: +
-  document-tools: +
-    type: stdio +
-    command: /opt/mcp-docs/venv/bin/python +
-    args: +
-      - /opt/mcp-docs/server.py +
-    timeout: 60000+
 </code> </code>
  
-===== 5. MCP Document-Tools Server (docx, xlsx, pdf, pptx) =====+Then create users with ''npm run create-user'' and just enter the parameters and restart the service. Once you are logged in, select the model you attached in the upper left drop down menu and test it for functionality. So long as it is working, you can now move on to creating an mcp server to do some common tasks like create docx, xlsx, pptx, and pdf files. Here's what I came up with:
  
-<code bash>+<code>
 cd /opt cd /opt
 mkdir -p /opt/mcp-docs mkdir -p /opt/mcp-docs
Line 210: Line 214:
 </code> </code>
  
-Create ''/opt/mcp-docs/server.py'':+Create ''/opt/mcp-docs/server.py'' and create python programs that do the various tasks on the host/vm running librechat: 
  
-<code python>+<code>
 #!/usr/bin/env python3 #!/usr/bin/env python3
 import json import json
Line 390: Line 394:
 </code> </code>
  
-<code bash>+<code>
 chmod +x /opt/mcp-docs/server.py chmod +x /opt/mcp-docs/server.py
 mkdir -p /opt/LibreChat/generated_docs mkdir -p /opt/LibreChat/generated_docs
 deactivate deactivate
-</code> 
- 
-Restart LibreChat: 
- 
-<code bash> 
 pm2 restart librechat pm2 restart librechat
 </code> </code>
  
-===== 6. Using the Tools =====+The python above is 4 programs that do each of the various tasks of creating doc files, spreadsheets, powerpoints, and pdfs. You can customize names to your preference. I have not gotten to the point of needing to update yet, but/and the barebones update pathway would be something like this:
  
-  * In a chat, open the tools / MCP menu. +<code>
-  * Add or enable the **document-tools** MCP server. +
-  * Ask for a document. Available tools: +
-    * ''create_docx'' — Word +
-    * ''create_xlsx'' — Excel +
-    * ''create_pdf'' — PDF +
-    * ''create_pptx'' — PowerPoint +
- +
-Example prompts: +
- +
-  * "Create a Word document titled 'Solar System' with paragraphs and bullets about the planets. Give me the download link." +
-  * "Make an Excel file named 'Employees' with headers Name, Department, Salary and three sample rows." +
-  * "Create a PDF titled 'Monthly Report' with a heading and a few paragraphs." +
-  * "Create a PowerPoint titled 'Project Update' with slides for Goals, Progress, and Next Steps." +
- +
-Files appear at ''https://chat.haacksnetworking.org/downloads/...''. +
- +
-===== 7. Admin and Registration ===== +
- +
-First account is admin. Verify: +
- +
-<code bash> +
-mongosh --quiet --eval 'db = db.getSiblingDB("LibreChat"); db.users.find({}, {email:1, role:1}).pretty()' +
-</code> +
- +
-To disable public registration, add to ''.env'': +
- +
-<code env> +
-ALLOW_REGISTRATION=false +
-</code> +
- +
-Then create users with ''npm run create-user''. +
- +
-===== 8. Updates ===== +
- +
-<code bash>+
 cd /opt/LibreChat cd /opt/LibreChat
 pm2 stop librechat pm2 stop librechat
Line 447: Line 411:
 </code> </code>
  
-===== Quick Checklist ===== + --- //[[alerts@haacksnetworking.org|oemb1905]] 2026/10/17 19:44//
- +
-  1. Node 24 + MongoDB (Bookworm repo) +
-  2. Clone → ''.env'' (secrets, domains, HOST, DeepInfra key) → ''npm run reinstall'' +
-  3. PM2 +
-  4. Apache modules + Certbot + VirtualHost (with ''ProxyPass /downloads !'' + Alias) +
-  5. ''librechat.yaml'' (DeepSeek + webSearch + mcpServers) +
-  6. MCP server in ''/opt/mcp-docs'' with docx / xlsx / pdf / pptx tools +
-  7. Restart LibreChat and enable the document-tools MCP server in chat +
- +
-**This is the full working configuration.** +
- +
- --- //[[alerts@haacksnetworking.org|oemb1905]] 2026/10/17 18:31// +
- +
-```+
computing/librechat.1792262277.txt.gz · Last modified: by oemb1905