-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
40 lines (33 loc) · 1.47 KB
/
test_api.py
File metadata and controls
40 lines (33 loc) · 1.47 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
import asyncio
import httpx
import json
async def test_suggest():
"""Test the suggestion endpoint"""
url = "http://localhost:8001/api/suggest" # Note the port change
payload = {
"current_text": "The JavaScript event loop is fundamental to understanding asynchronous programming.",
"context": ["Modern web applications rely heavily on non-blocking operations."]
}
# Increased timeout to 60 seconds
async with httpx.AsyncClient(timeout=60.0) as client:
print("Sending request to API...")
try:
response = await client.post(url, json=payload)
print(f"Status: {response.status_code}")
if response.status_code == 200:
data = response.json()
print("\nSuggestions:")
for i, suggestion in enumerate(data["suggestions"], 1):
print(f"{i}. {suggestion}")
print("\nLatencies:")
for key, value in data["latencies"].items():
print(f"{key}: {value:.2f}ms")
print("\nSource chunks used (first 2):")
for i, chunk in enumerate(data["source_chunks"][:2], 1):
print(f"{i}. {chunk['text'][:100]}...")
else:
print(f"Error: {response.text}")
except Exception as e:
print(f"Request failed: {str(e)}")
if __name__ == "__main__":
asyncio.run(test_suggest())