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
95 stars 11 forks source link

Log Binding for All Interactions #47

Open kevinthedang opened 7 months ago

kevinthedang commented 7 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)
            }
        })
    }
}
JT2M0L3Y commented 3 months ago

I have mirrored the above method for log binding across commands and utilties in place. Though I have explored options for abstracting this into a universal log bind, I have not found a successful solution yet.