File size: 1,950 Bytes
3e2ca56 |
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 |
#!/usr/bin/env python3
"""
Debug script to test translation functionality
"""
import os
import asyncio
import sys
from pathlib import Path
# Add the current directory to Python path
sys.path.insert(0, str(Path(__file__).parent))
from translator import DocumentTranslator
async def test_translation():
"""Test the translation system"""
print("π§ͺ Testing Document Translation System...")
# Check API key
api_key = os.getenv('OPENROUTER_API_KEY')
if not api_key:
print("β OPENROUTER_API_KEY not found!")
print("Set it with: export OPENROUTER_API_KEY='your_key_here'")
return
print(f"β
API key found (length: {len(api_key)})")
# Initialize translator
translator = DocumentTranslator()
if not translator.is_ready():
print("β Translator not ready")
return
print("β
Translator initialized")
# Test model availability
models = await translator.get_available_models()
print(f"β
Available models: {len(models)}")
for model in models:
print(f" - {model['name']}: {model['id']}")
# Test basic translation
test_text = "Hello, this is a test sentence for translation."
print(f"\nπ€ Testing basic translation...")
print(f"Original: {test_text}")
try:
translated = await translator.translate_text(
test_text,
"google/gemini-2.5-pro-exp-03-25",
"en",
"ar"
)
print(f"Translated: {translated}")
if translated != test_text:
print("β
Basic translation working!")
else:
print("β οΈ Translation returned original text - check API key and credits")
except Exception as e:
print(f"β Translation test failed: {e}")
print("\nπ― Translation system test complete!")
if __name__ == "__main__":
asyncio.run(test_translation()) |