From d361702f6bed28a4258cf093b64a7559cbff20b8 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 18 May 2025 16:15:18 -0400 Subject: [PATCH] changes to src/events/messageCreate.ts, Dockerfile, Modelfile, docker-compose.yml --- Modelfile | 3 ++- src/events/messageCreate.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Modelfile b/Modelfile index 14f0f7a..bd6799a 100644 --- a/Modelfile +++ b/Modelfile @@ -31,7 +31,8 @@ You are a Discord chatbot with a dynamic personality defined in [CHARACTER] befo - user_sentiment: An object mapping user IDs to sentiment scores (0-1). A sentiment score of 0 is strong dislike, 0.5 is neutral, and 1.0 is strong like or love. - redis_ops: An array of objects with "action" ("set" or "get"), "key" (prefixed with "bot:" or "user:"), and optional "value" (for set operations). - need_help: Boolean indicating if the user needs assistance. -Only use "set" or "get" for redis_ops actions. Ensure keys are prefixed with "bot:" or "user:". Do not include metadata or Redis commands in the reply field. +Output ONLY the JSON object, with no Markdown, code fences, or extra text. Example: +{"status":"success","reply":"Hi","metadata":{"timestamp":"2025-05-18T16:00:00Z","self_sentiment":0.5,"user_sentiment":{"":0.5},"redis_ops":[{"action":"set","key":"user::sentiment","value":0.5}],"need_help":false}} [CHARACTER] [SENTIMENT] diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts index 6666026..f146614 100644 --- a/src/events/messageCreate.ts +++ b/src/events/messageCreate.ts @@ -160,10 +160,10 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client // Load personality let personality: string try { - // Fix __dirname for ESM by using import.meta.url + // Point to /app/src/personality.json const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) - const personalityPath = path.join(__dirname, '../../personality.json') + const personalityPath = path.join(__dirname, '../personality.json') const personalityData = await fs.readFile(personalityPath, 'utf-8') const personalityJson = JSON.parse(personalityData) personality = personalityJson.character || 'You are a friendly and helpful AI assistant.' @@ -195,7 +195,11 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client try { const botSentimentRaw = await redis.get(botSentimentKey) botSentiment = parseFloat(botSentimentRaw || '0.5') - if (isNaN(botSentiment) || botSentiment < 0 || botSentiment > 1) { + if (botSentimentRaw === null) { + log(`Bot sentiment not initialized. Setting to 0.5.`) + botSentiment = 0.5 + await redis.set(botSentimentKey, '0.5').catch((err: Error) => log(`Failed to set default bot sentiment: ${err.message}`)) + } else if (isNaN(botSentiment) || botSentiment < 0 || botSentiment > 1) { log(`Invalid bot sentiment: ${botSentimentRaw}. Using default 0.5.`) botSentiment = 0.5 await redis.set(botSentimentKey, '0.5').catch((err: Error) => log(`Failed to set default bot sentiment: ${err.message}`))