File size: 3,953 Bytes
e275025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""
Example script demonstrating OpenRouter client usage
for medical transcription correction
"""

import os
import sys
from pathlib import Path

# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

from corrector.openrouter_client import OpenRouterClient
from dotenv import load_dotenv

# Load environment variables
load_dotenv()


def test_basic_completion():
    """Test basic chat completion"""
    print("=" * 60)
    print("Testing Basic Chat Completion")
    print("=" * 60)
    
    client = OpenRouterClient()
    
    messages = [
        {
            "role": "user",
            "content": "How many r's are in the word 'strawberry'?"
        }
    ]
    
    response = client.chat_completion(messages=messages, reasoning_enabled=True)
    
    print(f"\nModel: {client.model}")
    print(f"Response: {client._extract_content(response)}")
    print(f"\nFull response:\n{response}")


def test_medical_correction():
    """Test medical transcription correction"""
    print("\n" + "=" * 60)
    print("Testing Medical Transcription Correction")
    print("=" * 60)
    
    client = OpenRouterClient()
    
    # Sample transcription with potential errors
    transcription = "Пациент жалуется на боль в животе, тошноту и рвоту. Диагноз апендицит."
    
    system_prompt = """Ты медицинский помощник. Исправь ошибки в медицинской транскрипции.
Используй правильную медицинскую терминологию.
Верни только исправленный текст без дополнительных пояснений."""
    
    corrected_text = client.correct_text(
        text=transcription,
        system_prompt=system_prompt,
        temperature=0.1
    )
    
    print(f"\nOriginal: {transcription}")
    print(f"Corrected: {corrected_text}")


def test_with_medical_terms():
    """Test correction with medical terms context"""
    print("\n" + "=" * 60)
    print("Testing with Medical Terms Context")
    print("=" * 60)
    
    client = OpenRouterClient()
    
    # Load medical terms
    medical_terms = "аппендицит, гастрит, энцефалопатия, кардиомиопатия"
    
    transcription = "У пациента подозрение на апендицит и гастрит"
    
    system_prompt = f"""Ты медицинский помощник. Исправь ошибки в транскрипции.
    
Используй следующие медицинские термины: {medical_terms}

Верни только исправленный текст."""
    
    messages = [
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": transcription}
    ]
    
    response = client.chat_completion(
        messages=messages,
        temperature=0.1,
        reasoning_enabled=True
    )
    
    corrected_text = client._extract_content(response)
    
    print(f"\nMedical terms: {medical_terms}")
    print(f"Original: {transcription}")
    print(f"Corrected: {corrected_text}")


def test_model_info():
    """Test model info retrieval"""
    print("\n" + "=" * 60)
    print("Model Information")
    print("=" * 60)
    
    client = OpenRouterClient()
    info = client.get_model_info()
    
    print("\nConfiguration:")
    for key, value in info.items():
        print(f"  {key}: {value}")


if __name__ == "__main__":
    try:
        # Run tests
        test_basic_completion()
        test_medical_correction()
        test_with_medical_terms()
        test_model_info()
        
        print("\n" + "=" * 60)
        print("All tests completed successfully!")
        print("=" * 60)
        
    except Exception as e:
        print(f"\n❌ Error: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)