mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2025-12-13 12:06:06 -05:00
Docker Container Setup (#15)
* minor package update and env * added docker scripts * added working docker compose * fixed docker container bridge
This commit is contained in:
@@ -1,21 +1,24 @@
|
||||
import type { ClientEvents, Awaitable, Client } from 'discord.js'
|
||||
import { Ollama } from 'ollama'
|
||||
|
||||
// Export events through here to reduce amount of imports
|
||||
export { Events } from 'discord.js'
|
||||
|
||||
export type LogMethod = (...args: unknown[]) => void
|
||||
export type EventKeys = keyof ClientEvents // only wants keys of ClientEvents object
|
||||
export type Tokens = {
|
||||
channel: string,
|
||||
model: string,
|
||||
clientUid: string
|
||||
}
|
||||
|
||||
// Event properties
|
||||
export interface EventProps {
|
||||
client: Client
|
||||
log: LogMethod
|
||||
msgHist: { role: string, content: string }[]
|
||||
tokens: {
|
||||
channel: string,
|
||||
model: string,
|
||||
clientUid: string
|
||||
}
|
||||
tokens: Tokens,
|
||||
ollama: Ollama
|
||||
}
|
||||
export type EventCallback<T extends EventKeys> = (
|
||||
props: EventProps,
|
||||
@@ -36,11 +39,8 @@ export function registerEvents(
|
||||
client: Client,
|
||||
events: Event[],
|
||||
msgHist: { role: string, content: string }[],
|
||||
tokens: {
|
||||
channel: string,
|
||||
model: string,
|
||||
clientUid: string
|
||||
}
|
||||
tokens: Tokens,
|
||||
ollama: Ollama
|
||||
): void {
|
||||
for (const { key, callback } of events) {
|
||||
client.on(key, (...args) => {
|
||||
@@ -49,7 +49,7 @@ export function registerEvents(
|
||||
|
||||
// Handle Errors, call callback, log errors as needed
|
||||
try {
|
||||
callback({ client, log, msgHist, tokens }, ...args)
|
||||
callback({ client, log, msgHist, tokens, ollama }, ...args)
|
||||
} catch (error) {
|
||||
log('[Uncaught Error]', error)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EmbedBuilder, Message } from 'discord.js'
|
||||
import ollama, { ChatResponse } from 'ollama'
|
||||
import { ChatResponse, Ollama } from 'ollama'
|
||||
|
||||
/**
|
||||
* Method to send replies as normal text on discord like any other user
|
||||
@@ -8,7 +8,8 @@ import ollama, { ChatResponse } from 'ollama'
|
||||
* @param msgHist message history between user and model
|
||||
*/
|
||||
export async function embedMessage(
|
||||
message: Message,
|
||||
message: Message,
|
||||
ollama: Ollama,
|
||||
tokens: {
|
||||
channel: string,
|
||||
model: string
|
||||
@@ -44,17 +45,19 @@ export async function embedMessage(
|
||||
stream: false
|
||||
})
|
||||
|
||||
// dummy message to let user know that query is underway
|
||||
const newEmbed = new EmbedBuilder()
|
||||
.setTitle(`Responding to ${message.author.tag}`)
|
||||
.setDescription(response.message.content)
|
||||
.setDescription(response.message.content || 'No Content to Provided...')
|
||||
.setColor('#00FF00')
|
||||
|
||||
// edit the message
|
||||
sentMessage.edit({ embeds: [newEmbed] })
|
||||
} catch(error: any) {
|
||||
console.log(`[Event: messageEmbed] Error creating message: ${error.message}`);
|
||||
const errorEmbed = new EmbedBuilder()
|
||||
.setTitle(`Responding to ${message.author.tag}`)
|
||||
.setDescription(error.error)
|
||||
.setDescription(`Issue creating response: ${error.message}`)
|
||||
.setColor('#00FF00')
|
||||
|
||||
// send back error
|
||||
|
||||
Reference in New Issue
Block a user