const axios = require('axios'); /** * Generates a persona-driven response from an LLM and returns the result. * * @param {string} message - The input prompt to complete. * @param {object} options - Persona and LLM settings. * @returns {Promise} - A trimmed response string. */ async function chatWithPersona(message, options) { const { botName = 'Cletus', persona = `a cranky teenager with a sense of dark humor and sarcasm. you have short responses and don't repeat yourself.`, length = 20, ollamaUrl = 'http://192.168.1.3:11434/api/generate', model = 'gemma3' } = options; const prompt = `You are a minecraft bot named ${botName}. ` + `You don't know that you're a bot though. Instead, you are a ${persona}. ` + `Keep your responses around ${length}. Respond to this: ${message}`; try { const response = await axios.post(ollamaUrl, { model, prompt, stream: false }); const aiReply = response.data.response?.trim().replace(/^"|"$/g, ''); return aiReply || "...What?"; } catch (err) { console.error("AI response failed:", err.message); return "I'm too moody to respond right now."; } } module.exports = { chatWithPersona };