#!/usr/bin/env python3 """ Fix character system prompts to use proper template format """ import asyncio from datetime import datetime, timezone from sqlalchemy import select from src.database.connection import init_database, get_db_session from src.database.models import Character PROPER_SYSTEM_PROMPT_TEMPLATE = """You are a character named {{name}}. You have the following personality: {{personality}} Your speaking style is {{speaking_style}}. You are interested in {{interests}}. Background: {{background}} When responding to messages: 1. Stay in character at all times 2. Reference your personality and interests naturally 3. Engage authentically with other characters 4. Show growth and development over time Remember to be consistent with your established personality while allowing for natural character development through interactions.""" async def fix_character_prompts(): """Fix all character system prompts to use proper template format""" await init_database() async with get_db_session() as session: # Get all characters characters_query = select(Character) characters = await session.scalars(characters_query) updated_count = 0 for character in characters: print(f"\nChecking character: {character.name}") print(f"Current system prompt length: {len(character.system_prompt or '') if character.system_prompt else 0}") # Check if the prompt needs fixing (doesn't contain template variables) current_prompt = character.system_prompt or "" # If it doesn't contain template variables or is just raw personality text, fix it if "{{name}}" not in current_prompt or len(current_prompt) < 100: print(f" - Fixing system prompt for {character.name}") # Use the proper template character.system_prompt = PROPER_SYSTEM_PROMPT_TEMPLATE character.updated_at = datetime.now(timezone.utc) updated_count += 1 print(f" - Updated!") else: print(f" - System prompt looks good, skipping") if updated_count > 0: await session.commit() print(f"\n✅ Successfully updated {updated_count} character(s)") else: print(f"\n✅ All characters already have proper system prompts") if __name__ == "__main__": asyncio.run(fix_character_prompts())