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:
Kevin Dang
2024-02-07 09:59:06 -08:00
committed by GitHub
parent 89c19990fa
commit ca6b8c3f9c
13 changed files with 124 additions and 337 deletions

View File

@@ -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)
}

View File

@@ -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