Automated deployment of GPT4All Docker API using Ansible.
Create inventory.ini:
[gpt4all_servers]
gpt4all-prod-01 ansible_host=192.168.1.100
[gpt4all_servers:vars]
ansible_user=ubuntu
ansible_python_interpreter=/usr/bin/python3
Create gpt4all-deploy.yml:
---
- name: Deploy GPT4All Docker API
hosts: gpt4all_servers
become: true
vars:
gpt4all_image: nomicai/gpt4all:latest
gpt4all_container_name: gpt4all
gpt4all_port: 4891
gpt4all_model: llama-3-8b-instruct.Q4_0.gguf
gpu_enabled: false
tasks:
- name: Install Docker prerequisites
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
update_cache: true
- name: Add Docker GPG key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
- name: Install Docker
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
state: present
update_cache: true
- name: Enable and start Docker
service:
name: docker
state: started
enabled: true
- name: Create GPT4All volume
docker_volume:
name: gpt4all-models
- name: Create Docker Compose file
copy:
dest: /opt/gpt4all/docker-compose.yml
content: |
version: '3.8'
services:
gpt4all:
image: {{ gpt4all_image }}
container_name: {{ gpt4all_container_name }}
restart: unless-stopped
ports:
- "127.0.0.1:{{ gpt4all_port }}:4891"
volumes:
- gpt4all-models:/app/models
environment:
- MODEL_NAME={{ gpt4all_model }}
{% if gpu_enabled %}
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
{% endif %}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:4891/v1/models"]
interval: 30s
timeout: 10s
retries: 3
mode: '0644'
- name: Start GPT4All with Docker Compose
command: >
docker compose up -d
args:
chdir: /opt/gpt4all
- name: Wait for GPT4All to be healthy
uri:
url: "http://localhost:{{ gpt4all_port }}/v1/models"
method: GET
status_code: 200
register: health_check
retries: 10
delay: 10
until: health_check.status == 200
ignore_errors: true
- name: Display access information
debug:
msg: |
GPT4All has been deployed successfully!
API Endpoint: http://localhost:{{ gpt4all_port }}
Models: http://localhost:{{ gpt4all_port }}/v1/models
Example usage:
curl http://localhost:{{ gpt4all_port }}/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "{{ gpt4all_model }}", "messages": [{"role": "user", "content": "Hello!"}]}'
ansible-playbook -i inventory.ini gpt4all-deploy.yml
ansible-playbook -i inventory.ini gpt4all-deploy.yml -e "gpu_enabled=true"
ansible-playbook -i inventory.ini gpt4all-deploy.yml -e "gpt4all_model=mistral-7b-instruct.Q4_0.gguf"
ansible gpt4all_servers -m command -a "docker ps -a | grep gpt4all"
ansible gpt4all_servers -m command -a "docker logs gpt4all --tail 50"
ansible gpt4all_servers -m uri -a "url=http://localhost:4891/v1/models method=GET"
ansible-playbook -i inventory.ini gpt4all-deploy.yml -e "gpt4all_image=nomicai/gpt4all:latest"
Any questions?
Feel free to contact us. Find all contact information on our contact page.