File size: 2,779 Bytes
b309c22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/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()