mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-12 11:56:06 -05:00
Compare commits
2 Commits
caccb47976
...
9ad36bb144
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ad36bb144 | ||
|
|
e07e8fbf89 |
2
.github/workflows/coverage.yml
vendored
2
.github/workflows/coverage.yml
vendored
@@ -36,7 +36,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Collect Code Coverage
|
- name: Collect Code Coverage
|
||||||
run: |
|
run: |
|
||||||
LINE_PCT=$(npm run test:coverage | tail -2 | head -1 | awk '{print $3}')
|
LINE_PCT=$(npm run coverage | tail -2 | head -1 | awk '{print $3}')
|
||||||
echo "COVERAGE=$LINE_PCT" >> $GITHUB_ENV
|
echo "COVERAGE=$LINE_PCT" >> $GITHUB_ENV
|
||||||
|
|
||||||
- name: Upload Code Coverage
|
- name: Upload Code Coverage
|
||||||
|
|||||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -47,4 +47,4 @@ jobs:
|
|||||||
|
|
||||||
- name: Test Application
|
- name: Test Application
|
||||||
run: |
|
run: |
|
||||||
npm run test:run
|
npm run tests
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ services:
|
|||||||
build: ./ # find docker file in designated path
|
build: ./ # find docker file in designated path
|
||||||
container_name: discord
|
container_name: discord
|
||||||
restart: always # rebuild container always
|
restart: always # rebuild container always
|
||||||
image: kevinthedang/discord-ollama:0.8.4
|
image: kevinthedang/discord-ollama:0.8.5
|
||||||
environment:
|
environment:
|
||||||
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
||||||
OLLAMA_IP: ${OLLAMA_IP}
|
OLLAMA_IP: ${OLLAMA_IP}
|
||||||
|
|||||||
20
package-lock.json
generated
20
package-lock.json
generated
@@ -1,18 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.8.4",
|
"version": "0.8.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.8.4",
|
"version": "0.8.5",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.18.0",
|
"discord.js": "^14.18.0",
|
||||||
"dotenv": "^16.5.0",
|
"dotenv": "^16.5.0",
|
||||||
"ollama": "^0.5.15",
|
"ollama": "^0.5.15",
|
||||||
"redis": "^4.7.0"
|
"redis": "^4.7.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.13.14",
|
"@types/node": "^22.13.14",
|
||||||
@@ -779,9 +779,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@redis/client": {
|
"node_modules/@redis/client": {
|
||||||
"version": "1.6.0",
|
"version": "1.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/@redis/client/-/client-1.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/@redis/client/-/client-1.6.1.tgz",
|
||||||
"integrity": "sha512-aR0uffYI700OEEH4gYnitAnv3vzVGXCFvYfdpu/CJKvk4pHfLPEy/JSZyrpQ+15WhXe1yJRXLtfQ84s4mEXnPg==",
|
"integrity": "sha512-/KCsg3xSlR+nCK8/8ZYSknYxvXHwubJrU82F3Lm1Fp6789VQ0/3RJKfsmRXjqfaTA++23CvC3hqmqe/2GEt6Kw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cluster-key-slot": "1.1.2",
|
"cluster-key-slot": "1.1.2",
|
||||||
@@ -2099,16 +2099,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/redis": {
|
"node_modules/redis": {
|
||||||
"version": "4.7.0",
|
"version": "4.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/redis/-/redis-4.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/redis/-/redis-4.7.1.tgz",
|
||||||
"integrity": "sha512-zvmkHEAdGMn+hMRXuMBtu4Vo5P6rHQjLoHftu+lBqq8ZTA3RCVC/WzD790bkKKiNFp7d5/9PcSD19fJyyRvOdQ==",
|
"integrity": "sha512-S1bJDnqLftzHXHP8JsT5II/CtHWQrASX5K96REjWjlmWKrviSOLWmM7QnRLstAWsu1VBBV1ffV6DzCvxNP0UJQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"./packages/*"
|
"./packages/*"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@redis/bloom": "1.2.0",
|
"@redis/bloom": "1.2.0",
|
||||||
"@redis/client": "1.6.0",
|
"@redis/client": "1.6.1",
|
||||||
"@redis/graph": "1.1.1",
|
"@redis/graph": "1.1.1",
|
||||||
"@redis/json": "1.0.7",
|
"@redis/json": "1.0.7",
|
||||||
"@redis/search": "1.2.0",
|
"@redis/search": "1.2.0",
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-ollama",
|
"name": "discord-ollama",
|
||||||
"version": "0.8.4",
|
"version": "0.8.5",
|
||||||
"description": "Ollama Integration into discord",
|
"description": "Ollama Integration into discord",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"exports": "./build/index.js",
|
"exports": "./build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:run": "vitest run",
|
"tests": "vitest run",
|
||||||
"test:coverage": "vitest run --coverage",
|
"coverage": "vitest run --coverage",
|
||||||
"watch": "tsx watch src",
|
"watch": "tsx watch src",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"prod": "node .",
|
"prod": "node .",
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
"discord.js": "^14.18.0",
|
"discord.js": "^14.18.0",
|
||||||
"dotenv": "^16.5.0",
|
"dotenv": "^16.5.0",
|
||||||
"ollama": "^0.5.15",
|
"ollama": "^0.5.15",
|
||||||
"redis": "^4.7.0"
|
"redis": "^4.7.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.13.14",
|
"@types/node": "^22.13.14",
|
||||||
|
|||||||
@@ -34,10 +34,14 @@ registerEvents(client, Events, messageHistory, ollama, Keys.defaultModel)
|
|||||||
|
|
||||||
// Try to connect to redis
|
// Try to connect to redis
|
||||||
await redis.connect()
|
await redis.connect()
|
||||||
.then(() => console.log('[Redis] Connected'))
|
.then(response => {
|
||||||
.catch((error) => {
|
console.log('[Redis] Successfully Connected')
|
||||||
console.error('[Redis] Connection Error', error)
|
})
|
||||||
process.exit(1)
|
.catch(error => {
|
||||||
|
console.error('[Redis] Connection Error. See error below:\n', error)
|
||||||
|
console.warn('[Redis] Failed to connect to Redis Database, using local system')
|
||||||
|
// TODO: create boolean flag that will probably be used in messageCreate.ts if redis database is down
|
||||||
|
// When implementing this boolean flag, move connection to database BEFORE the registerEvents method
|
||||||
})
|
})
|
||||||
|
|
||||||
// Try to log in the client
|
// Try to log in the client
|
||||||
|
|||||||
@@ -37,9 +37,21 @@ export const DeleteModel: SlashCommand = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if model exists
|
// check if model exists
|
||||||
const modelExists: boolean = await ollama.list()
|
const modelExists = await ollama.list()
|
||||||
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
||||||
|
.catch(error => {
|
||||||
|
console.error(`[Command: delete-model] Failed to connect with Ollama service. Error: ${error.message}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Validate for any issue or if service is running
|
||||||
|
if (!modelExists) {
|
||||||
|
interaction.editReply({
|
||||||
|
content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).`
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// call ollama to delete model
|
// call ollama to delete model
|
||||||
if (modelExists) {
|
if (modelExists) {
|
||||||
|
|||||||
@@ -36,9 +36,21 @@ export const PullModel: SlashCommand = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if model was already pulled
|
// check if model was already pulled, if the ollama service isn't running throw error
|
||||||
const modelExists: boolean = await ollama.list()
|
const modelExists = await ollama.list()
|
||||||
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
.then(response => response.models.some((model: ModelResponse) => model.name.startsWith(modelInput)))
|
||||||
|
.catch(error => {
|
||||||
|
console.error(`[Command: pull-model] Failed to connect with Ollama service. Error: ${error.message}`)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Validate for any issue or if service is running
|
||||||
|
if (!modelExists) {
|
||||||
|
interaction.editReply({
|
||||||
|
content: `The Ollama service is not running. Please turn on/download the [service](https://ollama.com/).`
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// call ollama to pull desired model
|
// call ollama to pull desired model
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ export const SwitchModel: SlashCommand = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(`[Command: switch-model] Failed to connect with Ollama service. Error: ${error.message}`)
|
||||||
|
})
|
||||||
// todo: problem can be here if async messes up
|
// todo: problem can be here if async messes up
|
||||||
if (switchSuccess) {
|
if (switchSuccess) {
|
||||||
// set model now that it exists
|
// set model now that it exists
|
||||||
@@ -56,10 +59,13 @@ export const SwitchModel: SlashCommand = {
|
|||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: `Could not find **${modelInput}** in local model library.\n\nPlease contact an server admin for access to this model.`
|
content: `Could not find **${modelInput}** in local model library.\n\nPlease contact an server admin for access to this model.`
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
// could not resolve user model switch
|
// could not resolve user model switch
|
||||||
|
if (error.message.includes("fetch failed") as string)
|
||||||
|
error.message = "The Ollama service is not running. Please turn on/download the [service](https://ollama.com/)."
|
||||||
|
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: `Unable to switch user preferred model to **${modelInput}**.\n\n${error}\n\nPossible solution is to request an server admin run \`/pull-model ${modelInput}\` and try again.`
|
content: `Unable to switch user preferred model to **${modelInput}**.\n\n${error.message}`
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,9 +71,8 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
|
|||||||
userConfig = await new Promise((resolve, reject) => {
|
userConfig = await new Promise((resolve, reject) => {
|
||||||
getUserConfig(`${message.author.username}-config.json`, (config) => {
|
getUserConfig(`${message.author.username}-config.json`, (config) => {
|
||||||
if (config === undefined) {
|
if (config === undefined) {
|
||||||
openConfig(`${message.author.username}-config.json`, 'message-style', false)
|
|
||||||
openConfig(`${message.author.username}-config.json`, 'switch-model', defaultModel)
|
openConfig(`${message.author.username}-config.json`, 'switch-model', defaultModel)
|
||||||
reject(new Error('No User Preferences is set up.\n\nCreating preferences file with \`message-style\` set as \`false\` for regular message style.\nPlease try chatting again.'))
|
reject(new Error(`No User Preferences is set up.\n\nCreating new preferences file for ${message.author.username}\nPlease try chatting again.`))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,10 +74,11 @@ export async function normalMessage(
|
|||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(`[Util: messageNormal] Error creating message: ${error.message}`)
|
console.log(`[Util: messageNormal] Error creating message: ${error.message}`)
|
||||||
if (error.message.includes('try pulling it first'))
|
if (error.message.includes('fetch failed'))
|
||||||
sentMessage.edit(`**Response generation failed.**\n\nReason: You do not have the ${model} downloaded. Ask an admin to pull it using the \`pull-model\` command.`)
|
error.message = 'Missing ollama service on machine'
|
||||||
else
|
else if (error.message.includes('try pulling it first'))
|
||||||
sentMessage.edit(`**Response generation failed.**\n\nReason: ${error.message}`)
|
error.message = `You do not have the ${model} downloaded. Ask an admin to pull it using the \`pull-model\` command.`
|
||||||
|
sentMessage.edit(`**Response generation failed.**\n\nReason: ${error.message}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user