kevinthedang / discord-ollama

Discord Bot that utilizes Ollama to interact with any Large Language Models to talk with users and allow them to host/create their own models.
Creative Commons Attribution 4.0 International
42 stars 4 forks source link

Log Binding for All Interactions #47

Open kevinthedang opened 2 months ago

kevinthedang commented 2 months ago

Issue

Notes

Sample Binding in events.ts

export function registerEvents(
    client: Client, 
    events: Event[], 
    msgHist: Queue<UserMessage>,
    tokens: Tokens,
    ollama: Ollama
): void {
    for (const { key, callback } of events) {
        client.on(key, (...args) => {
            // Create a new log method for this event
            const log = console.log.bind(console, `[Event: ${key}]`)

            // Handle Errors, call callback, log errors as needed
            try {
                callback({ client, log, msgHist, tokens, ollama }, ...args)
            } catch (error) {
                log('[Uncaught Error]', error)
            }
        })
    }
}