126 lines
5.0 KiB
Python
126 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Test Gemini integration via backend API."""
|
|
|
|
import requests
|
|
import json
|
|
import time
|
|
|
|
def test_gemini_via_api():
|
|
"""Test Gemini integration through the backend API."""
|
|
|
|
print("🚀 Testing Gemini integration via Backend API")
|
|
|
|
# Test 1: Check available models
|
|
print("\n=== Step 1: Check Available Models ===")
|
|
try:
|
|
response = requests.get("http://localhost:8000/api/models/available")
|
|
if response.status_code == 200:
|
|
models = response.json()
|
|
print(f"✅ Found {models['active_count']} available models:")
|
|
|
|
gemini_found = False
|
|
for model in models['models']:
|
|
provider = model['provider']
|
|
name = model['display_name']
|
|
context = model.get('context_window', 'N/A')
|
|
|
|
print(f" - {provider}: {name} (context: {context:,})")
|
|
|
|
if provider == 'google' and 'Gemini' in name:
|
|
gemini_found = True
|
|
gemini_model = model
|
|
print(f" 🎯 GEMINI FOUND! Context window: {context:,} tokens")
|
|
|
|
if not gemini_found:
|
|
print("❌ Gemini model not found in available models")
|
|
return False
|
|
|
|
else:
|
|
print(f"❌ Failed to get models: {response.status_code}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error checking models: {e}")
|
|
return False
|
|
|
|
# Test 2: Test Gemini summarization with a sample request
|
|
print("\n=== Step 2: Test Gemini Summarization ===")
|
|
|
|
test_request = {
|
|
"model": "gemini-1.5-pro",
|
|
"transcript": """This is a test transcript about artificial intelligence and machine learning.
|
|
In this comprehensive overview, we explore the fundamentals of neural networks, deep learning architectures,
|
|
and their practical applications across various industries including healthcare, finance, education,
|
|
and autonomous systems. We discuss convolutional neural networks for computer vision, recurrent neural networks
|
|
for natural language processing, transformer architectures that have revolutionized AI, and the importance of
|
|
large datasets in training robust machine learning models. The content covers both theoretical foundations
|
|
and practical implementation considerations for AI systems in production environments.""",
|
|
"options": {
|
|
"length": "brief",
|
|
"focus_areas": ["AI", "machine learning", "neural networks"]
|
|
}
|
|
}
|
|
|
|
try:
|
|
print("📤 Sending summarization request to Gemini...")
|
|
response = requests.post(
|
|
"http://localhost:8000/api/models/summarize",
|
|
json=test_request,
|
|
headers={"Content-Type": "application/json"}
|
|
)
|
|
|
|
print(f"📨 Response status: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print("✅ Gemini summarization successful!")
|
|
|
|
if 'summary' in result:
|
|
summary = result['summary']
|
|
print(f"📄 Summary: {summary[:200]}...")
|
|
|
|
if 'key_points' in result:
|
|
key_points = result.get('key_points', [])
|
|
print(f"🔑 Key points ({len(key_points)} found):")
|
|
for i, point in enumerate(key_points[:3], 1):
|
|
print(f" {i}. {point}")
|
|
|
|
if 'cost_data' in result:
|
|
cost = result['cost_data'].get('total_cost_usd', 0)
|
|
print(f"💰 Cost: ${cost:.4f}")
|
|
|
|
# Check if it used Gemini's large context advantage
|
|
if 'processing_metadata' in result:
|
|
metadata = result['processing_metadata']
|
|
if 'large_context_advantage' in metadata:
|
|
print(f"⚡ Large context advantage: {metadata['large_context_advantage']}")
|
|
|
|
return True
|
|
|
|
elif response.status_code == 400:
|
|
error_detail = response.json()
|
|
print(f"❌ Bad request: {error_detail}")
|
|
return False
|
|
|
|
elif response.status_code == 500:
|
|
print(f"❌ Server error: {response.text}")
|
|
return False
|
|
|
|
else:
|
|
print(f"❌ Unexpected status {response.status_code}: {response.text}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error testing summarization: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = test_gemini_via_api()
|
|
|
|
if success:
|
|
print("\n🎉 Gemini integration test PASSED!")
|
|
print("✅ Gemini 1.5 Pro with 2M token context is ready for long YouTube videos!")
|
|
else:
|
|
print("\n❌ Gemini integration test FAILED")
|
|
|
|
print("\n🔗 Next: Test with a real long YouTube video to demonstrate the 2M context advantage") |