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

Infinite Message Length for Chat Generation #50

Closed kevinthedang closed 2 months ago

kevinthedang commented 2 months ago

Issue

Solution

await message.channel.send('Generating Response . . .').then(async sentMessage => {
    try {
        // Attempt to query model for message
        response = await ollama.chat({
            model: tokens.model,
            messages: msgHist.getItems(),
            options: {
                num_thread: 8, // remove if optimization needed further
                mirostat: 1,
                mirostat_tau: 2.0,
                top_k: 70
            },
            stream: false
        })

        // check if message length > discord max for normal messages
        if (response.message.content.length > 2000) {
            sentMessage.edit(response.message.content.slice(0, 2000))
            message.channel.send(response.message.content.slice(2000))
        } else // edit the 'generic' response to new message
            sentMessage.edit(response.message.content)            
    } catch(error: any) {
        console.log(`[Util: messageNormal] Error creating message: ${error.message}`)
        sentMessage.edit(`**Response generation failed.**\n\nReason: ${error.message}`)
    }
})