-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_endpoint.py
70 lines (57 loc) · 2.09 KB
/
test_endpoint.py
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
import requests
import json
import sys
import os
# Add the parent directory to the Python path to import from main.py
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from main import print_vector_db_contents
def test_api():
base_url = "https://cerebral-hive-backend.onrender.com"
headers = {"Content-Type": "application/json"}
timeout = 10 # 10 seconds timeout
query = "I am a query!"
try:
# Test post_query
chat_completion_request = {
"messages": [
{"role": "user", "content": query}
],
"model": "gpt-4o", # or whatever model you're using
"max_tokens": 2048,
"stream": False
}
response = requests.post(
f"{base_url}/chat/completions",
headers=headers,
json=chat_completion_request,
timeout=timeout
)
if response.status_code == 200:
print("Chat Completion - Success!")
print("Response:", response.json())
else:
print("Chat Completion - Error:", response.status_code)
print("Response:", response.text)
# Simulate answer generation (this would be done by the Continue frontend)
answer = "The capital of France is Paris."
# Test store_answer
data = {
"query": {"query": "What is the capital of France?"},
"answer": {"answer": answer},
}
response = requests.post(
f"{base_url}/store_answer", headers=headers, json=data, timeout=timeout
)
if response.status_code == 200:
print("Store Answer - Success!")
print("Response:", response.json())
else:
print("Store Answer - Error:", response.status_code)
print("Response:", response.text)
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
# Print the contents of the vector database
print("\nPrinting Vector Database Contents:")
print_vector_db_contents()
if __name__ == "__main__":
test_api()