-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
38 lines (30 loc) · 1.01 KB
/
Copy pathtest_api.py
File metadata and controls
38 lines (30 loc) · 1.01 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
import requests
import json
import time
def test_rag_api():
url = "http://localhost:8080/api/ask"
payload = {
"query": "TO BE FILLED"
}
headers = {
"Content-Type": "application/json"
}
print(f"[{time.strftime('%X')}] Sending questions to server...")
print(f"Query: {payload['query']}")
print("-" * 50)
try:
start_time = time.time()
response = requests.post(url, json=payload, headers=headers)
end_time = time.time()
if response.status_code == 200:
result = response.json()
print(f"[{time.strftime('%X')}] Answer came in! (Time: {end_time - start_time:.2f} sec)\n")
print("Answer: ")
print(result.get("answer", "No answer."))
else:
print(f"Error : {response.status_code}")
print(response.text)
except requests.exceptions.ConnectionError:
print("Cannot connect to server")
if __name__ == "__main__":
test_rag_api()