Install LibreChat using Unraid
Comprehensive guide on how to install and setup LibreChat using the Unraid Community App
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 inCrypto Key
,CREDS_IV
which youâll put inCrypto Initialization Vector
,JWT_SECRET
which youâll put inJWT Secret
, andJWT_REFRESH_SECRET
which youâll put inJWT 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 is192.168.1.100
and I kept it at the default port of27017
, 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 totrue
, Enable Social Login set tofalse
, Enable Social Registration set tofalse
. 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 aslibrechat.mycoolserver.net
or whatever. -
Debug Logging Enabled default to
False
, -
UID default of
1000
, GID default of1000
.
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.