changes to src/events/messageCreate.ts, Dockerfile, Modelfile, docker-compose.yml
This commit is contained in:
@@ -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":{"<user_id>":0.5},"redis_ops":[{"action":"set","key":"user:<user_id>:sentiment","value":0.5}],"need_help":false}}
|
||||
|
||||
[CHARACTER]
|
||||
[SENTIMENT]
|
||||
|
||||
@@ -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}`))
|
||||
|
||||
Reference in New Issue
Block a user