Install LibreChat using Unraid
March 22, 2024

Install LibreChat using Unraid

Comprehensive guide on how to install and setup LibreChat using the Unraid Community App


Install LibreChat using Unraid

Please be aware that this guide is specifically tailored for the LibreChat Unraid Community application. However, alternative installation methods for LibreChat on Unraid do exist, such as utilizing Portainer.

Intro

I just set this up the other day and this is the guide I wish I had.

Why do this? I assume a lot of us find ChatGPT useful, the audience here is likely programmers and it’s been helpful for my projects. But $21.50/mo (after taxes) is a steep monthly price for GPT 4 when my wife can’t also use it on her account and when I maybe send it 50 or so commands a month, sometimes going a full month not using it.

The API pricing

Here’s the OpenAI API pricing page it’s a bit confusing as it’s per 1M tokens. What are tokens? Honestly still not sure. But I do know that my average command uses about 500-800 tokens. The TL;DR is that at the time of writing I’ve found GPT 3.5 Turbo uses fractions of a penny per response, and GPT 4 Turbo uses about 1.5-2 cents per response. If you want to use DALL-E, it’s 4-12 cents per image depending on quality. (“Turbo” seems to be a version that’s “more powerful and cheaper”). This is in US Dollars, sorry, not sure about other currencies.

The one catch is they don’t bill you at the end of the month, you have to keep money in your account and use an auto-refill. The lowest you can set it is basically “when my wallet goes below $5, top off to $10”.

Setup Prerequisites

MongoDB

Go to the Community Apps store and search for MongoDB. I’m using the one maintained by Taddeusz. The default docker template is fine, no configuration needed, just note the port you use but the default is 27017. Install it, make sure to turn on autostart, and you’re set.

If you’re interested in poking around, once you open the console you can run mongosh to enter Mongo Shell. From there you can check out the MongoDB Manual for info on what to do. But a useful one is show dbs to see what databases exist. I’ll talk more about this later.

OpenAI API Key

If you have an OpenAI account, you can sign in on the OpenAI Developer Platform. You need a valid phone number to use the API. I believe they give you free credits, but long story short I didn’t get those.

On the left menu, go to Settings > Billing, to set up your payment method. As I mentioned previously, they’ll ask you how many credits you want to buy right now (minimum $5), at what threshold do you want to be charged (minimum $5), and how much do you want to top off to (minimum $10). I just set the minimums although I bought $10 from the start. I believe it takes you to a monthly limit screen, but if not, under Usage on the left menu, you can set your Monthly Limit. I set mine to $20. Once that threshold is hit, your API key stops working until the 1st of the next month.

To get your API key, just go to API Keys on the left menu, hit Create New Secret Key, and give it a name. I named mine “LibreChat” and gave it All permissions. Save this API Key in a password manager or something because you won’t be able to see it later, and once you enter it in your Docker Compose, you won’t easily be able to retrieve it.

Setup LibreChat

LibreChat is effectively a self hosted ChatGPT clone; it looks just like it. Here is the GitHub. It has support for almost every feature of the traditional ChatGPT site, but it stores all the accounts and messages in a MongoDB database and utilizes the API instead.

Go to Community Apps and search for LibreChat. At the time of writing there should only be one result, a container maintained by pureelectricity.

The Docker compose file is where this gets tricky, there’s a lot here. From top to bottom:

  • Port UI is just your Web UI port. I kept the default.

  • Crypto Key, Crypto Initialization Vector, JWT Secret, and JWT Refresh Secret.

    These 4 we get all at once and honestly I’m still not sure what they are. LibreChat recommend this Replit to generate them. In order to run it, you need to create an account. I created one with my GitHub Login and then just deleted it once I was done. It should be fairly self explanatory (I also don’t feel like making another account to write a more detailed guide), but once you run it, you’ll see an output with CREDS_KEY which you’ll put in Crypto Key, CREDS_IV which you’ll put in Crypto Initialization Vector, JWT_SECRET which you’ll put in JWT Secret, and JWT_REFRESH_SECRET which you’ll put in JWT Refresh Secret. Great, the hard part is done.

  • Back to MongoDB URI. Here you’ll put the location of your MongoDB instance in the following format: mongodb://ip:port/database. So since my server’s local IP is 192.168.1.100 and I kept it at the default port of 27017, I entered the following: mongodb://192.168.1.100:27017/librechat. But wait, I didn’t create a librechat database! That’s fine, it’ll create one for you. You can actually name this whatever you want, but librechat makes the most sense.

  • Moving on, Email From Address, Email Service Provider, Email Username, and Email Password I kept blank. They’re not required and I don’t know what they do exactly. I assume it’s for sending out emails during account creation, but unless you’re spinning this up for dozens of people, I wouldn’t worry about that stuff. My goal is just for my family to use it.

  • OpenAI API Key, enter your OpenAI key that you got earlier.

  • Enable Email Login set to true, Enable Email Registration set to true, Enable Social Login set to false, Enable Social Registration set to false. The app allows you to register or login via Email or Social (Google, GitHub, Discord, etc.) Once again, for my family just Email is fine. The account info saves to your local MongoDB instance, so you can enter a fake email upon registration if you even want. I’m assuming Social Login has more complexity and the potential for issues anyway.

  • Client Domain and Server Domain, I set both of these to my server’s local IP address, so 192.168.1.100. I assume if you’re running this through a reverse proxy, you’d set it to whatever domain you use such as librechat.mycoolserver.net or whatever.

  • Debug Logging Enabled default to False,

  • UID default of 1000, GID default of 1000.

