Implement comprehensive LLM provider system with global cost protection
- Add multi-provider LLM architecture supporting OpenRouter, OpenAI, Gemini, and custom providers - Implement global LLM on/off switch with default DISABLED state for cost protection - Add per-character LLM configuration with provider-specific models and settings - Create performance-optimized caching system for LLM enabled status checks - Add API key validation before enabling LLM providers to prevent broken configurations - Implement audit logging for all LLM enable/disable actions for cost accountability - Create comprehensive admin UI with prominent cost warnings and confirmation dialogs - Add visual indicators in character list for custom AI model configurations - Build character-specific LLM client system with global fallback mechanism - Add database schema support for per-character LLM settings - Implement graceful fallback responses when LLM is globally disabled - Create provider testing and validation system for reliable connections
This commit is contained in:
65
fix_character_prompts.py
Normal file
65
fix_character_prompts.py
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/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())
|
||||
Reference in New Issue
Block a user