Spaces:
Sleeping
Sleeping
File size: 1,122 Bytes
8421ec4 | 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 |
import requests
import time
# Create chat
try:
chat = requests.post("http://localhost:4000/chats", json={"title": "RAG Tool Test"}).json()
chat_id = chat["id"]
except Exception as e:
print(f"Failed to create chat: {e}")
exit(1)
def ask(question):
print(f"\nUser: {question}")
t0 = time.time()
try:
res = requests.post(f"http://localhost:4000/chats/{chat_id}/messages", json={"content": question})
duration = time.time() - t0
if res.status_code == 200:
data = res.json()
print(f"Assistant ({duration:.1f}s): {data['assistant_message']['content']}")
else:
print(f"Error {res.status_code}: {res.text}")
except Exception as e:
print(f"Request failed: {e}")
# Test 1: Math Tool (Should verify tools still work)
ask("Calculate 55 * 4")
# Test 2: RAG Tool (Should verify retrieve_documents is called)
ask("What specific data is in the uploaded document?")
# Test 3: Rate Limit Resilience (Hammer the API)
print("\n--- Stress Test (Rate Limit) ---")
for i in range(5):
ask(f"Quick question {i}: What is 1+{i}?")
|