Roll NPM Dependencies Forward (#136)

* update channel as sendable

* Update: Casting SendableChannels Once

* Remove: another semicolon

* Update: version increment

---------

Co-authored-by: kevinthedang <kevinthedang_1@outlook.com>
This commit is contained in:
Jonathan Smoley
2024-11-08 10:13:16 -08:00
committed by GitHub
parent 68a5e097fe
commit 1ccd1a012e
5 changed files with 643 additions and 408 deletions

View File

@@ -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.7.0 image: kevinthedang/discord-ollama:0.7.1
environment: environment:
CLIENT_TOKEN: ${CLIENT_TOKEN} CLIENT_TOKEN: ${CLIENT_TOKEN}
OLLAMA_IP: ${OLLAMA_IP} OLLAMA_IP: ${OLLAMA_IP}

1009
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "discord-ollama", "name": "discord-ollama",
"version": "0.7.0", "version": "0.7.1",
"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",
@@ -26,17 +26,17 @@
"author": "Kevin Dang", "author": "Kevin Dang",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"discord.js": "^14.15.3", "discord.js": "^14.16.3",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"ollama": "^0.5.9" "ollama": "^0.5.9"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.5", "@types/node": "^22.9.0",
"@vitest/coverage-v8": "^2.1.2", "@vitest/coverage-v8": "^2.1.4",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
"tsx": "^4.19.1", "tsx": "^4.19.2",
"typescript": "^5.6.3", "typescript": "^5.6.3",
"vitest": "^2.1.2" "vitest": "^2.1.4"
}, },
"type": "module", "type": "module",
"engines": { "engines": {

View File

@@ -1,4 +1,4 @@
import { EmbedBuilder, Message } from 'discord.js' import { EmbedBuilder, Message, SendableChannels } 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'
@@ -28,7 +28,8 @@ export async function embedMessage(
.setColor('#00FF00') .setColor('#00FF00')
// send the message // send the message
const sentMessage = await message.channel.send({ embeds: [botMessage] }) const channel = message.channel as SendableChannels
const sentMessage = await channel.send({ embeds: [botMessage] })
// create params // create params
const params: ChatParams = { const params: ChatParams = {
@@ -48,12 +49,12 @@ export async function embedMessage(
// exceeds handled length // exceeds handled length
if (result.length > 5000) { if (result.length > 5000) {
const errorEmbed = new EmbedBuilder() const errorEmbed = new EmbedBuilder()
.setTitle(`Responding to ${message.author.tag}`) .setTitle(`Responding to ${message.author.tag}`)
.setDescription(`Response length ${result.length} has exceeded Discord maximum.\n\nLong Stream messages not supported.`) .setDescription(`Response length ${result.length} has exceeded Discord maximum.\n\nLong Stream messages not supported.`)
.setColor('#00FF00') .setColor('#00FF00')
// send error // send error
message.channel.send({ embeds: [errorEmbed] }) channel.send({ embeds: [errorEmbed] })
break // cancel loop and stop break // cancel loop and stop
} }
@@ -90,7 +91,7 @@ export async function embedMessage(
.setDescription(result.slice(0, 5000) || 'No Content to Provide...') .setDescription(result.slice(0, 5000) || 'No Content to Provide...')
.setColor('#00FF00') .setColor('#00FF00')
message.channel.send({ embeds: [whileEmbed] }) channel.send({ embeds: [whileEmbed] })
result = result.slice(5000) result = result.slice(5000)
} }
@@ -100,7 +101,7 @@ export async function embedMessage(
.setColor('#00FF00') .setColor('#00FF00')
// rest of the response // rest of the response
message.channel.send({ embeds: [lastEmbed] }) channel.send({ embeds: [lastEmbed] })
} else { } else {
// only need to create 1 embed, handles 6000 characters // only need to create 1 embed, handles 6000 characters
const newEmbed = new EmbedBuilder() const newEmbed = new EmbedBuilder()

View File

@@ -1,4 +1,4 @@
import { Message } from 'discord.js' import { Message, SendableChannels } 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'
@@ -20,8 +20,9 @@ export async function normalMessage(
// bot's respnse // bot's respnse
let response: ChatResponse | AbortableAsyncIterator<ChatResponse> let response: ChatResponse | AbortableAsyncIterator<ChatResponse>
let result: string = '' let result: string = ''
const channel = message.channel as SendableChannels
await message.channel.send('Generating Response . . .').then(async sentMessage => { await channel.send('Generating Response . . .').then(async sentMessage => {
try { try {
const params: ChatParams = { const params: ChatParams = {
model: model, model: model,
@@ -39,7 +40,7 @@ export async function normalMessage(
result = portion.message.content result = portion.message.content
// new message block, wait for it to send and assign new block to respond. // new message block, wait for it to send and assign new block to respond.
await message.channel.send("Creating new stream block...").then(sentMessage => { messageBlock = sentMessage }) await channel.send("Creating new stream block...").then(sentMessage => { messageBlock = sentMessage })
} else { } else {
result += portion.message.content result += portion.message.content
@@ -61,12 +62,12 @@ export async function normalMessage(
// handle for rest of message that is >2000 // handle for rest of message that is >2000
while (result.length > 2000) { while (result.length > 2000) {
message.channel.send(result.slice(0, 2000)) channel.send(result.slice(0, 2000))
result = result.slice(2000) result = result.slice(2000)
} }
// last part of message // last part of message
message.channel.send(result) channel.send(result)
} else // edit the 'generic' response to new message since <2000 } else // edit the 'generic' response to new message since <2000
sentMessage.edit(result) sentMessage.edit(result)
} }