changes to src/events/messageCreate.ts, Dockerfile, Modelfile, docker-compose.yml

This commit is contained in:
2025-05-18 16:15:18 -04:00
parent 87a70ce887
commit d361702f6b
2 changed files with 9 additions and 4 deletions

View File

@@ -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}`))