forked from Emissary-Tech/legit-rag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
47 lines (42 loc) · 1.67 KB
/
test.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
import requests
import json
# API endpoint
BASE_URL = "http://localhost:8000"
# Test documents
documents = {
"documents": [
{
"text": "The Python programming language was created by Guido van Rossum and was released in 1991. It emphasizes code readability with its notable use of significant indentation.",
"metadata": {"source": "wiki", "topic": "programming"}
},
{
"text": "Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured, object-oriented, and functional programming.",
"metadata": {"source": "wiki", "topic": "programming"}
},
{
"text": "OpenAI was founded in 2015. Initially a non-profit organization, it transitioned to a 'capped-profit' model in 2019.",
"metadata": {"source": "news", "topic": "AI"}
}
]
}
# Add documents
print("\nAdding documents...")
response = requests.post(f"{BASE_URL}/documents", json=documents)
print(f"Status: {response.status_code}")
print(json.dumps(response.json(), indent=2))
# Test queries
test_queries = [
"When was Python created and by whom?",
"What type of programming language is Python?",
"Tell me about OpenAI's founding",
"What is the capital of France?" # This should fail due to no relevant context
]
print("\nTesting queries...")
for query in test_queries:
print(f"\nQuery: {query}")
response = requests.post(f"{BASE_URL}/query", json={"query": query})
print(f"Status: {response.status_code}")
if response.status_code == 200:
print(json.dumps(response.json(), indent=2))
else:
print(f"Error: {response.text}")