37 lines
914 B
Python
37 lines
914 B
Python
# 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)
|
|
|