diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index b41186e..abf212f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -8,10 +8,10 @@ assignees: '' --- ## Issue -A clear and concise description of what the problem/feature is. +A clear and concise description of what the problem/feature is. PLease describe it as best as possible. ## Solution -* Provide steps or ideals to how to implement or investigate this new feature. +* Provide steps or ideas to how to implement or investigate this new feature. ## References * Provide additional context and external references here diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3675511..0b161a4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,75 +1,75 @@ -name: Builds -run-name: Validate Node and Docker Builds -on: - push: - branches: - - master # runs after Pull Request is merged - -jobs: - Discord-Node-Build: # test if the node install and run - runs-on: ubuntu-latest - timeout-minutes: 2 - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Node Environment lts/jod - uses: actions/setup-node@v4 - with: - node-version: lts/jod - cache: "npm" - - - name: Install Project Dependencies - run: | - npm install - - - name: Build Application - run: | - npm run build - - - name: Create Environment Variables - run: | - touch .env - echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env - echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env - echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env - echo MODEL = ${{ secrets.MODEL }} >> .env - - # set -e ensures if nohup fails, this section fails - - name: Startup Discord Bot Client - run: | - set -e - nohup npm run prod & - - Discord-Ollama-Container-Build: # test docker build and run - runs-on: ubuntu-latest - timeout-minutes: 2 - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Node Environment lts/jod - uses: actions/setup-node@v4 - with: - node-version: lts/jod - cache: "npm" - - - name: Create Environment Variables - run: | - touch .env - echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env - echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env - echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env - echo MODEL = ${{ secrets.MODEL }} >> .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 - - - name: Check Containers Exist - run: | - (docker ps | grep -q 'ollama' && docker ps | grep -q 'discord') || exit 1 +name: Builds +run-name: Validate Node and Docker Builds +on: + push: + branches: + - master # runs after Pull Request is merged + +jobs: + Discord-Node-Build: # test if the node install and run + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node Environment lts/jod + uses: actions/setup-node@v4 + with: + node-version: lts/jod + cache: "npm" + + - name: Install Project Dependencies + run: | + npm install + + - name: Build Application + run: | + npm run build + + - name: Create Environment Variables + run: | + touch .env + echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env + echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env + echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env + echo MODEL = ${{ secrets.MODEL }} >> .env + + # set -e ensures if nohup fails, this section fails + - name: Startup Discord Bot Client + run: | + set -e + nohup npm run prod & + + Discord-Ollama-Container-Build: # test docker build and run + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node Environment lts/jod + uses: actions/setup-node@v4 + with: + node-version: lts/jod + cache: "npm" + + - name: Create Environment Variables + run: | + touch .env + echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env + echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env + echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env + echo MODEL = ${{ secrets.MODEL }} >> .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 + + - name: Check Containers Exist + run: | + (docker ps | grep -q 'ollama' && docker ps | grep -q 'discord') || exit 1 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dee7c17..4291c7e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,9 +1,10 @@ name: Deploy run-name: Deploy Application Latest -on: - push: - tags: - - 'v*' +# on: +# push: +# tags: +# - 'v*' +on: workflow_dispatch jobs: Deploy-Application: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5fe9007..c7a4a4b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,48 +1,48 @@ -name: Tests -run-name: Unit Tests -on: - pull_request: - branches: - - master - paths: - - '*' - - 'package*.json' - - 'src/**' - - 'tests/**' - - '!docs/**' - - '!imgs/**' - - '!.github/**' - - '.github/workflows/**' - - '!.gitignore' - - '!LICENSE' - - '!README' - -jobs: - Discord-Node-Test: - runs-on: ubuntu-latest - timeout-minutes: 2 - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Node Environment lts/jod - uses: actions/setup-node@v4 - with: - node-version: lts/jod - cache: "npm" - - - name: Install Project Dependencies - run: | - npm install - - - name: Create Environment Variables - run: | - touch .env - echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env - echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env - echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env - echo MODEL = ${{ secrets.MODEL }} >> .env - - - name: Test Application - run: | - npm run tests +name: Tests +run-name: Unit Tests +on: + pull_request: + branches: + - master + paths: + - '*' + - 'package*.json' + - 'src/**' + - 'tests/**' + - '!docs/**' + - '!imgs/**' + - '!.github/**' + - '.github/workflows/**' + - '!.gitignore' + - '!LICENSE' + - '!README' + +jobs: + Discord-Node-Test: + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Node Environment lts/jod + uses: actions/setup-node@v4 + with: + node-version: lts/jod + cache: "npm" + + - name: Install Project Dependencies + run: | + npm install + + - name: Create Environment Variables + run: | + touch .env + echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env + echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env + echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env + echo MODEL = ${{ secrets.MODEL }} >> .env + + - name: Test Application + run: | + npm run tests diff --git a/README.md b/README.md index 9d8436e..b10ee40 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@