Great! We’re all done and it should run just fine, inshallah.

Using LibreChat

The WebUI is very self explanatory. It seems like this is some live web app from OpenAI, but once again, this account stuff just saves to your MongoDB (I’ll show you that later). So hit “Sign up”, enter whatever fake or real info you want, then Login. Just note that it does regex your email field, so it has to have an @ and a ..

You should now be greeted with a very familiar screen if you’ve used ChatGPT. The only new things here are that in the header there’s a dropdown that might say gpt-3.5-turbo-1106 and upon clicking it, you get over a dozen options. The format of these models are essentially gpt-[major version]-[flavor]-[minor version]. As I mentioned previously, the turbo “flavors” or whatever you want to call them, are cheaper and apparently better. The ones that say vision have the ability to understand images, but may use a slightly older training data. Ones without a [minor version] will be using whatever latest minor version. I believe right now, gpt-3.5-turbo-1106 and gpt-3.5-turbo are the same model, for example.

The TL;DR is stick to gpt-3.5-turbo for extremely cheap, fractions of a penny, answers (this is the free model anyway), and stick to gpt-4-turbo-preview for better answers that cost about $0.015-$0.02 each, and use gpt-4-vision-preview if you want to ask it about understanding images (same price as prior). You can find detailed information about the models on the OpenAI Models Docs page.

There’s also a config button next to that drop down that I honestly haven’t messed around with, the only one to note is the “Image Detail” slider which is used for DALL-E.

To use DALL-E, click on the OpenAI drop down (left of the model drop down) and select “Plugins”. A new drop down will appear to the right of the model drop down that says “None selected”. Click that, click “Plugin store”, and search for DALL-E. DALL-E is cheap and produces pretty bad images for about $0.04 each. DALL-E 3 produces pretty impressive stuff for $0.12 each (1024x1024 pixels). Hit install, and it may prompt you for your OpenAI API Key again, enter that in. Now you can select DALL-E and prompt some images. I’m not too sure how the GPT version affects the images, I believe it’s just for understanding your prompt and relaying it to DALL-E. When an image is being generated you can click the DALL-E drop down that appears and it’ll show you what it prompted DALL-E with. And as mentioned, the Image Detail config will give you a lower or higher quality image, the higher the quality the more expensive the image.

Looking inside MongoDB (Optional)

This Docker doesn’t utilize an appdata folder or anything, everything is just stored in MongoDB. To check out what’s going on, open up your MongoDB Docker’s console and type mongosh to enter the MongoDB Shell. You should now see a test> input. From here we can type show dbs to see all our databases. Don’t worry about admin, config, or local, I don’t know what they do either. Type use librechat to enter our LibreChat database. Now we can type show tables to see our various tables (think like Excel tables). The interesting ones to note are that every message we send is stored in messages and every user is stored in users. I guess if you want to make sure your kid isn’t typing “generate boobs”, you can snoop in the messages table. To see inside a table just type db.[table].find() so for every user we type db.users.find(). Now if for some reason you wanted to delete a user, you would type db.[table].remove({ [criteria] }). So for example, I want to delete the user with the username ‘poop’. I would type db.users.remove({ username: 'poop' }) and hit enter. The only thing to note is I believe poop’s message and chat history will be persistent, unlinked data in other tables, but I wouldn’t worry about cleaning it up.

Conclusion

I hope this was helpful for someone! I can’t comment on how more or less secure this is, as always there’s concerns about generative AI privacy. If you’re inputting sensitive customer data into an AI model, you’re now training that model with that data and my understanding is that it could spit back out your data to someone else. Here’s an article. I’m not a professional, just a skeptic, so do your own research.

My main goal here was that both my wife and I can login to LibreChat, have our own users, and we can both enjoy using GPT 4 to do our grunt work without paying $21.50/month each even if we barely used it that month.

Bonus Section! (Assistants)

There’s an interesting feature on the OpenAI Developer Portal that I’ve been messing around with called “Assistants”. Here’s the docs for that. In order to get Assistants to appear in your LibreChat instance, edit your Docker compose file, toggle on Advanced View, then hit “Add another Path, Port, Variable, Label or Device”. I’ll just list it out:

  • Config Type: Variable
  • Name: Assistants API Key
  • Key: ASSISTANTS_API_KEY
  • Value: [Your OpenAI API Key (yes we’re entering it again)]
  • Default Value: [blank]
  • Description: [blank]
  • Display: Always
  • Required: No
  • Password Mask: Yes

That’s it! Assistants will appear as another option when you click on that OpenAI dropdown in the header, above Plugins.