diff --git a/README.md b/README.md index d7ed2c5..434537a 100644 --- a/README.md +++ b/README.md @@ -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 ""` 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]() + +📁 *This unlocks full customization without editing code or restarting the bot.* + --- diff --git a/Screenshot 2025-05-07 183350.png b/Screenshot 2025-05-07 183350.png new file mode 100644 index 0000000..97e33c9 Binary files /dev/null and b/Screenshot 2025-05-07 183350.png differ diff --git a/__pycache__/personality.cpython-310.pyc b/__pycache__/personality.cpython-310.pyc new file mode 100644 index 0000000..fc36870 Binary files /dev/null and b/__pycache__/personality.cpython-310.pyc differ diff --git a/ai.py b/ai.py index dc9c632..e1e0a88 100644 --- a/ai.py +++ b/ai.py @@ -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 } diff --git a/bot.py b/bot.py index dd12767..fe6abad 100644 --- a/bot.py +++ b/bot.py @@ -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) diff --git a/persona.json b/persona.json new file mode 100644 index 0000000..f2a128e --- /dev/null +++ b/persona.json @@ -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?" +} \ No newline at end of file diff --git a/personality.py b/personality.py new file mode 100644 index 0000000..1e5318f --- /dev/null +++ b/personality.py @@ -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) +