Dependencies and Readme Updates (#74)
This commit is contained in:
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@@ -13,10 +13,10 @@ jobs:
|
|||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node Environment v18.18.2
|
- name: Set up Node Environment lts/hydrogen
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18.18.2
|
node-version: lts/hydrogen
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|
||||||
- name: Install Project Dependencies
|
- name: Install Project Dependencies
|
||||||
@@ -50,10 +50,10 @@ jobs:
|
|||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node Environment v18.18.2
|
- name: Set up Node Environment lts/hydrogen
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18.18.2
|
node-version: lts/hydrogen
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|
||||||
- name: Create Environment Variables
|
- name: Create Environment Variables
|
||||||
|
|||||||
8
.github/workflows/test.yml
vendored
8
.github/workflows/test.yml
vendored
@@ -21,10 +21,10 @@ jobs:
|
|||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node Environment v18.18.2
|
- name: Set up Node Environment lts/hydrogen
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18.18.2
|
node-version: lts/hydrogen
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|
||||||
- name: Install Project Dependencies
|
- name: Install Project Dependencies
|
||||||
@@ -52,10 +52,10 @@ jobs:
|
|||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Node Environment v18.18.2
|
- name: Set up Node Environment lts/hydrogen
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18.18.2
|
node-version: lts/hydrogen
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|
||||||
- name: Create Environment Variables
|
- name: Create Environment Variables
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# use node LTS image for version 18
|
# use node LTS image for version 18
|
||||||
FROM node:18.18.2
|
FROM node:hydrogen-alpine
|
||||||
|
|
||||||
# set working directory inside container
|
# set working directory inside container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -14,9 +14,11 @@ The project aims to:
|
|||||||
* [x] Create a Discord bot that will utilize Ollama and chat to chat with users!
|
* [x] Create a Discord bot that will utilize Ollama and chat to chat with users!
|
||||||
* [ ] User Preferences on Chat
|
* [ ] User Preferences on Chat
|
||||||
* [ ] Message Persistance on Channels and Threads
|
* [ ] Message Persistance on Channels and Threads
|
||||||
|
* [x] Threads
|
||||||
|
* [ ] Channels
|
||||||
* [x] Containerization with Docker
|
* [x] Containerization with Docker
|
||||||
* [x] Slash Commands Compatible
|
* [x] Slash Commands Compatible
|
||||||
* [x] Generated Token Length Handling for >2000 ~~or >6000 characters~~
|
* [x] Generated Token Length Handling for >2000
|
||||||
* [x] Token Length Handling of any message size
|
* [x] Token Length Handling of any message size
|
||||||
* [ ] External WebUI Integration
|
* [ ] External WebUI Integration
|
||||||
* [x] Administrator Role Compatible
|
* [x] Administrator Role Compatible
|
||||||
@@ -28,20 +30,29 @@ The project aims to:
|
|||||||
* Clone this repo using `git clone https://github.com/kevinthedang/discord-ollama.git` or just use [GitHub Desktop](https://desktop.github.com/) to clone the repo.
|
* Clone this repo using `git clone https://github.com/kevinthedang/discord-ollama.git` or just use [GitHub Desktop](https://desktop.github.com/) to clone the repo.
|
||||||
* You will need a `.env` file in the root of the project directory with the bot's token. There is a `.env.sample` is provided for you as a reference for what environment variables.
|
* You will need a `.env` file in the root of the project directory with the bot's token. There is a `.env.sample` is provided for you as a reference for what environment variables.
|
||||||
* For example, `CLIENT_TOKEN = [Bot Token]`
|
* For example, `CLIENT_TOKEN = [Bot Token]`
|
||||||
* Please refer to the docs for bot setup. **NOTE**: These guides assume you already know how to setup a bot account for discord.
|
* Please refer to the docs for bot setup.
|
||||||
* [Local Machine Setup](./docs/setup-local.md)
|
* [Local Machine Setup](./docs/setup-local.md)
|
||||||
* [Docker Setup for Servers and Local Machines](./docs/setup-docker.md)
|
* [Docker Setup for Servers and Local Machines](./docs/setup-docker.md)
|
||||||
* Local use is not recommended.
|
* Local use is not recommended.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> These guides assume you already know how to setup a bot account for discord. Documentation will be added later.
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
* [NodeJS](https://nodejs.org/en)
|
* [NodeJS](https://nodejs.org/en)
|
||||||
* This project uses `v20.10.0+` (npm `10.2.5`). Consider using [nvm](https://github.com/nvm-sh/nvm) for multiple NodeJS versions.
|
* This project uses `v20.10.0+` (npm `10.2.5`). Consider using [nvm](https://github.com/nvm-sh/nvm) for multiple NodeJS versions.
|
||||||
* To run dev in `ts-node`, using `v18.18.2` is recommended. **CAUTION**: `v18.19.0` or `lts/hydrogen` will not run properly.
|
* To run dev in `ts-node`, using `v18.18.2` is recommended.
|
||||||
* To run dev with `tsx`, you can use `v20.10.0` or earlier.
|
* To run dev with `tsx`, you can use `v20.10.0` or earlier.
|
||||||
* This project supports any NodeJS version above `16.x.x` to only allow ESModules.
|
* This project supports any NodeJS version above `16.x.x` to only allow ESModules.
|
||||||
* [Ollama](https://ollama.ai/)
|
* [Ollama](https://ollama.ai/)
|
||||||
* [Ollama Docker Image](https://hub.docker.com/r/ollama/ollama)
|
* [Ollama Docker Image](https://hub.docker.com/r/ollama/ollama)
|
||||||
* **IMPORTANT**: For Nvidia GPU setup, **install** `nvidia container toolkit/runtime` then **configure** it with Docker to utilize Nvidia driver.
|
|
||||||
|
> [!NOTE]
|
||||||
|
> For Nvidia GPU setup, **install** `nvidia container toolkit/runtime` then **configure** it with Docker to utilize Nvidia driver.
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
> `v18.X.X` or `lts/hydrogen` will not run properly for `npm run dev-mon`.
|
||||||
|
|
||||||
* [Discord Developer Portal](https://discord.com/developers/docs/intro)
|
* [Discord Developer Portal](https://discord.com/developers/docs/intro)
|
||||||
* [Discord.js Docs](https://discord.js.org/docs/packages/discord.js/main)
|
* [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 Docker (Ubuntu 20.04)](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04)
|
||||||
|
|||||||
1252
package-lock.json
generated
1252
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@@ -16,7 +16,7 @@
|
|||||||
"start": "docker compose build --no-cache && docker compose up -d",
|
"start": "docker compose build --no-cache && docker compose up -d",
|
||||||
"docker:start": "npm run docker:network && npm run docker:build && npm run docker:client && npm run docker:ollama",
|
"docker:start": "npm run docker:network && npm run docker:build && npm run docker:client && npm run docker:ollama",
|
||||||
"docker:start-cpu": "npm run docker:network && npm run docker:build && npm run docker:client && npm run docker:ollama-cpu",
|
"docker:start-cpu": "npm run docker:network && npm run docker:build && npm run docker:client && npm run docker:ollama-cpu",
|
||||||
"docker:clean": "docker rmi $(docker images --filter \"dangling=true\" -q --no-trunc)",
|
"docker:clean": "docker rm -f discord && docker rm -f ollama && docker rmi $(docker images --filter \"dangling=true\" -q --no-trunc)",
|
||||||
"docker:network": "docker network create --subnet=172.18.0.0/16 ollama-net",
|
"docker:network": "docker network create --subnet=172.18.0.0/16 ollama-net",
|
||||||
"docker:build": "docker build --no-cache -t discord/bot:$(node -p \"require('./package.json').version\") .",
|
"docker:build": "docker build --no-cache -t discord/bot:$(node -p \"require('./package.json').version\") .",
|
||||||
"docker:test": "docker run -d --rm -v discord:/src/app --name test discord/bot:$(node -p \"require('./package.json').version\") npm run test:run",
|
"docker:test": "docker run -d --rm -v discord:/src/app --name test discord/bot:$(node -p \"require('./package.json').version\") npm run test:run",
|
||||||
@@ -27,17 +27,17 @@
|
|||||||
"author": "Kevin Dang",
|
"author": "Kevin Dang",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.14.1",
|
"discord.js": "^14.15.3",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.4.5",
|
||||||
"ollama": "^0.5.0"
|
"ollama": "^0.5.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.10.5",
|
"@types/node": "^20.14.2",
|
||||||
"@vitest/coverage-v8": "^1.6.0",
|
"@vitest/coverage-v8": "^1.6.0",
|
||||||
"nodemon": "^3.0.2",
|
"nodemon": "^3.1.3",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"tsx": "^4.6.2",
|
"tsx": "^4.15.5",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.4.5",
|
||||||
"vitest": "^1.6.0"
|
"vitest": "^1.6.0"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const MessageStream: SlashCommand = {
|
|||||||
openConfig('config.json', interaction.commandName, interaction.options.get('stream')?.value)
|
openConfig('config.json', interaction.commandName, interaction.options.get('stream')?.value)
|
||||||
|
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
content: `Message streaming preferences for embed set to: \`${interaction.options.get('stream')?.value}\``,
|
content: `Message streaming preferences set to: \`${interaction.options.get('stream')?.value}\``,
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { EmbedBuilder, Message } from 'discord.js'
|
|||||||
import { ChatResponse, Ollama } from 'ollama'
|
import { ChatResponse, Ollama } from 'ollama'
|
||||||
import { ChatParams, UserMessage, streamResponse, blockResponse } from './index.js'
|
import { ChatParams, UserMessage, streamResponse, blockResponse } from './index.js'
|
||||||
import { Queue } from '../queues/queue.js'
|
import { Queue } from '../queues/queue.js'
|
||||||
|
import { AbortableAsyncIterator } from 'ollama/src/utils.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to send replies as normal text on discord like any other user
|
* Method to send replies as normal text on discord like any other user
|
||||||
@@ -19,7 +20,7 @@ export async function embedMessage(
|
|||||||
stream: boolean
|
stream: boolean
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// bot response
|
// bot response
|
||||||
let response: ChatResponse | AsyncGenerator<ChatResponse, any, unknown>
|
let response: ChatResponse | AbortableAsyncIterator<ChatResponse>
|
||||||
let result: string = ''
|
let result: string = ''
|
||||||
|
|
||||||
// initial message to client
|
// initial message to client
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Message } from 'discord.js'
|
|||||||
import { ChatResponse, Ollama } from 'ollama'
|
import { ChatResponse, Ollama } from 'ollama'
|
||||||
import { ChatParams, UserMessage, streamResponse, blockResponse } from './index.js'
|
import { ChatParams, UserMessage, streamResponse, blockResponse } from './index.js'
|
||||||
import { Queue } from '../queues/queue.js'
|
import { Queue } from '../queues/queue.js'
|
||||||
|
import { AbortableAsyncIterator } from 'ollama/src/utils.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to send replies as normal text on discord like any other user
|
* Method to send replies as normal text on discord like any other user
|
||||||
@@ -19,7 +20,7 @@ export async function normalMessage(
|
|||||||
stream: boolean
|
stream: boolean
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// bot's respnse
|
// bot's respnse
|
||||||
let response: ChatResponse | AsyncGenerator<ChatResponse, any, unknown>
|
let response: ChatResponse | AbortableAsyncIterator<ChatResponse>
|
||||||
let result: string = ''
|
let result: string = ''
|
||||||
|
|
||||||
await message.channel.send('Generating Response . . .').then(async sentMessage => {
|
await message.channel.send('Generating Response . . .').then(async sentMessage => {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { ChatResponse } from "ollama"
|
import { ChatResponse } from "ollama"
|
||||||
import { ChatParams } from "./index.js"
|
import { ChatParams } from "./index.js"
|
||||||
|
import { AbortableAsyncIterator } from "ollama/src/utils.js"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to query the Ollama client for async generation
|
* Method to query the Ollama client for async generation
|
||||||
* @param params
|
* @param params
|
||||||
* @returns Asyn
|
* @returns Asyn
|
||||||
*/
|
*/
|
||||||
export async function streamResponse(params: ChatParams): Promise<AsyncGenerator<ChatResponse, any, unknown>> {
|
export async function streamResponse(params: ChatParams): Promise<AbortableAsyncIterator<ChatResponse>> {
|
||||||
return await params.ollama.chat({
|
return await params.ollama.chat({
|
||||||
model: params.model,
|
model: params.model,
|
||||||
messages: params.msgHist,
|
messages: params.msgHist,
|
||||||
@@ -16,7 +17,7 @@ export async function streamResponse(params: ChatParams): Promise<AsyncGenerator
|
|||||||
top_k: 70
|
top_k: 70
|
||||||
},
|
},
|
||||||
stream: true
|
stream: true
|
||||||
})
|
}) as unknown as AbortableAsyncIterator<ChatResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
// Dependent on node version
|
// Dependent on node version
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"module": "Node16",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "Node16",
|
"moduleResolution": "NodeNext",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
// We must set the type
|
// We must set the type
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
@@ -13,11 +13,17 @@
|
|||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
// We can import json files like JavaScript
|
// We can import json files like JavaScript
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
// Decompile .ts to .js into a folder named dist
|
"skipLibCheck": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
// Decompile .ts to .js into a folder named build
|
||||||
"outDir": "build",
|
"outDir": "build",
|
||||||
"rootDir": "src"
|
"rootDir": "src",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"*": ["node_modules/"]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// environment for env vars
|
// environment for env vars
|
||||||
"include": ["src/**/*"],
|
"include": ["src/**/*.ts"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user