mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2026-06-20 13:57:24 -04:00
Pipeline Trigger Change and Newline Format (#193)
This commit is contained in:
4
.github/ISSUE_TEMPLATE/feature_request.md
vendored
4
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -8,10 +8,10 @@ assignees: ''
|
|||||||
---
|
---
|
||||||
|
|
||||||
## Issue
|
## 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
|
## 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
|
## References
|
||||||
* Provide additional context and external references here
|
* Provide additional context and external references here
|
||||||
|
|||||||
150
.github/workflows/build.yml
vendored
150
.github/workflows/build.yml
vendored
@@ -1,75 +1,75 @@
|
|||||||
name: Builds
|
name: Builds
|
||||||
run-name: Validate Node and Docker Builds
|
run-name: Validate Node and Docker Builds
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master # runs after Pull Request is merged
|
- master # runs after Pull Request is merged
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Discord-Node-Build: # test if the node install and run
|
Discord-Node-Build: # test if the node install and run
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 2
|
timeout-minutes: 2
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node Environment lts/jod
|
- name: Set up Node Environment lts/jod
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: lts/jod
|
node-version: lts/jod
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|
||||||
- name: Install Project Dependencies
|
- name: Install Project Dependencies
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
- name: Build Application
|
- name: Build Application
|
||||||
run: |
|
run: |
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
- name: Create Environment Variables
|
- name: Create Environment Variables
|
||||||
run: |
|
run: |
|
||||||
touch .env
|
touch .env
|
||||||
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
|
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
|
||||||
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
|
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
|
||||||
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
|
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
|
||||||
echo MODEL = ${{ secrets.MODEL }} >> .env
|
echo MODEL = ${{ secrets.MODEL }} >> .env
|
||||||
|
|
||||||
# set -e ensures if nohup fails, this section fails
|
# set -e ensures if nohup fails, this section fails
|
||||||
- name: Startup Discord Bot Client
|
- name: Startup Discord Bot Client
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
nohup npm run prod &
|
nohup npm run prod &
|
||||||
|
|
||||||
Discord-Ollama-Container-Build: # test docker build and run
|
Discord-Ollama-Container-Build: # test docker build and run
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 2
|
timeout-minutes: 2
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node Environment lts/jod
|
- name: Set up Node Environment lts/jod
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: lts/jod
|
node-version: lts/jod
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|
||||||
- name: Create Environment Variables
|
- name: Create Environment Variables
|
||||||
run: |
|
run: |
|
||||||
touch .env
|
touch .env
|
||||||
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
|
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
|
||||||
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
|
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
|
||||||
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
|
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
|
||||||
echo MODEL = ${{ secrets.MODEL }} >> .env
|
echo MODEL = ${{ secrets.MODEL }} >> .env
|
||||||
|
|
||||||
- name: Setup Docker Network and Images
|
- name: Setup Docker Network and Images
|
||||||
run: |
|
run: |
|
||||||
npm run docker:start-cpu
|
npm run docker:start-cpu
|
||||||
|
|
||||||
- name: Check Images Exist
|
- name: Check Images Exist
|
||||||
run: |
|
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') || exit 1
|
||||||
|
|
||||||
- name: Check Containers Exist
|
- name: Check Containers Exist
|
||||||
run: |
|
run: |
|
||||||
(docker ps | grep -q 'ollama' && docker ps | grep -q 'discord') || exit 1
|
(docker ps | grep -q 'ollama' && docker ps | grep -q 'discord') || exit 1
|
||||||
|
|||||||
9
.github/workflows/deploy.yml
vendored
9
.github/workflows/deploy.yml
vendored
@@ -1,9 +1,10 @@
|
|||||||
name: Deploy
|
name: Deploy
|
||||||
run-name: Deploy Application Latest
|
run-name: Deploy Application Latest
|
||||||
on:
|
# on:
|
||||||
push:
|
# push:
|
||||||
tags:
|
# tags:
|
||||||
- 'v*'
|
# - 'v*'
|
||||||
|
on: workflow_dispatch
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Deploy-Application:
|
Deploy-Application:
|
||||||
|
|||||||
96
.github/workflows/test.yml
vendored
96
.github/workflows/test.yml
vendored
@@ -1,48 +1,48 @@
|
|||||||
name: Tests
|
name: Tests
|
||||||
run-name: Unit Tests
|
run-name: Unit Tests
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
paths:
|
paths:
|
||||||
- '*'
|
- '*'
|
||||||
- 'package*.json'
|
- 'package*.json'
|
||||||
- 'src/**'
|
- 'src/**'
|
||||||
- 'tests/**'
|
- 'tests/**'
|
||||||
- '!docs/**'
|
- '!docs/**'
|
||||||
- '!imgs/**'
|
- '!imgs/**'
|
||||||
- '!.github/**'
|
- '!.github/**'
|
||||||
- '.github/workflows/**'
|
- '.github/workflows/**'
|
||||||
- '!.gitignore'
|
- '!.gitignore'
|
||||||
- '!LICENSE'
|
- '!LICENSE'
|
||||||
- '!README'
|
- '!README'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Discord-Node-Test:
|
Discord-Node-Test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 2
|
timeout-minutes: 2
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node Environment lts/jod
|
- name: Set up Node Environment lts/jod
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: lts/jod
|
node-version: lts/jod
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|
||||||
- name: Install Project Dependencies
|
- name: Install Project Dependencies
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
- name: Create Environment Variables
|
- name: Create Environment Variables
|
||||||
run: |
|
run: |
|
||||||
touch .env
|
touch .env
|
||||||
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
|
echo CLIENT_TOKEN = ${{ secrets.BOT_TOKEN }} >> .env
|
||||||
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
|
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
|
||||||
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
|
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
|
||||||
echo MODEL = ${{ secrets.MODEL }} >> .env
|
echo MODEL = ${{ secrets.MODEL }} >> .env
|
||||||
|
|
||||||
- name: Test Application
|
- name: Test Application
|
||||||
run: |
|
run: |
|
||||||
npm run tests
|
npm run tests
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
<h3><a href="#"></a>Ollama as your Discord AI Assistant</h3>
|
<h3><a href="#"></a>Ollama as your Discord AI Assistant</h3>
|
||||||
<p><a href="#"></a><a href="https://creativecommons.org/licenses/by/4.0/"><img alt="License" src="https://img.shields.io/badge/License-CC_BY_4.0-darkgreen.svg" /></a>
|
<p><a href="#"></a><a href="https://creativecommons.org/licenses/by/4.0/"><img alt="License" src="https://img.shields.io/badge/License-CC_BY_4.0-darkgreen.svg" /></a>
|
||||||
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/releases/latest"><img alt="Release" src="https://img.shields.io/github/v/release/kevinthedang/discord-ollama?logo=github" /></a>
|
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/releases/latest"><img alt="Release" src="https://img.shields.io/github/v/release/kevinthedang/discord-ollama?logo=github" /></a>
|
||||||
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/actions/workflows/build.yml"><img alt="Build Status" src="https://github.com/kevinthedang/discord-ollama/actions/workflows/build.yml/badge.svg" /></a>
|
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/actions/workflows/build.yml"><img alt="Builds" src="https://github.com/kevinthedang/discord-ollama/actions/workflows/build.yml/badge.svg" /></a>
|
||||||
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/actions/workflows/deploy.yml"><img alt="Deploy Status" src="https://github.com/kevinthedang/discord-ollama/actions/workflows/deploy.yml/badge.svg" /></a>
|
<!-- <a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/actions/workflows/deploy.yml"><img alt="Deploy Status" src="https://github.com/kevinthedang/discord-ollama/actions/workflows/deploy.yml/badge.svg" /></a> -->
|
||||||
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/actions/workflows/test.yml"><img alt="Testing Status" src="https://github.com/kevinthedang/discord-ollama/actions/workflows/test.yml/badge.svg" /></a>
|
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/actions/workflows/test.yml"><img alt="Tests" src="https://github.com/kevinthedang/discord-ollama/actions/workflows/test.yml/badge.svg" /></a>
|
||||||
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/actions/workflows/coverage.yml"><img alt="Code Coverage" src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/kevinthedang/bc7b5dcfa16561ab02bb3df67a99b22d/raw/coverage.json"></a>
|
<a href="#"></a><a href="https://github.com/kevinthedang/discord-ollama/actions/workflows/coverage.yml"><img alt="Code Coverage" src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/kevinthedang/bc7b5dcfa16561ab02bb3df67a99b22d/raw/coverage.json"></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +1,44 @@
|
|||||||
import { Client, GatewayIntentBits } from 'discord.js'
|
import { Client, GatewayIntentBits } from 'discord.js'
|
||||||
import { Ollama } from 'ollama'
|
import { Ollama } from 'ollama'
|
||||||
import { Queue } from './queues/queue.js'
|
import { Queue } from './queues/queue.js'
|
||||||
import { UserMessage, registerEvents } from './utils/index.js'
|
import { UserMessage, registerEvents } from './utils/index.js'
|
||||||
import Events from './events/index.js'
|
import Events from './events/index.js'
|
||||||
import Keys from './keys.js'
|
import Keys from './keys.js'
|
||||||
|
|
||||||
// initialize the client with the following permissions when logging in
|
// initialize the client with the following permissions when logging in
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
GatewayIntentBits.GuildMembers,
|
GatewayIntentBits.GuildMembers,
|
||||||
GatewayIntentBits.GuildMessages,
|
GatewayIntentBits.GuildMessages,
|
||||||
GatewayIntentBits.MessageContent
|
GatewayIntentBits.MessageContent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
// initialize connection to ollama container
|
// initialize connection to ollama container
|
||||||
export const ollama = new Ollama({
|
export const ollama = new Ollama({
|
||||||
host: `http://${Keys.ipAddress}:${Keys.portAddress}`,
|
host: `http://${Keys.ipAddress}:${Keys.portAddress}`,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create Queue managed by Events
|
// Create Queue managed by Events
|
||||||
const messageHistory: Queue<UserMessage> = new Queue<UserMessage>
|
const messageHistory: Queue<UserMessage> = new Queue<UserMessage>
|
||||||
|
|
||||||
// Create Channel History Queue managed by Events
|
// Create Channel History Queue managed by Events
|
||||||
const channelMessageHistory: Queue<UserMessage> = new Queue<UserMessage>
|
const channelMessageHistory: Queue<UserMessage> = new Queue<UserMessage>
|
||||||
|
|
||||||
// register all events
|
// register all events
|
||||||
registerEvents(client, Events, messageHistory, channelMessageHistory, ollama, Keys.defaultModel)
|
registerEvents(client, Events, messageHistory, channelMessageHistory, ollama, Keys.defaultModel)
|
||||||
|
|
||||||
// Try to log in the client
|
// Try to log in the client
|
||||||
await client.login(Keys.clientToken)
|
await client.login(Keys.clientToken)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('[Login Error]', error)
|
console.error('[Login Error]', error)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
// queue up bots name
|
// queue up bots name
|
||||||
messageHistory.enqueue({
|
messageHistory.enqueue({
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: `My name is ${client.user?.username}`,
|
content: `My name is ${client.user?.username}`,
|
||||||
images: []
|
images: []
|
||||||
})
|
})
|
||||||
@@ -1 +1 @@
|
|||||||
import('./client.js')
|
import('./client.js')
|
||||||
|
|||||||
18
src/keys.ts
18
src/keys.ts
@@ -1,10 +1,10 @@
|
|||||||
import { getEnvVar } from './utils/index.js'
|
import { getEnvVar } from './utils/index.js'
|
||||||
|
|
||||||
export const Keys = {
|
export const Keys = {
|
||||||
clientToken: getEnvVar('CLIENT_TOKEN'),
|
clientToken: getEnvVar('CLIENT_TOKEN'),
|
||||||
ipAddress: getEnvVar('OLLAMA_IP', '127.0.0.1'), // default ollama ip if none
|
ipAddress: getEnvVar('OLLAMA_IP', '127.0.0.1'), // default ollama ip if none
|
||||||
portAddress: getEnvVar('OLLAMA_PORT', '11434'), // default ollama port if none
|
portAddress: getEnvVar('OLLAMA_PORT', '11434'), // default ollama port if none
|
||||||
defaultModel: getEnvVar('MODEL', 'llama3.2')
|
defaultModel: getEnvVar('MODEL', 'llama3.2')
|
||||||
} as const // readonly keys
|
} as const // readonly keys
|
||||||
|
|
||||||
export default Keys
|
export default Keys
|
||||||
@@ -1,78 +1,78 @@
|
|||||||
// describe marks a test suite
|
// describe marks a test suite
|
||||||
// expect takes a value from an expression
|
// expect takes a value from an expression
|
||||||
// it marks a test case
|
// it marks a test case
|
||||||
import { describe, expect, it, vi } from 'vitest'
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
import commands from '../src/commands/index.js'
|
import commands from '../src/commands/index.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mocking client.ts because of the commands
|
* Mocking client.ts because of the commands
|
||||||
*/
|
*/
|
||||||
vi.mock('../src/client.js', () => ({}))
|
vi.mock('../src/client.js', () => ({}))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commands test suite, tests the commands object
|
* Commands test suite, tests the commands object
|
||||||
* Each command is to be tested elsewhere, this file
|
* Each command is to be tested elsewhere, this file
|
||||||
* is to ensure that the commands object is defined.
|
* is to ensure that the commands object is defined.
|
||||||
*
|
*
|
||||||
* @param name name of the test suite
|
* @param name name of the test suite
|
||||||
* @param fn function holding tests to run
|
* @param fn function holding tests to run
|
||||||
*/
|
*/
|
||||||
describe('Commands Existence', () => {
|
describe('Commands Existence', () => {
|
||||||
// test definition of commands object
|
// test definition of commands object
|
||||||
it('references defined object', () => {
|
it('references defined object', () => {
|
||||||
// toBe compares the value to the expected value
|
// toBe compares the value to the expected value
|
||||||
expect(typeof commands).toBe('object')
|
expect(typeof commands).toBe('object')
|
||||||
})
|
})
|
||||||
|
|
||||||
// test specific commands in the object
|
// test specific commands in the object
|
||||||
it('references specific commands', () => {
|
it('references specific commands', () => {
|
||||||
const commandsString = commands.map(e => e.name).join(', ')
|
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']
|
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(', '))
|
expect(commandsString).toBe(expectedCommands.join(', '))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User Commands Test suite for testing out commands
|
* User Commands Test suite for testing out commands
|
||||||
* that would be run by users when using the application.
|
* that would be run by users when using the application.
|
||||||
*/
|
*/
|
||||||
describe('User Command Tests', () => {
|
describe('User Command Tests', () => {
|
||||||
// test capacity command
|
// test capacity command
|
||||||
it('run modify-capacity command', () => {
|
it('run modify-capacity command', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('run clear-user-channel-history command', () => {
|
it('run clear-user-channel-history command', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('run message-stream command', () => {
|
it('run message-stream command', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('run message-style command', () => {
|
it('run message-style command', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('run thread command', () => {
|
it('run thread command', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('run private-thread command', () => {
|
it('run private-thread command', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin Commands Test suite for running administrative
|
* Admin Commands Test suite for running administrative
|
||||||
* commands with the application.
|
* commands with the application.
|
||||||
*/
|
*/
|
||||||
describe('Admin Command Tests', () => {
|
describe('Admin Command Tests', () => {
|
||||||
it('run shutoff command', () => {
|
it('run shutoff command', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('run toggle-chat command', () => {
|
it('run toggle-chat command', () => {
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user