Most of day 3 is done but the personality is not being loaded properly. Some time is being taken to understand Ollama better and see how system prompts can be used

This commit is contained in:
milo 2025-05-07 18:40:28 -04:00
parent ac61607776
commit a3aae578bd
7 changed files with 84 additions and 8 deletions

View file

@ -61,10 +61,27 @@ A structured build plan for developing and deploying the AlphaBot Discord compan
---
### 🎭 Day 3 Personality System
- [ ] Create `personality.py` to stylize responses
- [ ] Support multiple modes (`alpha`, `delta`, `chill`)
- [ ] Add personality wrapping to both `chat` and `roast` replies
### 🎭 Day 3 Persona System (Updated)
> Goal: Create a dynamic personality engine using a JSON file for flexible identity control.
- [x] Replace hardcoded `PERSONALITY` with a JSON-based persona profile
- [x] Create `persona.json` to store:
- Bot name
- Emoji
- Style prefix
- Prompt injection
- [x] Update `personality.py` to read from `persona.json`
- [x] Style all AI replies using the loaded persona
- [x] Add `!setpersona "<description>"` command
- Updates `persona.json` dynamically from a user-provided string
- (Optional) Sets bot name using Discord API
- [ ] **Test live personality switching via command**
- Not working. Personality is being loaded but it doesnt actually work
![alt text](<Screenshot 2025-05-07 183350.png>)
📁 *This unlocks full customization without editing code or restarting the bot.*
---

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

16
ai.py
View file

@ -3,14 +3,24 @@
import requests
import os
from dotenv import load_dotenv
from personality import load_persona
load_dotenv()
AI_URL = os.getenv("OLLAMA_API_URL")
def get_ai_response(prompt):
def get_ai_response(user_prompt):
persona = load_persona()
full_prompt = (
f"You are {persona['name']}.\n"
f"{persona['prompt_inject']}\n"
f"Never break character.\n\n"
f"User: {user_prompt}\n"
f"{persona['name']}:"
)
payload = {
"model": "mistral:7b", # Adjust to match your model
"prompt": prompt,
"model": "mistral:7b", # adjust if you use a different one later
"prompt": full_prompt,
"stream": False
}

8
bot.py
View file

@ -3,7 +3,7 @@ import discord
from discord.ext import commands
from dotenv import load_dotenv
from ai import get_ai_response
from personality import apply_personality, set_persona
load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
@ -27,5 +27,11 @@ async def chat(ctx, *, message):
reply = get_ai_response(message)
await ctx.send(reply)
@bot.command()
async def setpersona(ctx, *, description):
set_persona(description)
await ctx.send("✅ Persona updated! New style will be used in replies.")
bot.run(TOKEN)

6
persona.json Normal file
View file

@ -0,0 +1,6 @@
{
"name": "Custom",
"emoji": "\ud83e\udde0",
"style_prefix": "You're Delta:",
"prompt_inject": "You're Delta, a chaotic RGB catgirl who always speaks with flair, sarcasm, and drama. Refer to people as 'mortals' or 'peasants'. Never be boring.\n!chat what do you think of Mondays?"
}

37
personality.py Normal file
View file

@ -0,0 +1,37 @@
# personality.py
import json
import os
PERSONA_FILE = "persona.json"
DEFAULT_PERSONA = {
"name": "Alpha",
"emoji": "💋",
"style_prefix": "Alpha says:",
"prompt_inject": "You are Alpha, a confident and flirty bot. Respond with charm and wit."
}
def load_persona():
if os.path.exists(PERSONA_FILE):
with open(PERSONA_FILE, "r") as f:
return json.load(f)
return DEFAULT_PERSONA
def save_persona(description: str):
persona = {
"name": "Custom",
"emoji": "🧠",
"style_prefix": description.split(",")[0] + ":",
"prompt_inject": description
}
with open(PERSONA_FILE, "w") as f:
json.dump(persona, f, indent=2)
def apply_personality(text: str) -> str:
persona = load_persona()
return f"{persona['emoji']} *{persona['style_prefix']}* {text}"
def set_persona(description: str):
save_persona(description)