ChatGPT at home! Basically a better Google Nest Hub or Amazon Alexa home assistant. Built on the Raspberry Pi using the OpenAI API.
This guide will explain how to build your own. It's pretty straight forward. You can also use this as a reference for building other projects on the Raspberry Pi.
|
|
echo "export OPENAI_API_KEY='your_api_key_here'" >> ~/.bashrc && source ~/.bashrc
LITELLM_API_KEY
. See the LiteLLM docs for a list of all supported providers.echo "export LITELLM_API_KEY='your_api_key_here'" >> ~/.bashrc && source ~/.bashrc
--no-build
flag to pull the latest image from DockerHub:curl -s https://raw.githubusercontent.com/judahpaul16/gpt-home/main/contrib/setup.sh |
bash -s -- --no-build
IMPORTANT: The image on the left is for illustration purposes. Do not connect the battery directly to the Raspberry Pi. Use a UPS or power supply with a battery like this one. Connecting the battery directly to the Raspberry Pi can cause damage to the board from voltage fluctuations.
Before connecting the battery, ensure that the polarity is correct to avoid damage to your Raspberry Pi or other components. Disconnect power sources before making changes.
![]() |
![]() |
This is the list of parts I used to build my first GPT Home. You can use this as a reference for building your own. I've also included optional parts that you can add to enhance your setup. To be clear you can use any system that runs Linux.
Core Components
Optional Components
To configure Wi-Fi on your Raspberry Pi, you'll need to edit the wpa_supplicant.conf
file and ensure the wireless interface is enabled at boot. This method supports configuring multiple Wi-Fi networks and is suitable for headless setups.
You could also use the raspi-config
or the nmcli
utility to configure Wi-Fi; or simply use an Ethernet connection if you prefer.
Step 1: Create the Bash Script
sudo nano /usr/local/bin/start_wifi.sh
Add the following content to the script:
#!/bin/bash
# Set the interface and SSID details
INTERFACE="wlan0"
SSID="your_wifi_ssid"
PASSWORD="your_wifi_password"
# Make sure no previous configuration interferes
sudo killall wpa_supplicant
sudo dhcpcd -x $INTERFACE
# Ensure the wireless interface is up
sudo ip link set $INTERFACE up
# Create a wpa_supplicant configuration file
WPA_CONF="/etc/wpa_supplicant/wpa_supplicant.conf"
wpa_passphrase "$SSID" "$PASSWORD" | sudo tee $WPA_CONF > /dev/null
# Start wpa_supplicant
sudo wpa_supplicant -B -i $INTERFACE -c $WPA_CONF
# Obtain an IP address
sudo dhcpcd $INTERFACE
Make sure to replace your_wifi_ssid
and your_wifi_password
with your actual WiFi network's SSID and password.
Step 2: Make the Script Executable
sudo chmod +x /usr/local/bin/start_wifi.sh
Step 3: Create a Systemd Service File
sudo nano /etc/systemd/system/start_wifi.service
Add the following content to the service file:
[Unit]
Description=Start WiFi at boot
After=network.target
[Service]
ExecStart=/usr/local/bin/start_wifi.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
Step 4: Reload Systemd and Enable the Service
sudo systemctl daemon-reload
sudo systemctl enable start_wifi.service
sudo systemctl start start_wifi.service
Your Raspberry Pi should now connect to the Wi-Fi network automatically on boot.
If you want to connect to hidden networks or multiple networks, edit the wpa_supplicant.conf
file located at /etc/wpa_supplicant/wpa_supplicant.conf
and add the following configuration:
network={
priority=1 # Higher priority networks are attempted first
ssid="Your_Wi-Fi_Name"
psk="Your_Wi-Fi_Password"
key_mgmt=WPA-PSK
scan_ssid=1 # Hidden network
priority=2
ssid="Enterprise_Wi-Fi_Name"
key_mgmt=WPA-EAP
eap=PEAP # or TTLS, TLS, FAST, LEAP
identity="Your_Username"
password="Your_Password"
phase1="peaplabel=0" # or "peapver=0" for PEAPv0
phase2="auth=MSCHAPV2" # or "auth=MSCHAP" for MSCHAPv1
}
Restart the wpa_supplicant
service to apply the changes:
sudo systemctl restart wpa_supplicant
See the wpa_supplicant example file for more information on the configuration options.
Before running this project on your system, ensure your system clock is synchronized, your package lists are updated, and NGINX and Docker are installed. The setup script will take care of this for you but you can also do this manually.
Synchronize your system clock:
Install chrony
for time synchronization:
sudo apt install -y chrony # For Debian/Ubuntu
sudo yum install -y chrony # For RHEL/CentOS/Alma
sudo dnf install -y chrony # # For RHEL/CentOS/Alma 9^
sudo zypper install -y chrony # For openSUSE
sudo pacman -S chrony # For Arch Linux
Activate and synchronize time immediately with chrony
:
sudo chronyc makestep
Update your package list:
Regular updates to your package list ensure access to the latest software and security patches.
sudo apt update # For Debian/Ubuntu
sudo yum makecache # For RHEL/CentOS/Alma
sudo dnf makecache # For RHEL/CentOS/Alma 9^
sudo zypper refresh # For openSUSE
sudo pacman -Sy # For Arch Linux
Enable additional repositories:
For systems that utilize EPEL and other special repositories, you may need to enable them to access a wider range of available packages.
For Debian/Ubuntu:
sudo add-apt-repository universe
sudo apt update
For RHEL/CentOS/Alma and Fedora:
sudo yum install -y epel-release # For RHEL/CentOS/Alma
sudo dnf install -y epel-release # For RHEL/CentOS/Alma 9^
sudo yum makecache --timer # For RHEL/CentOS/Alma
sudo dnf makecache --timer # For RHEL/CentOS/Alma 9^
Install Development Tools:
Development tools are essential for building packages and compiling software. Ensure you have the necessary tools installed.
For Debian/Ubuntu:
sudo apt install -y build-essential
For RHEL/CentOS/Alma and Fedora:
sudo yum groupinstall -y "Development Tools" # For RHEL/CentOS/Alma
sudo dnf groupinstall -y "Development Tools" # For RHEL/CentOS/Alma 9^
Install System Dependencies
Docker: Required for containerization.
sudo apt-get install -y docker.io # For Debian/Ubuntu
sudo yum install -y docker # For RHEL/CentOS/Alma
sudo dnf install -y docker # For RHEL/CentOS/Alma 9^
sudo zypper install -y docker # For openSUSE
sudo pacman -S docker # For Arch Linux
then sudo systemctl enable --now docker
NGINX: Required for reverse proxy for the web interface.
sudo apt-get install -y nginx # For Debian/Ubuntu
sudo yum install -y nginx # For RHEL/CentOS/Alma
sudo dnf install -y nginx # For RHEL/CentOS/Alma 9^
sudo zypper install -y nginx # For openSUSE
sudo pacman -S nginx # For Arch Linux
Before you run the setup script to build the container you should first make sure to export your OpenAI API Key to an environment variable.
LITELLM_API_KEY
. See the LiteLLM docs for a list of all supported providers. The setup script will use this variable to initialize the container.Note: Executing export
directly in the terminal does not persist after reboot.
export OPENAI_API_KEY="your_api_key_here"
Alternatively, you can put this at the end of your ~/.bashrc
file. (recommended)
# export your API Key in here to initialize it at boot
export OPENAI_API_KEY="your_api_key_here"
# Optional: Anthropic, Mistral, Cohere, HuggingFace, etc.
export LITELLM_API_KEY="your_api_key_here"
# Optional: Add these aliases to your .bashrc file for easier management
alias gpt-start="docker exec -it gpt-home supervisorctl start app"
alias gpt-restart="docker exec -it gpt-home supervisorctl restart app"
alias gpt-stop="docker exec -it gpt-home supervisorctl stop app"
alias gpt-status="docker exec -it gpt-home supervisorctl status app"
alias gpt-log="docker exec -it gpt-home tail -n 100 -f /app/src/events.log"
alias wi-start="docker exec -it gpt-home supervisorctl start web-interface"
alias wi-restart="docker exec -it gpt-home supervisorctl restart web-interface && sudo systemctl restart nginx"
alias wi-stop="docker exec -it gpt-home supervisorctl stop web-interface"
alias wi-status="docker exec -it gpt-home supervisorctl status web-interface"
alias wi-build="docker exec -it gpt-home bash -c 'cd /app/src/frontend && npm run build'"
alias wi-log="tail -n 100 -f /var/log/nginx/access.log"
alias wi-error="tail -n 100 -f /var/log/nginx/error.log"
alias spotifyd-start="docker exec -it gpt-home supervisorctl start spotifyd"
alias spotifyd-restart="docker exec -it gpt-home supervisorctl restart spotifyd"
alias spotifyd-stop="docker exec -it gpt-home supervisorctl stop spotifyd"
alias spotifyd-status="docker exec -it gpt-home supervisorctl status spotifyd"
alias spotifyd-log="docker exec -it gpt-home tail -n 100 -f /var/log/spotifyd.log"
Run source ~/.bashrc
to apply the changes to your current terminal session.
The setup script will take quite a while to run (900.0s+ to build and setup dependencies on my quad-core Raspberry Pi 4B w/ 1G RAM). It will install all the dependencies and build the Docker container. However, you can skip the build process by passing the --no-build
flag to the script; it will install the dependencies, set up the firewall and NGINX, and pull the container from Docker Hub and run it.
curl -s https://raw.githubusercontent.com/judahpaul16/gpt-home/main/contrib/setup.sh |
bash -s -- --no-build
Alternatively, for development purposes, running setup.sh
without the --no-build
flag mounts the project directory to the container by adding -v ~/gpt-home:/app
to the docker run
command. This allows you to make changes to the project files on your Raspberry Pi and see the changes reflected in the container without rebuilding the image. This is useful for testing changes to the codebase. Run directly with:
curl -s https://raw.githubusercontent.com/judahpaul16/gpt-home/main/contrib/setup.sh |
bash -s
You can also run the container interactively if you need to debug or test changes to the codebase with the -it
(interactive terminal), --entrypoint /bin/bash
, and --rm
(remove on process exit) flags. This will drop you into a shell session inside the container. Alternatively, if the conatiner is already running:
docker exec -it gpt-home bash
This will start the container and drop you into a shell session inside the container.
Explanation of Docker Run Flags
--tmpfs /run:
Mounts a tmpfs at /run for transient runtime data.
--tmpfs /run/lock:
Mounts a tmpfs at /run/lock for lock files.
--privileged:
Grants extended privileges to the container
Necessary for accessing host audio devices.
--net=host:
Uses the host network stack directly.
May be necessary for avahi-daemon services.
-v /dev/snd:/dev/snd:
Provides access to the host's sound devices.
-v /dev/shm:/dev/shm:
Provides access to shared memory.
-v /usr/share/alsa:/usr/share/alsa:ro:
Maps the ALSA shared data as read-only.
-v /var/run/dbus:/var/run/dbus:
Provides access to the D-Bus system for inter-process communication.
--mount type=bind,source=/etc/asound.conf,target=/etc/asound.conf:
Binds the host's ALSA configuration to the container.
If you prefer to run the setup script manually, you can do so. Create a script in your home folder with vim ~/setup.sh
or nano ~/setup.sh
and paste in the following:
#!/bin/bash
latest_release=$(curl -s https://api.github.com/repos/judahpaul16/gpt-home/releases/latest | grep 'tag_name' | cut -d" -f4)
# Colors
RED='