Skip to content

Commit

Permalink
Docker fixes (#88)
Browse files Browse the repository at this point in the history
* Add server variables

* Update Docker docs

* Update Docker action

* Add Docker action badge

* Fix default host for Docker
  • Loading branch information
justinh-rahb authored Sep 10, 2023
1 parent 9f00904 commit 5ab5373
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 113 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ name: Docker Image

on:
push:
branches: ['master']
branches:
- master
paths:
- '**.py'
- 'client.js'
- 'interface.html'
- 'requirements.txt'
create:

env:
Expand All @@ -19,7 +25,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@v2
Expand Down
76 changes: 30 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
[![Python 3.11](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/python-3.11.yml/badge.svg)](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/python-3.11.yml)
[![GCP Deployment](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/gcp-deploy.yml/badge.svg)](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/gcp-deploy.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

<br/>
<p align="center">
<img src="https://raw.githubusercontent.com/RAHB-REALTORS-Association/chat2gpt/master/docs/chat2gpt.png" alt="Logo" width="300"/>
</p>
<hr/>

[![Python 3.11](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/python-3.11.yml/badge.svg)](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/python-3.11.yml)
[![GCP Deployment](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/gcp-deploy.yml/badge.svg)](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/gcp-deploy.yml)
[![Docker Image](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/docker-image.yml/badge.svg)](https://github.com/RAHB-REALTORS-Association/chat2gpt/actions/workflows/docker-image.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

**Chat²GPT** is a [ChatGPT](https://openai.com/chatgpt) chat bot for Google Chat 🤖💬. It's designed to amplify the experience in your Google Chat rooms by offering personalized user sessions for coherent dialogues, a manual reset capability, the power to generate images via OpenAI's [DALL·E 2 API](https://openai.com/dall-e-2), and dynamic interactions through mentions or direct messaging. Moreover, with the integration of ElevenLabs' [Text-to-Speech API](https://docs.elevenlabs.io/api-reference/text-to-speech), Chat²GPT now brings voice interactions, letting users convert textual prompts into audio. User input and text output is moderated with OpenAI's [Moderation API](https://platform.openai.com/docs/guides/moderation).

## 📖 Table of Contents
- [📖 Table of Contents](#-table-of-contents)
- [🛠️ Setup](#️-setup)
- [👷 Development](#-development)
- [Docker 🐳](#docker-)
- [Basic Usage:](#basic-usage)
- [Additional Options:](#additional-options)
- [Ubuntu 🤓](#ubuntu-)
- [macOS 🍎](#macos-)
- [Android 🤖](#android-)
Expand Down Expand Up @@ -108,54 +107,39 @@ Now, your bot can be added to any room within your Google Workspace.

The `server.py` script included in this repository serves as a lightweight, local development server for Chat²GPT. This enables you to test new features, debug issues, or get a firsthand experience of the chatbot's capabilities without deploying it to a production environment. Running the server starts a web service that you can access at [http://127.0.0.1:5000](http://127.0.0.1:5000).

### Setup
The following are only applicable if using the `server.py` script or Docker:
- Additional environment variables:
- `LOG_FILE`: Path to save server log file to. Default: None (disabled)
- `DEBUG`: [True/False] Enable Flask server debugging. Default: False
- `HOST`: Interfaces to bind server to. Default: "0.0.0.0"
- `PORT`: Port to bind server to. Default 5000

### Docker 🐳

To quickly set up and run the Chat²GPT application, you can use the pre-built Docker image available at `ghcr.io/rahb-realtors-assocaition/chat2gpt:latest`. Below are the steps and options for running the Docker container.
To quickly set up and run the Chat²GPT application, you can use the pre-built Docker image available at `ghcr.io/rahb-realtors-association/chat2gpt:latest`. Below are the steps and options for running the Docker container:

#### Basic Usage:
1. **Basic Usage**

Run the following command to pull the image and start a container:
Run the following command to pull the image and start a container:

```bash
docker run -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```

Here's a breakdown:

- `docker run`: This command creates and starts a container from a Docker image.
- `-p 5000:5000`: This maps port 5000 in the container to port 5000 on your host machine, allowing you to access the application.
```bash
docker run -d -e OPENAI_API_KEY=sk-myopenaisecretapikey -p 5000:5000 --name chat2gpt ghcr.io/rahb-realtors-association/chat2gpt:latest
```

#### Additional Options:

1. **Detached Mode**: To run the container in the background, add the `-d` flag:

```bash
docker run -d -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```

2. **Environment Variables**: If you need to pass environment variables to your application:

```bash
docker run -e VAR_NAME=value -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```

3. **Name the Container**: To assign a name to your container for easy identification, use the `--name` flag:

```bash
docker run --name chat2gpt-container -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```
2. **Additional Options**

4. **Volume Mapping**: To persist data, use volume mapping:
To load from .env file or persist logs, use volume mapping:

```bash
docker run -v /path/on/host:/path/in/container -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```
```bash
docker run -d -v ./.env:/app/.env -v ./chat2gpt-server-log.txt:/app/chat2gpt-server-log.txt -e LOG_FILE=chat2gpt-server-log.txt -p 5000:5000 ghcr.io/rahb-realtors-association/chat2gpt:latest
```

You can combine these options as needed. For example:
To access an API_URL running on the Docker host, use host networking:

```bash
docker run -d --name chat2gpt-container -e VAR_NAME=value -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```
```bash
docker run -d -e API_URL=http://127.0.0.1:1234/v1/chat/completions --network host --name chat2gpt ghcr.io/rahb-realtors-association/chat2gpt:latest
```

The server should start successfully and can be accessed at [http://127.0.0.1:5000](http://127.0.0.1:5000).

Expand Down Expand Up @@ -213,7 +197,7 @@ The server should start successfully and can be accessed at [http://127.0.0.1:50

### macOS 🍎

To run Chat²GPT on macOS, you can use Homebrew to manage your packages. Follow these steps:
To run Chat²GPT on macOS, you can use [Homebrew](https://brew.sh/) to manage your packages. Follow these steps:

1. **Install Homebrew**

Expand Down Expand Up @@ -265,7 +249,7 @@ The server should start successfully and can be accessed at [http://127.0.0.1:50

### Android 🤖

To run Chat²GPT on an Android device using Termux, follow these steps:
To run Chat²GPT on an Android device using [Termux](https://termux.dev/en/), follow these steps:

1. **Update and Upgrade Termux Packages**

Expand Down
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Chat2GPT Bot",
"description": "A chatbot that uses OpenAI API to generate responses to messages.",
"name": "Chat2GPT",
"description": "Chat²GPT is a ChatGPT chat bot for Google Chat. 🤖💬",
"repository": "https://github.com/RAHB-REALTORS-Association/chat2gpt"
}
51 changes: 14 additions & 37 deletions docs/development/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,28 @@ nav_order: 0

## Docker 🐳

To quickly set up and run the Chat²GPT application, you can use the pre-built Docker image available at `ghcr.io/rahb-realtors-assocaition/chat2gpt:latest`. Below are the steps and options for running the Docker container.
To quickly set up and run the Chat²GPT application, you can use the pre-built Docker image available at `ghcr.io/rahb-realtors-association/chat2gpt:latest`. Below are the steps and options for running the Docker container:

### Basic Usage:
1. **Basic Usage**

Run the following command to pull the image and start a container:

```bash
docker run -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```

Here's a breakdown:

- `docker run`: This command creates and starts a container from a Docker image.
- `-p 5000:5000`: This maps port 5000 in the container to port 5000 on your host machine, allowing you to access the application.

### Additional Options:

1. **Detached Mode**: To run the container in the background, add the `-d` flag:

```bash
docker run -d -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```

2. **Environment Variables**: If you need to pass environment variables to your application:

```bash
docker run -e VAR_NAME=value -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```

3. **Name the Container**: To assign a name to your container for easy identification, use the `--name` flag:
Run the following command to pull the image and start a container:

```bash
docker run --name chat2gpt-container -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
docker run -d -e OPENAI_API_KEY=sk-myopenaisecretapikey -p 5000:5000 --name chat2gpt ghcr.io/rahb-realtors-association/chat2gpt:latest
```

2. **Additional Options**

4. **Volume Mapping**: To persist data, use volume mapping:
To load from .env file or persist logs, use volume mapping:

```bash
docker run -v /path/on/host:/path/in/container -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```
```bash
docker run -d -v ./.env:/app/.env -v ./server-log.txt:/app/server-log.txt -e LOG_FILE=server-log.txt -p 5000:5000 ghcr.io/rahb-realtors-association/chat2gpt:latest
```

You can combine these options as needed. For example:
To access an API_URL running on the Docker host, use host networking:

```bash
docker run -d --name chat2gpt-container -e VAR_NAME=value -p 5000:5000 ghcr.io/rahb-realtors-assocaition/chat2gpt:latest
```
```bash
docker run -d -e API_URL=http://127.0.0.1:1234/v1/chat/completions --network host --name chat2gpt ghcr.io/rahb-realtors-association/chat2gpt:latest
```

The server should start successfully and can be accessed at [http://127.0.0.1:5000](http://127.0.0.1:5000).
8 changes: 8 additions & 0 deletions docs/development/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ has_children: true
# 👷 Development

The `server.py` script included in this repository serves as a lightweight, local development server for Chat²GPT. This enables you to test new features, debug issues, or get a firsthand experience of the chatbot's capabilities without deploying it to a production environment. Running the server starts a web service that you can access at [http://127.0.0.1:5000](http://127.0.0.1:5000).

## Setup
The following are only applicable if using the `server.py` script or Docker:
- Additional environment variables:
- `LOG_FILE`: Path to save server log file to. Default: None (disabled)
- `DEBUG`: [True/False] Enable Flask server debugging. Default: False
- `HOST`: Interfaces to bind server to. Default: "0.0.0.0"
- `PORT`: Port to bind server to. Default 5000
2 changes: 1 addition & 1 deletion docs/development/macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ nav_order: 2

## macOS 🍎

To run Chat²GPT on macOS, you can use Homebrew to manage your packages. Follow these steps:
To run Chat²GPT on macOS, you can use [Homebrew](https://brew.sh/) to manage your packages. Follow these steps:

1. **Install Homebrew**

Expand Down
2 changes: 1 addition & 1 deletion docs/development/termux.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ nav_order: 3

## Android 🤖

To run Chat²GPT on an Android device using Termux, follow these steps:
To run Chat²GPT on an Android device using [Termux](https://termux.dev/en/), follow these steps:

1. **Update and Upgrade Termux Packages**

Expand Down
38 changes: 19 additions & 19 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ This bot is intended to be deployed on Google Cloud Functions, with audio data t
In your GitHub repository:
- Navigate to "Settings" > "Secrets" > "New repository secret".
- Add the following secrets:
- `GCP_PROJECT_ID`: Your Google Cloud Project identifier.
- `GCP_FUNCTION`: Your desired Google Cloud Function name.
- `GCP_REGION`: Your chosen Google Cloud region.
- `GCP_SA_KEY`: The entire JSON key file content that was downloaded in the previous step, encoded as base64.
- `OPENAI_API_KEY`: Your OpenAI API key.
- `MODEL_NAME`: The name of the OpenAI model you're using. Default: "gpt-3.5-turbo".
- `SYSTEM_PROMPT`: The system prompt to use for the text-generation API.
- `PROMPT_PREFIX`: Prefix added to beginning of user prompt for local model API. Default: LLaMa2 style.
- `PROMPT_SUFFIX`: Suffix added to ending of user prompt for local model API. Default: LLaMa2 style.
- `MAX_TURNS`: This sets the maximum number of exchanges the bot remembers in a user session before resetting. Default: 10 exchanges.
- `TTL`: This sets the duration (in seconds) a user session stays active from the last received message before it resets. Default: 600 seconds (10 minutes).
- `MAX_TOKENS_INPUT`: This sets the maximum number of tokens that can be sent. Default: 1000 tokens.
- `MAX_TOKENS_OUTPUT`: This sets the maximum number of tokens that can be received. Default: 1000 tokens.
- `TEMPERATURE`: This sets the temperature for the OpenAI API. Default: 0.8.
- `IMAGE_SIZE`: This sets the image size for the DALL-E API. Default: "512x512".
- `API_URL`: This sets the API endpoint for the chat completions API. Default: "https://api.openai.com/v1/chat/completions".
- `ELEVENLABS_API_KEY`: Your ElevenLabs API key. Can be disabled by omitting this secret.
- `ELEVENLABS_MODEL_NAME`: ElevenLabs model you're using. Default: "eleven_multilingual_v2".
- `GCS_BUCKET_NAME`: Your chosen name for the GCS bucket meant for TTS audio file storage.
- `GCP_PROJECT_ID`: Your Google Cloud Project identifier.
- `GCP_FUNCTION`: Your desired Google Cloud Function name.
- `GCP_REGION`: Your chosen Google Cloud region.
- `GCP_SA_KEY`: The entire JSON key file content that was downloaded in the previous step, encoded as base64.
- `OPENAI_API_KEY`: Your OpenAI API key.
- `MODEL_NAME`: The name of the OpenAI model you're using. Default: "gpt-3.5-turbo".
- `SYSTEM_PROMPT`: The system prompt to use for the text-generation API.
- `PROMPT_PREFIX`: Prefix added to beginning of user prompt for local model API. Default: LLaMa2 style.
- `PROMPT_SUFFIX`: Suffix added to ending of user prompt for local model API. Default: LLaMa2 style.
- `MAX_TURNS`: This sets the maximum number of exchanges the bot remembers in a user session before resetting. Default: 10 exchanges.
- `TTL`: This sets the duration (in seconds) a user session stays active from the last received message before it resets. Default: 600 seconds (10 minutes).
- `MAX_TOKENS_INPUT`: This sets the maximum number of tokens that can be sent. Default: 1000 tokens.
- `MAX_TOKENS_OUTPUT`: This sets the maximum number of tokens that can be received. Default: 1000 tokens.
- `TEMPERATURE`: This sets the temperature for the OpenAI API. Default: 0.8.
- `IMAGE_SIZE`: This sets the image size for the DALL-E API. Default: "512x512".
- `API_URL`: This sets the API endpoint for the chat completions API. Default: "https://api.openai.com/v1/chat/completions".
- `ELEVENLABS_API_KEY`: Your ElevenLabs API key. Can be disabled by omitting this secret.
- `ELEVENLABS_MODEL_NAME`: ElevenLabs model you're using. Default: "eleven_multilingual_v2".
- `GCS_BUCKET_NAME`: Your chosen name for the GCS bucket meant for TTS audio file storage.

5. **GitHub Actions 🚀**

Expand Down
2 changes: 1 addition & 1 deletion interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h4>Response:</h4>
<!-- Formatted markdown content goes here -->
</div>
<div class="tab-pane fade" id="raw" role="tabpanel" aria-labelledby="raw-tab">
<!-- Raw markdown content goes here -->
<!-- Raw JSON response goes here -->
</div>
</div>
</div>
Expand Down
12 changes: 8 additions & 4 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from flask import Flask, request, jsonify, send_from_directory
from main import process_event
import json
import logging
from flask import Flask, request, jsonify, send_from_directory
from env_loader import get_env
from main import process_event

LOG_FILE = "chat2gpt-server-log.txt" # Set to None or an empty string to disable
LOG_FILE = get_env("LOG_FILE")
DEBUG = get_env("DEBUG")
HOST = get_env("HOST")
PORT = get_env("PORT")

# Basic logging setup for console
logging.basicConfig(
Expand Down Expand Up @@ -40,4 +44,4 @@ def google_chat_event():
return jsonify({"error": str(e)}), 500

if __name__ == "__main__":
app.run(host='0.0.0.0',port=5000)
app.run(host=HOST, port=PORT, debug=DEBUG)
24 changes: 24 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,29 @@
"required": False,
"type": str,
"description": "Name of the Google Cloud Storage bucket."
},
"LOG_FILE": {
"default": None,
"required": False,
"type": str,
"description": "Path to save server log file. Disabled if none."
},
"DEBUG": {
"default": False,
"required": False,
"type": bool,
"description": "Enable debugging for server."
},
"HOST": {
"default": "0.0.0.0",
"required": False,
"type": str,
"description": "Server host."
},
"PORT": {
"default": 5000,
"required": False,
"type": int,
"description": "Server port."
}
}

0 comments on commit 5ab5373

Please sign in to comment.