-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_tests.py
More file actions
77 lines (66 loc) · 2.7 KB
/
Copy pathapi_tests.py
File metadata and controls
77 lines (66 loc) · 2.7 KB
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
import asyncio
import httpx
import os
from dotenv import load_dotenv
# Загружаем переменные из .env
load_dotenv()
async def check_rapidapi():
print("🔄 Проверка RapidAPI (Random Words)...")
# ПРАВИЛЬНЫЙ ENDPOINT: /v1/generator/random-word-list
url = f"https://{os.getenv('RAPIDAPI_HOST')}/v1/generator/random-word-list"
headers = {
"X-RapidAPI-Key": os.getenv('RAPIDAPI_KEY'),
"X-RapidAPI-Host": os.getenv('RAPIDAPI_HOST')
}
# Правильные параметры API
params = {
"word_count": 3,
"min_length": 3,
"max_length": 10,
"is_common": 1
}
try:
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
print(f"✅ RapidAPI: OK - Получены слова: {data.get('random_words', [])}")
return True
else:
print(f"❌ RapidAPI: Ошибка {response.status_code} - {response.text}")
return False
except Exception as e:
print(f"❌ RapidAPI: Исключение - {e}")
return False
async def check_gemini():
print("🔄 Проверка Google Gemini API...")
model = os.getenv('GEMINI_MODEL', 'gemini-2.5-flash-lite')
url = f"https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent"
params = {"key": os.getenv('GEMINI_API_KEY')}
payload = {
"contents": [{"parts": [{"text": "Привет, ответь одним словом: OK"}]}]
}
try:
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.post(url, params=params, json=payload)
if response.status_code == 200:
print("✅ Gemini API: OK")
return True
else:
print(f"❌ Gemini API: Ошибка {response.status_code} - {response.text}")
return False
except Exception as e:
print(f"❌ Gemini API: Исключение - {e}")
return False
async def main():
print("🚀 Запуск smoke-тестов внешних API...\n")
rapid_ok = await check_rapidapi()
print("-" * 40)
gemini_ok = await check_gemini()
print("-" * 40)
if rapid_ok and gemini_ok:
print("🎉 Все внешние API доступны и настроены корректно!")
else:
print("⚠️ Обнаружены проблемы с внешними API. Проверьте ключи в .env файле.")
if __name__ == "__main__":
asyncio.run(main())