Skip to content

Commit

Permalink
Prepare Redis Environment (#133)
Browse files Browse the repository at this point in the history
* add redis container

* Updated Guides and Goals  (#134)

* Update README.md

* Update commands-guide.md

* Update events-guide.md

* Update commands-guide.md

* Added: redis client

* Fixed: redis mock in commands.test.ts

* Updated: npm package patches

* Fixed: redis ip name in keys.ts

* update Node LTS version, workflow env vars

* Updated: node package engine requirements

* Updated: documentation

* fix: upgrade dotenv from 16.4.5 to 16.4.7 (#152)

Snyk has created this PR to upgrade dotenv from 16.4.5 to 16.4.7.

See this package in npm:
dotenv

See this project in Snyk:
https://app.snyk.io/org/jt2m0l3y/project/d8b070a3-e4a3-457a-977b-7eb6a4a48346?utm_source=github&utm_medium=referral&page=upgrade-pr

Co-authored-by: snyk-bot <snyk-bot@snyk.io>

* Update: docs patches, connection ordering

---------

Co-authored-by: snyk-bot <snyk-bot@snyk.io>
  • Loading branch information
JT2M0L3Y and snyk-bot authored Dec 30, 2024
1 parent 6c7e48d commit 2ea77c9
Show file tree
Hide file tree
Showing 18 changed files with 536 additions and 351 deletions.
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ DISCORD_IP = IP_ADDRESS

# subnet address, ex. 172.18.0.0 as we use /16.
SUBNET_ADDRESS = ADDRESS

# redis port and ip
REDIS_IP = IP_ADDRESS
REDIS_PORT = PORT
16 changes: 10 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node Environment lts/hydrogen
- name: Set up Node Environment lts/jod
uses: actions/setup-node@v4
with:
node-version: lts/hydrogen
node-version: lts/jod
cache: "npm"

- name: Install Project Dependencies
Expand All @@ -33,6 +33,8 @@ jobs:
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
echo REDIS_IP = ${{ secrets.REDIS_IP }} >> .env
echo REDIS_PORT = ${{ secrets.REDIS_PORT }} >> .env
# set -e ensures if nohup fails, this section fails
- name: Startup Discord Bot Client
Expand All @@ -47,10 +49,10 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node Environment lts/hydrogen
- name: Set up Node Environment lts/jod
uses: actions/setup-node@v4
with:
node-version: lts/hydrogen
node-version: lts/jod
cache: "npm"

- name: Create Environment Variables
Expand All @@ -59,15 +61,17 @@ jobs:
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
echo REDIS_IP = ${{ secrets.REDIS_IP }} >> .env
echo REDIS_PORT = ${{ secrets.REDIS_PORT }} >> .env
- name: Setup Docker Network and Images
run: |
npm run docker:start-cpu
- name: Check Images Exist
run: |
(docker images | grep -q 'kevinthedang/discord-ollama' && docker images | grep -qE 'ollama/ollama') || exit 1
(docker images | grep -q 'kevinthedang/discord-ollama' && docker images | grep -qE 'ollama/ollama' | docker images | grep -qE 'redis') || exit 1
- name: Check Containers Exist
run: |
(docker ps | grep -q 'ollama' && docker ps | grep -q 'discord') || exit 1
(docker ps | grep -q 'ollama' && docker ps | grep -q 'discord' && docker ps | grep -q 'redis') || exit 1
6 changes: 4 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node Environment lts/hydrogen
- name: Set up Node Environment lts/jod
uses: actions/setup-node@v4
with:
node-version: lts/hydrogen
node-version: lts/jod
cache: "npm"

- name: Install Project Dependencies
Expand All @@ -30,6 +30,8 @@ jobs:
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
echo REDIS_IP = ${{ secrets.REDIS_IP }} >> .env
echo REDIS_PORT = ${{ secrets.REDIS_PORT }} >> .env
- name: Collect Code Coverage
run: |
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node Environment lts/hydrogen
- name: Set up Node Environment lts/jod
uses: actions/setup-node@v4
with:
node-version: lts/hydrogen
node-version: lts/jod
cache: "npm"

- name: Create Environment Variables
Expand All @@ -26,6 +26,8 @@ jobs:
echo CLIENT_TOKEN = NOT_REAL_TOKEN >> .env
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
echo REDIS_IP = ${{ secrets.REDIS_IP }} >> .env
echo REDIS_PORT = ${{ secrets.REDIS_PORT }} >> .env
- name: Get Version from package.json
run: echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Node Environment lts/hydrogen
- name: Set up Node Environment lts/jod
uses: actions/setup-node@v4
with:
node-version: lts/hydrogen
node-version: lts/jod
cache: "npm"

- name: Install Project Dependencies
Expand All @@ -41,6 +41,8 @@ jobs:
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
echo REDIS_IP = ${{ secrets.REDIS_IP }} >> .env
echo REDIS_PORT = ${{ secrets.REDIS_PORT }} >> .env
- name: Test Application
run: |
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Technical/Business Code Ownership
/src/ @kevinthedang @JT2M0L3Y
/tests/ @kevinthedang @JT2M0L3Y
/tests/ @JT2M0L3Y
/.github/ @kevinthedang

# Docker Ownership
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# use node LTS image for version 18
FROM node:hydrogen-alpine
# use node LTS image for version 22
FROM node:jod-alpine

# set working directory inside container
WORKDIR /app
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ The project aims to:
* [x] Administrator Role Compatible
* [x] Multi-User Chat Generation (Multiple users chatting at the same time) - This was built in from Ollama `v0.2.1+`
* [x] Automatic and Manual model pulling through the Discord client
* [ ] Allow others to create their own models personalized for their own servers!
* [ ] Documentation on creating your own LLM
* [ ] Documentation on web scrapping and cleaning

Further, Ollama provides the functionality to utilize custom models or provide context for the top-layer of any model available through the Ollama model library.
* [Customize a model](https://github.com/ollama/ollama#customize-a-model)
* [Modelfile Docs](https://github.com/ollama/ollama/blob/main/docs/modelfile.md)

## Documentation
These are guides to the feature set included and the events triggered in this app.
These are guides to the features and capabilities of this app.
* [User Slash Commands](./docs/commands-guide.md)
* [Client Events](./docs/events-guide.md)

Expand All @@ -49,10 +50,12 @@ These are guides to the feature set included and the events triggered in this ap

## Resources
* [NodeJS](https://nodejs.org/en)
* This project runs on `lts\hydrogen`.
* This project supports any NodeJS version above `16.x.x` to only allow ESModules.
* This project runs on `lts\jod` and above.
* This project requires the use of npm version `10.9.0` or above.
* [Ollama](https://ollama.com/)
* [Ollama Docker Image](https://hub.docker.com/r/ollama/ollama)
* [Redis](https://redis.io/)
* [Redis Docker Image](https://hub.docker.com/_/redis)
* [Discord.js Docs](https://discord.js.org/docs/packages/discord.js/main)
* [Setting up Docker (Ubuntu 20.04)](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04)
* [Setting up Nvidia Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html)
Expand Down
18 changes: 16 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ services:
build: ./ # find docker file in designated path
container_name: discord
restart: always # rebuild container always
image: kevinthedang/discord-ollama:0.8.0
image: kevinthedang/discord-ollama:0.8.1
environment:
CLIENT_TOKEN: ${CLIENT_TOKEN}
OLLAMA_IP: ${OLLAMA_IP}
OLLAMA_PORT: ${OLLAMA_PORT}
REDIS_IP: ${REDIS_IP}
REDIS_PORT: ${REDIS_PORT}
networks:
ollama-net:
ipv4_address: ${DISCORD_IP}
Expand All @@ -35,7 +37,18 @@ services:
ports:
- ${OLLAMA_PORT}:${OLLAMA_PORT}

# Put Redis Container here?
# setup redis container
redis:
image: redis:latest
container_name: redis
restart: always
networks:
ollama-net:
ipv4_address: ${REDIS_IP}
volumes:
- redis:/root/.redis
ports:
- ${REDIS_PORT}:${REDIS_PORT}

# create a network that supports giving addresses withing a specific subnet
networks:
Expand All @@ -49,3 +62,4 @@ networks:
volumes:
ollama:
discord:
redis:
3 changes: 1 addition & 2 deletions docs/commands-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ This is a guide to all of the slash commands for the app.
```
/message-stream stream true
```
> [!NOTE]
> This is a very slow progress on Discord because "spamming" changes within 5 seconds is not allowed.
**This is very slow on Discord because "spamming" changes in a channel within a period of 5 seconds is not allowed.**
3. Message Style
This command allows a user to select whether to embed the app's response.
Expand Down
8 changes: 4 additions & 4 deletions docs/events-guide.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Events Guide
This is a guide to all of the client events for the app.

> [!NOTE] Each of these is logged to the console for a developer to track.
> [!NOTE]
> * Each of these is logged to the console for a developer to track.
> * Possible interactions include commands, buttons, menus, etc.
1. ClientReady
This event signifies that the Discord app is online.
Expand All @@ -11,8 +13,6 @@ This is a guide to all of the client events for the app.
This event signifies that a user interacted from Discord in some way.
Here commands are selected from a knowledge bank and executed if found.

> [!NOTE] Possible interactions include commands, buttons, menus, etc.
3. MessageCreate
This event signifies that a message was sent.
Here user questions and comments for the LLM are processed.
Expand All @@ -24,4 +24,4 @@ This is a guide to all of the client events for the app.

4. ThreadDelete
This event signifies that a Discord Thread was deleted.
Here any preferences set for interaction within the thread are cleared away.
Here any preferences set for interaction within the thread are cleared away.
6 changes: 4 additions & 2 deletions docs/setup-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ sudo systemctl restart docker
* [GitHub repository](https://github.com/NVIDIA/nvidia-container-toolkit?tab=readme-ov-file) for Nvidia Container Toolkit

## To Run (with Docker and Docker Compose)
* With the inclusion of subnets in the `docker-compose.yml`, you will need to set the `SUBNET_ADDRESS`, `OLLAMA_IP`, `OLLAMA_PORT`, and `DISCORD_IP`. Here are some default values if you don't care:
* With the inclusion of subnets in the `docker-compose.yml`, you will need to set the `SUBNET_ADDRESS`, `OLLAMA_IP`, `OLLAMA_PORT`, `REDIS_IP`, `REDIS_PORT`, and `DISCORD_IP`. Here are some default values if you don't care:
* `SUBNET_ADDRESS = 172.18.0.0`
* `OLLAMA_IP = 172.18.0.2`
* `OLLAMA_PORT = 11434`
* `DISCORD_IP = 172.18.0.3`
* `SUBNET_ADDRESS = 172.18.0.0`
* `REDIS_IP = 172.18.0.4`
* `REDIS_PORT = 6379`
* Don't understand any of this? watch a Networking video to understand subnetting.
* You also need all environment variables shown in [`.env.sample`](../.env.sample)
* Otherwise, there is no need to install any npm packages for this, you just need to run `npm run start` to pull the containers and spin them up.
Expand Down
Loading

0 comments on commit 2ea77c9

Please sign in to comment.