import sys import os import asyncio import json from pathlib import Path # Add app to path sys.path.insert(0, '/app') from services.provider_factory import ProviderFactory from utils.rag_chat import RAGChatService from deps import get_qdrant_client from config import get_settings async def test_roles(): print("🌲 Testing ALL Roles with Gemini 2.0 & RAG...") # Load Config with open("crumbforest_config.json", "r") as f: config = json.load(f) roles = config.get("roles", {}) settings = get_settings() # Setup Services qdrant = get_qdrant_client() embedding_provider = ProviderFactory.create_provider("openrouter", settings) completion_provider = ProviderFactory.create_provider("openrouter", settings) # Default rag = RAGChatService(qdrant, embedding_provider, completion_provider) question = "Was ist das Nullfeld?" print(f"ā“ Question for all: '{question}'\n") results = [] for role_id, role in roles.items(): print(f"šŸŽ­ Testing {role['name']} ({role['model']})...") try: # Check model availability first? No, just try. res = rag.chat_with_context( question=question, character_name=role['name'], character_prompt=role['system_prompt'], lang="de", model_override=role.get("model") ) answer = res['answer'][:100].replace('\n', ' ') + "..." sources = len(res.get('sources', [])) model_used = res.get('model') status = "āœ…" if sources == 0: status = "āš ļø No Context" print(f" āžœ Answer: {answer}") print(f" āžœ Sources: {sources} | Model: {model_used} | {status}") results.append({ "role": role_id, "status": "OK", "sources": sources, "model": model_used }) except Exception as e: print(f" āŒ Error: {e}") results.append({ "role": role_id, "status": "ERROR", "error": str(e) }) print("-" * 40) # Summary print("\nšŸ“Š Summary:") success = len([r for r in results if r['status'] == "OK"]) print(f"Total Roles: {len(roles)}") print(f"Success: {success}") print(f"Failures: {len(results) - success}") if len(results) - success == 0: print("\nšŸŽ‰ All roles passed!") else: print("\nšŸ’„ Some roles failed.") if __name__ == "__main__": asyncio.run(test_roles())