Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Test script for custom prompt functionality | |
| """ | |
| import sys | |
| import os | |
| # Add the current directory to Python path | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from app import AutoCompleteApp | |
| from config.settings import AppSettings | |
| def test_custom_prompts(): | |
| """Test the custom prompt functionality""" | |
| print("π§ͺ Testing Custom Prompt Functionality") | |
| print("=" * 50) | |
| # Initialize settings and app | |
| settings = AppSettings() | |
| app = AutoCompleteApp() | |
| # Test custom prompts | |
| custom_prompts = { | |
| "email": { | |
| "system_prompt": "You are a VERY FORMAL email assistant. Always use extremely formal language. Generate approximately {max_tokens} tokens.", | |
| "user_template": "Complete this FORMAL email with {max_tokens} tokens: {text}", | |
| "temperature": 0.6, | |
| }, | |
| "creative": { | |
| "system_prompt": "You are a PIRATE storyteller. Write everything in pirate speak! Generate approximately {max_tokens} tokens.", | |
| "user_template": "Continue this pirate tale with {max_tokens} tokens: {text}", | |
| "temperature": 0.8, | |
| }, | |
| "general": { | |
| "system_prompt": "You are a TECHNICAL writer. Use precise, technical language. Generate approximately {max_tokens} tokens.", | |
| "user_template": "Complete this technical text with {max_tokens} tokens: {text}", | |
| "temperature": 0.7, | |
| }, | |
| } | |
| # Test cases | |
| test_cases = [ | |
| ("Hello, I wanted to", "email", "Should be VERY formal"), | |
| ("Once upon a time", "creative", "Should be in pirate speak"), | |
| ("The system processes", "general", "Should be technical"), | |
| ] | |
| print("Testing custom prompts...") | |
| for text, context, expected in test_cases: | |
| print(f"\nπ Testing: '{text}' with {context} context") | |
| print(f"Expected: {expected}") | |
| try: | |
| # Test with custom prompts | |
| suggestions, status = app.get_suggestions_with_custom_prompts( | |
| text=text, | |
| context=context, | |
| output_tokens=100, | |
| user_context="", | |
| custom_prompts=custom_prompts | |
| ) | |
| print(f"Status: {status}") | |
| if suggestions: | |
| print(f"β Custom prompt test passed - got suggestion") | |
| print(f"Preview: {suggestions[0][:100]}...") | |
| else: | |
| print("β οΈ No suggestions generated") | |
| except Exception as e: | |
| print(f"β Error: {str(e)}") | |
| print("\n" + "=" * 50) | |
| print("π Custom prompt functionality test completed!") | |
| if __name__ == "__main__": | |
| test_custom_prompts() | |