HostedGPT is a free, open-source alternative to ChatGPT. It's a Ruby on Rails app so you can run it on any server or even your own computer. Just bring your own OpenAI API key.
This app is designed to be incredibly easy for ChatGPT users to switch. All the features you expect are here plus it supports Claude 3 and GPT-4 in a single app. You can also switch assistants in the middle of a conversation!
This project is led by an experienced rails developer, but I'm actively looking for contributors to help!
- Use GPT-4 and Claude 3 without two $20 / month subscriptions, you don't even need a single $20 subscription! You only pay as much as you use. The HostedGPT app is free so you just pay for your GPT-4 and Claude 3 API usage.
- A very polished interface with great mobile support You can "install" on your mobile phone by opening your instance of HostedGPT in your Safari browser, tapping the Share icon, and then selecting "Add to Home Screen".
- You will never hit the 'You've reached the current usage cap' errors.
- Top features of HostedGPT
- Table of Contents
- Deploy the app on Render
- Deploy the app on Fly.io
- Deploy the app on Heroku
- Deploy on your own server
- Configure optional features
- Contribute as a developer
- Understanding the Docker configuration
- Changelog
For the easiest way to get started, deploy a full version of HostedGPT to the hosting service, Render, for free. This free app works for 90 days and then the database will stop working. You will need to upgrade to a paid version of the database which is $7 / month. Alternatively, you can also run it off your local computer. Jump down to the Developer Instructions if you want to run it locally.
-
Click Fork > Create New Fork at the top of this repository
-
Create an account on Render.com and login. If you are new to Render, you may be prompted to add a credit card to your account. However, you will be on their free plan by default unless you choose to upgrade.
-
View your newly created fork within github.com and click the button below (be sure you're viewing your fork of this repo before clicking):
-
In Blueprint Name, type anything such as "hostedgpt-"
-
Click Apply
-
Wait for the hostedgpt database and web service to be deployed. The first deploy takes a good 5 minutes so be patient. After they are all deployed, click Dashboard at the top of the Render screen. Or if an error occurs, skip to Troubleshooting Render below.
-
You should see two "Service Names" called "hostedgpt-..." (the name you picked), click the one that is of type Web Service
-
On the details screen, click the URL that looks something like hostedgpt-XXX.onrender.com
NOTE: After 15 minutes of not using the app your Render server will pause. Next time you visit the first request will auto-resume the server, but this resume is slow. If this annoys you, upgrade Render for $7 per month:
- To upgrade, go to your Render Dashboard
- Click "HostedGPT" or whatever you named your Web Service
- Click "Upgrade" and select $7 per month
You may want to read about configuring optional features.
If you encountered an error while waiting for the services to be deployed on Render:
- Login to your account on Render.com and click Dashboard at the top then click the Service that failed.
- It should take you to the Events section and the top event should explain the error. It will probably contain a link to click to the deploy logs
- Scroll back up through the logs and find any instances of errors. Start a new discussion and share details.
- When you are ready to try Render again, it's best to do the following:
- First, ensure your repo is caught up. Open your fork in github, click the Sync Fork button so that any bug fixes are pulled in.
- Second, in Render navigate to the Dashboard, Bluebrint, and Env Groups and delete any details associated with hostedgpt
- Now you can go back to your repo and click Deploy to Render
Deploying to Fly.io is another great option. It's not quite one-click like Render and it's not 100% free. But we've made the configuration really easy for you and the cost should be about $2 per month, and Render costs $7 per month after 90 days of free service so Fly is actually less expensive over the long term.
-
Click Fork > Create New Fork at the top of this repository. Pull your forked repository down to your computer (the usual git clone ...).
-
Install the Fly command-line tool on Mac with
brew install flyctl
otherwisecurl -L https://fly.io/install.sh | sh
(view instructions) -
Think of an internal Fly name for your app, it has to be unique to all of Fly, and then in the root directory of the repository you pulled down, run
fly launch --build-only --copy-config --name=APP_NAME_YOU_CHOSE
- Say "Yes" when it asks if you want to tweak these settings
-
When it opens your browser, change the Database to
Fly Postgres
with a unique name such as[APP_NAME]-db
and you can set the configuration toDevelopment
. -
Click
Confirm Settings
at the bottom of the page and close the browser. -
The app will do a bunch of build steps and then return to the command line. Scroll through the output and save the Postgres username & password somewhere as you'll never be able to see those again.
-
Next run
bin/rails db:setup_encryption[true]
. This will initialize some private keys for your app and send them to Fly. -
Run
fly deploy --ha=false
-
Assuming you chose
Development
as the DB size in the step above, now you should runbin/rails db:fly[APP_NAME_FROM_EARLIER,swap,512]
This will increase the swap on your database machine so that it doesn't crash.
You may want to read about configuring optional features.
Heroku is a one-click option that will cost $10/month for the compute (dyno) and database. By default, apps use Eco dynos ($5) if you are subscribed to Eco. Otherwise, it defaults to Basic dynos ($7). The Eco dynos plan is shared across all Eco dynos in your account and is recommended if you plan on deploying many small apps to Heroku. Eco dynos "sleep" after 30 minutes of inactivity and take a few seconds to wake up. Basic dynos do not sleep.
Eligible students can apply for Heroku platform credits through Heroku for GitHub Students program.
-
Click Fork > Create New Fork at the top of this repository
-
Sign up for a free Heroku account at heroku.com
-
If you wish to Eco dynos, you will need to subscribe to the $5 Eco dyno plan at the billing page.
-
View your newly created fork within github.com and click the button below (be sure you're viewing your fork of this repo before clicking):
You may want to read about configuring optional features.
There are only two services that need to be running for this app to work: the Puma web server and a Postgres database.
First, ensure your Postgres server is running and verify your connection string using psql
, for example:
Example:
psql postgres://app:secret@postgres/hostedgpt_production
Take this DB connection string and start your rails server like this:
RAILS_ENV=production RUN_SOLID_QUEUE_IN_PUMA=true DATABASE_URL=postgres://string-you-verified-above rails s -p 8081
Note: You can change the port 8081 to anything you want.
If you are running a proxy such as nginx, be aware that the app is running http and websockets (ws). Here is an example of what your configuration might look like in order to proxy both of those:
<VirtualHost *:443>
ServerName chat.${maindomain}
ServerAlias chat.${secondarydomain}
ProxyPreserveHost On
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/
RequestHeader set X-Forwarded-Proto "https"
<Location /cable>
ProxyPreserveHost On
ProxyPass ws://localhost:8081/cable
ProxyPassReverse ws://localhost:8081/cable
</Location>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/chat.${maindomain}/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/chat.${maindomain}/privkey.pem
</VirtualHost>
There are a number of optional feature flags that can be set and settings that can be configured. All of these can be seen in the file options.yml
, however each is explained below and can be activated by setting environment variables.
PRODUCTION_HOST
is blank but you should ideally set this if you are deploying the app with a public domain to protect against host header attacks. For example, set it toexample.com
(leave off https). You may add multiple host names separated by comma,example.fly.dev, example.com
(whitespace is ignored).REGISTRATON_FEATURE
istrue
by default, but you can set tofalse
to prevent any new people from creating an account.DEFAULT_LLM_KEYS
isfalse
by default so each user is expected to add LLM API keys to their user settings. Set this totrue
if you want to configure LLM API keys that will be shared by all users. Set one or more of the additional variables in order to use this feature. The app will still check if the user has added their own API keys for any services and will use those instead of the default ones.DEFAULT_OPENAI_KEY
will be used by the pre-configured OpenAI API ServiceDEFAULT_ANTHROPIC_KEY
will be used by the pre-configured Anthropic API ServiceDEFAULT_GROQ_KEY
will be used by the pre-configured Groq API Service
CLOUDFLARE_STORAGE_FEATURE
isfalse
by default so any files that are uploaded while chatting with your assistant will be stored in postgres. This is recommended for small deployments. Set this totrue
if you would like to store message attachments in Cloudflare's R2 storage (this mimics AWS S3). You must also sign up for Cloudflare. The free tier allows 10 GB of storage. After you sign up, you need to create a new bucket and an API token. The API token should have "Object Read and Write" access to your bucket. Take note of your Access Key ID and your Secret Access Key along with your Account ID. Set the following environment variables:CLOUDFLARE_ACCOUNT_ID
- Your Cloudflare Account IDCLOUDFLARE_ACCESS_KEY_ID
- Your Cloudflare Access Key IDCLOUDFLARE_SECRET_ACCESS_KEY
- Your Cloudflare Secret Access KeyCLOUDFLARE_BUCKET
- The name of the bucket you created
GOOGLE_TOOLS_FEATURE
isfalse
by default because this feature is still in development. Set this totrue
if you would like to try the experimental feature where your assistant can access your Gmail, Google Tasks, and soon Google Calendar. After enabling, you need to set up Google OAuth and include the apps as part of the consent flow. See Configure Google Tools. After this is done, when each user goes to Settings within the app, there will be a button to explicitly connect their account to Gmail, Google Tasks, and/or Google Calendar. Reviewgmail.rb
andgoogle_tasks.rb
in the directoryapp/services/toolbox/
to see what capabilities have currently been built.VOICE_FEATURE
isfalse
by default. This is an experimental feature to have spoken conversation with your assistant. It's still a bit buggy but it's coming along.PASSWORD_AUTHENTICATION_FEATURE
istrue
by default, see the Authentication section for more details.GOOGLE_AUTHENTICATION_FEATURE
isfalse
by default, see the Authentication section for more details.HTTP_HEADER_AUTHENTICATION_FEATURE
isfalse
by default. If this is set totrue
it automatically disables Password and Google Authentication Features. See the Authentication section for more details.
You first need to follow all the steps in the Google OAuth instructions. The only step that is optional is that you can leave GOOGLE_AUTHENTICATION_FEATURE
set to false, which means you don't have to enable new users to register with Google. However, following all the steps will also set up Google Auth so you can connect Google Tools to your assistants. After, you complete those steps, here is the additional configuration you need to do in order to enable the Google tools:
-
Go back to the OAuth Consent Screen:
- In the navigation menu, go to "APIs & Services" > "OAuth consent screen" > click Edit App
- It starts you on "OAuth consent screen" which is already done, at the bottom click "Save and Continue" to advance to "Scopes"
- Click "Add or Remove Scopes", check "userinfo.email" and then in "Manually add scopes" paste these URLs, one at a time:
- https://www.googleapis.com/auth/gmail.modify (then click "Add To Table")
- https://www.googleapis.com/auth/tasks (then click "Add To Table")
-
Finally, set
GOOGLE_TOOLS_FEATURE
to true
HostedGPT supports multiple authentication methods:
Password authentication is enabled by default. You can disable it by setting PASSWORD_AUTHENTICATION_FEATURE
to false
.
Google OAuth authentication is disabled by default. You can enable it by setting GOOGLE_AUTHENTICATION_FEATURE
to true
.
To enable Google OAuth authentication, you need to set up Google OAuth in the Google Cloud Console. It's a bit involved but we've outlined the steps below. After you follow these steps you will set the following environment variables:
GOOGLE_AUTH_CLIENT_ID
- Google OAuth client IDGOOGLE_AUTH_CLIENT_SECRET
- Google OAuth client secret
Steps to set up:
-
Go to the Google Cloud Console and Create a New Project:
- Open your web browser and navigate to Google Cloud Console.
- Click on the project drop-down menu at the top of the page.
- Select "New Project"
- Enter a name for your project and click "Create"
-
Create OAuth Consent Screen:
- In the navigation menu, go to "APIs & Services" > "OAuth consent screen"
- If you want to restrict this to users in your Google Workspace, select "Internal". If you want to let people use any Google account, select "External", and then click "Create"
- Fill out the required fields (App name, User support email, etc.).
- Add your domain and authorized domains.
- Click "Save and Continue"
- Leaves Scopes blank and click "Save and Continue"
- On the "Test Users" screen you can enter a few email address that you want to test with, then "Save and Continue"
-
Create OAuth Credentials:
- In the navigation menu, go to "APIs & Services" > "Credentials"
- Click on "Create Credentials" and select "OAuth client ID"
- Choose "Web application" as the application type.
- Fill out the required fields:
- Name: A descriptive name for your client ID, e.g. "HostedGPT"
- Authorized JavaScript origins: Your application's base URL, e.g.,
https://example.com
- Authorized Redirect URIs: Add these paths but replace the base URL with yours:
https://example.com/auth/google/callback
https://example.com/auth/gmail/callback
- Click "Create"
-
Set Environment Variables:
- After creating the credentials, you will see a dialog with your Client ID and Client Secret.
- Set the Client ID and Client Secret as environment variables in your application:
GOOGLE_AUTH_CLIENT_ID
: Your Client IDGOOGLE_AUTH_CLIENT_SECRET
: Your Client Secret
Note: Enabling this automatically disables Password-based and Google-auth based authentication.
HTTP header authentication is an alternative method to authenticate users based on custom HTTP request headers. This method is useful when you have an existing authentication system, and you want to direct users to HostedGPT and have them skip all authentication steps. They'll be taken right into the app and a HostedGPT user account will be created on the fly. This works by having your existing system set custom headers for authenticated users. This may be a Reverse Proxy (e.g., Traefik or Caddy) or a Zero Trust Network (e.g., Tailscale).
Steps to set up:
-
Enable the feature:
- Since HTTP header authentication is disabled by default set the environment variable
HTTP_HEADER_AUTHENTICATION_FEATURE
totrue
. This will automatically disable password and Google OAuth authentication methods.
- Since HTTP header authentication is disabled by default set the environment variable
-
Configure the request headers:
- Beware: enabling HTTP header authentication will allow anyone with direct access to the application to impersonate any user by setting the custom headers, if not properly secured. You must ensure that the custom headers are set by a trusted source and are not easily spoofed.
- Configure your authentication system to set the following request headers when directing users to the HostedGPT app:
HTTP_HEADER_AUTH_EMAIL
- Set this environment variable to the name of the HTTP request header which will contain the user's email address. This defaults to a check for a request header ofX-WEBAUTH-EMAIL
to find the user's email.HTTP_HEADER_AUTH_NAME
- Set this environment variable to the name of the HTTP request header which will contain the user's full name (first and last). This defaults to a check for a request header ofX-WEBAUTH-NAME
to find the user's full name.HTTP_HEADER_AUTH_UID
- Set this environment variable to the name of the HTTP request header which will contain the user's identifier (any unique alphanumeric string). This defaults to a check for a request header ofX-WEBAUTH-USER
to find the user's unique ID.
-
Test the connection:
- After you complete the configuration changes above and restart your server, however you direct users to the HostedGPT app you need to be sure that the request headers are present in that initial visit. This will do a find_or_create on the user: so it will register them if they've never been seen and log them in as that user if the information is already present.
We welcome contributors! After you get your development environment setup, review the list of Issues. We organize the issues into Milestones and are currently wrapping up v0.7 and starting 0.8 View 0.8 Milestone. Look for any issues tagged with Good first issue and add a comment so we know you're working on it.
The easiest way to get up and running is to use the provided Docker compose workflow. The only things you need installed on your computer are Docker and Git.
- Make sure you have Docker Desktop installed and running
- Clone your fork
git clone [repository url]
cd
into your clone- Run
docker compose up --build
to start the app - Open http://localhost:3000 and register as a new user
- Run tests:
docker compose run base rails test
The app has comprehensive test coverage but note that system tests currently do not work in docker. - Open the rails console:
docker compose run base rails console
- Run a psql console:
docker compose run base psql
- If you want a few fake users and a bunch of conversations and other data pre-populated in the database, you can load fixtures into the development database. This can be helpful, for example, if you want to test a migration and save yourself the time manually creating a bunch of data:
docker compose run base rails db:fixtures:load
- The project root has an
.editorconfig
file to help eliminate whitespace differences in pull requests. It's nice if you install an extension in your IDE to utilize this (e.g. VS Code has "EditorConfig for VS Code").
Every time you pull new changes down, kill docker (if it's running) and re-run:
docker compose up --build
This will ensure your local app picks up changes to Gemfile, migrations, and docker config.
HostedGPT requires these services to be running:
- Postgres (installation instructions)
- rbenv (installation instructions)
- ImageMagick (
brew install imagemagick
should work on Mac )
cd
into your local repository clonerbenv install
to install the correct ruby version (it reads the .ruby-version in the repo)bin/dev
starts up all the services, installs gems, and inits database (don't run db:setup as it will not configure encryption properly)- Open http://localhost:3000 and register as a new user
bin/rails test
andbin/rails test:system
to run the comprehensive tests- The project root has an
.editorconfig
file to help eliminate whitespace differences in pull requests. It's nice if you install an extension in your IDE to utilize this (e.g. VS Code has "EditorConfig for VS Code"). - If you want a few fake users and a bunch of conversations and other data pre-populated in the database, you can load fixtures into the development database. This can be helpful, for example, if you want to test a migration and save yourself the time manually creating a bunch of data:
bin/rails db:fixtures:load
Every time you pull new changes down, kill bin/dev
and then re-run it. This will ensure your local app picks up changes to Gemfile and migrations.
If you're set up with Docker you run docker compose run base rails test
. Note that the system tests, which use a headless browser, are not able to run in Docker. They will be run automatically for you if you create a Pull Request against the project.
If you set up the app outside of Docker, then run the usual bin/rails test
and bin/rails test:system
.
The Dockerfile
is set up to support three distinct situations: development, deploying to Render, and deploying to Fly. Each of these are completely separate targets which don't share any steps, they are simply in the same Dockerfile.
The docker-compose.yml
is solely for development. It references the development
build target.
The render.yml
specifies details of the Render production environment. Note that Render does not support specifying a build target within this file, it simply defaults to the last target with the Dockerfile so the order of the sections within there matter.
The fly.toml
specifies details of the Fly production environment. It references the fly-production
build target. The Fly section of the Dockerfile was generated using the dockerfile-rails generator. This is Fly's recommendation and it produces a reasonable production-ready Dockerfile. Edits to this top section of the file have been kept very minimal, on purpose, because it's intended to be updated using the generator. When it was originally generated it saved all the configuration parameters into config/dockerfile.yml
. When you run bin/rails generate dockerfile
it will read all these configurations and attempt to re-generate the Dockerfile. You can try this, it will warn you that it's going to overwrite, and press d
to see the diff of what changes it will make. There should be no functional changes above the line #### END of FLY ####
. Imagine you wanted to use this generator to change the app to use MySQL (view all generator options). You could run bin/rails generate dockerfile --mysql
and it would update your Gemfile, automatically run bundle install to install any gem changes, and then it will attempt to update Dockerfile where you can again press d
. Inspect the diff of any changes above the line #### END of FLY ####
and manually apply those changes. Similarly, view the diff for dockerignore and docker-entrypoint, although none of those changes should be necessary. When you get to fly.toml
you will want to view that diff closely and manually apply those changes. At the end it will update config/dockerfile.yml to record the new configuration of the Dockerfile. In this way, you can continue to use the generator to keep the Dockerfile updated (as recommended by Fly) while not breaking the dev or Render setup.
(Notable features being developed for v0.7: Heroku deploy, voice support, skills for the AI, Gemini Pro, pin conversations)
v0.6 - Released on 4/26/2024
- Abort a long AI reply by clicking stop or simply "interrupting" it with a new question
- Edit your messages and view previous versions with the left & right arrows
- Support PWA (progressive web app) install for mobile phones (open in Safari, tap share then "Add to Home")
- Show a helpful error messages when the API responds with an error
- Re-generate an AI responses and even switch to a different assistant
- Copy-to-clipboard button (and keyboard shortcut) for messages and markdown sections
- Markdown is properly rendered in AI responses (and your own chats)
- Include images in your messages (click icon, drag & drop, or copy & paste into message)
v0.5 - Released on 2/14/2024
- Anthropic's Claude 3 models can be used alongside GPT-4 and GPT-3
- Dark mode theme is now supported (it switches automatically with your OS)
- Full keyboard shortcuts have been added (press ? to see them)
- AI assistants can be given custom instructions (under Profile > Settings)
- Delete conversations
- Ability to edit conversation title
- Conversations are automatically titled
- Sidebar can be closed
- AI responses stream in