Ollama as your Discord AI Assistant

License Release - Build Status - Deploy Status - Testing Status + Builds + + Tests Code Coverage diff --git a/src/client.ts b/src/client.ts index fbf72f5..6e5996d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,44 +1,44 @@ -import { Client, GatewayIntentBits } from 'discord.js' -import { Ollama } from 'ollama' -import { Queue } from './queues/queue.js' -import { UserMessage, registerEvents } from './utils/index.js' -import Events from './events/index.js' -import Keys from './keys.js' - -// initialize the client with the following permissions when logging in -const client = new Client({ - intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildMembers, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent - ] -}) - -// initialize connection to ollama container -export const ollama = new Ollama({ - host: `http://${Keys.ipAddress}:${Keys.portAddress}`, -}) - -// Create Queue managed by Events -const messageHistory: Queue = new Queue - -// Create Channel History Queue managed by Events -const channelMessageHistory: Queue = new Queue - -// register all events -registerEvents(client, Events, messageHistory, channelMessageHistory, ollama, Keys.defaultModel) - -// Try to log in the client -await client.login(Keys.clientToken) - .catch((error) => { - console.error('[Login Error]', error) - process.exit(1) - }) - -// queue up bots name -messageHistory.enqueue({ - role: 'assistant', - content: `My name is ${client.user?.username}`, - images: [] +import { Client, GatewayIntentBits } from 'discord.js' +import { Ollama } from 'ollama' +import { Queue } from './queues/queue.js' +import { UserMessage, registerEvents } from './utils/index.js' +import Events from './events/index.js' +import Keys from './keys.js' + +// initialize the client with the following permissions when logging in +const client = new Client({ + intents: [ + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildMembers, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.MessageContent + ] +}) + +// initialize connection to ollama container +export const ollama = new Ollama({ + host: `http://${Keys.ipAddress}:${Keys.portAddress}`, +}) + +// Create Queue managed by Events +const messageHistory: Queue = new Queue + +// Create Channel History Queue managed by Events +const channelMessageHistory: Queue = new Queue + +// register all events +registerEvents(client, Events, messageHistory, channelMessageHistory, ollama, Keys.defaultModel) + +// Try to log in the client +await client.login(Keys.clientToken) + .catch((error) => { + console.error('[Login Error]', error) + process.exit(1) + }) + +// queue up bots name +messageHistory.enqueue({ + role: 'assistant', + content: `My name is ${client.user?.username}`, + images: [] }) \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 67fbfc4..1441e90 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -import('./client.js') \ No newline at end of file +import('./client.js') diff --git a/src/keys.ts b/src/keys.ts index c037016..03423b2 100644 --- a/src/keys.ts +++ b/src/keys.ts @@ -1,10 +1,10 @@ -import { getEnvVar } from './utils/index.js' - -export const Keys = { - clientToken: getEnvVar('CLIENT_TOKEN'), - ipAddress: getEnvVar('OLLAMA_IP', '127.0.0.1'), // default ollama ip if none - portAddress: getEnvVar('OLLAMA_PORT', '11434'), // default ollama port if none - defaultModel: getEnvVar('MODEL', 'llama3.2') -} as const // readonly keys - +import { getEnvVar } from './utils/index.js' + +export const Keys = { + clientToken: getEnvVar('CLIENT_TOKEN'), + ipAddress: getEnvVar('OLLAMA_IP', '127.0.0.1'), // default ollama ip if none + portAddress: getEnvVar('OLLAMA_PORT', '11434'), // default ollama port if none + defaultModel: getEnvVar('MODEL', 'llama3.2') +} as const // readonly keys + export default Keys \ No newline at end of file diff --git a/tests/commands.test.ts b/tests/commands.test.ts index c06e911..1596017 100644 --- a/tests/commands.test.ts +++ b/tests/commands.test.ts @@ -1,78 +1,78 @@ -// describe marks a test suite -// expect takes a value from an expression -// it marks a test case -import { describe, expect, it, vi } from 'vitest' -import commands from '../src/commands/index.js' - -/** - * Mocking client.ts because of the commands - */ -vi.mock('../src/client.js', () => ({})) - -/** - * Commands test suite, tests the commands object - * Each command is to be tested elsewhere, this file - * is to ensure that the commands object is defined. - * - * @param name name of the test suite - * @param fn function holding tests to run - */ -describe('Commands Existence', () => { - // test definition of commands object - it('references defined object', () => { - // toBe compares the value to the expected value - expect(typeof commands).toBe('object') - }) - - // test specific commands in the object - it('references specific commands', () => { - const commandsString = commands.map(e => e.name).join(', ') - const expectedCommands = ['thread', 'private-thread', 'message-stream', 'toggle-chat', 'shutoff', 'modify-capacity', 'clear-user-channel-history', 'pull-model', 'switch-model', 'delete-model'] - expect(commandsString).toBe(expectedCommands.join(', ')) - }) -}) - -/** - * User Commands Test suite for testing out commands - * that would be run by users when using the application. - */ -describe('User Command Tests', () => { - // test capacity command - it('run modify-capacity command', () => { - - }) - - it('run clear-user-channel-history command', () => { - - }) - - it('run message-stream command', () => { - - }) - - it('run message-style command', () => { - - }) - - it('run thread command', () => { - - }) - - it('run private-thread command', () => { - - }) -}) - -/** - * Admin Commands Test suite for running administrative - * commands with the application. - */ -describe('Admin Command Tests', () => { - it('run shutoff command', () => { - - }) - - it('run toggle-chat command', () => { - - }) +// describe marks a test suite +// expect takes a value from an expression +// it marks a test case +import { describe, expect, it, vi } from 'vitest' +import commands from '../src/commands/index.js' + +/** + * Mocking client.ts because of the commands + */ +vi.mock('../src/client.js', () => ({})) + +/** + * Commands test suite, tests the commands object + * Each command is to be tested elsewhere, this file + * is to ensure that the commands object is defined. + * + * @param name name of the test suite + * @param fn function holding tests to run + */ +describe('Commands Existence', () => { + // test definition of commands object + it('references defined object', () => { + // toBe compares the value to the expected value + expect(typeof commands).toBe('object') + }) + + // test specific commands in the object + it('references specific commands', () => { + const commandsString = commands.map(e => e.name).join(', ') + const expectedCommands = ['thread', 'private-thread', 'message-stream', 'toggle-chat', 'shutoff', 'modify-capacity', 'clear-user-channel-history', 'pull-model', 'switch-model', 'delete-model'] + expect(commandsString).toBe(expectedCommands.join(', ')) + }) +}) + +/** + * User Commands Test suite for testing out commands + * that would be run by users when using the application. + */ +describe('User Command Tests', () => { + // test capacity command + it('run modify-capacity command', () => { + + }) + + it('run clear-user-channel-history command', () => { + + }) + + it('run message-stream command', () => { + + }) + + it('run message-style command', () => { + + }) + + it('run thread command', () => { + + }) + + it('run private-thread command', () => { + + }) +}) + +/** + * Admin Commands Test suite for running administrative + * commands with the application. + */ +describe('Admin Command Tests', () => { + it('run shutoff command', () => { + + }) + + it('run toggle-chat command', () => { + + }) }) \ No newline at end of file