-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
171 lines (110 loc) · 3.37 KB
/
tests.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import time
import requests
import json
import logging
from load_text import load_text
logger = logging.getLogger("tests")
logging.basicConfig(level=logging.INFO, format='%(message)s')
class Tester:
def __init__(self, engine):
self.api = "http://localhost:8088/api/v1/"
self.engine = engine
def test_embeddings(self):
logger.debug("** Embeddings test")
input = {
"text": "What is a cat?",
}
resp = requests.post(
f"{self.api}embeddings",
timeout=10,
json=input,
)
resp = resp.json()
if "error" in resp:
raise RuntimeError("Embeddings: " + resp["error"])
logger.debug("Got embeddings")
def test_text_completion(self):
logger.debug("** Text completion test")
input = {
"system": "Answer the question",
"prompt": "What is 2 + 2?",
}
resp = requests.post(
f"{self.api}text-completion",
timeout=30,
json=input,
)
resp = resp.json()
if "error" in resp:
raise RuntimeError("Text completion: " + resp["error"])
logger.debug("Got text completion")
def test_prompt(self):
logger.debug("** Prompt test")
input = {
"id": "question",
"variables": {
"question": "What is 2 + 2?",
}
}
resp = requests.post(
f"{self.api}prompt",
timeout=30,
json=input,
)
resp = resp.json()
if "error" in resp:
raise RuntimeError("Prompt: " + resp["error"])
logger.debug("Got prompt response")
def test_graph_rag(self):
logger.debug("** Graph RAG test")
input = {
"query": "What is a cat?",
}
resp = requests.post(
f"{self.api}graph-rag",
timeout=90,
json=input,
)
resp = resp.json()
if "error" in resp:
raise RuntimeError("Prompt: " + resp["error"])
logger.debug("Got graph RAG response")
def test_load_text(self):
logger.debug("** Load text")
load_text(self.api, self.engine)
logger.debug("Text loaded")
def test_triples(self):
logger.debug("** Query triples")
timeout = 120
until = time.time() + timeout
input = {
"limit": 10,
}
while time.time() < until:
try:
resp = requests.post(
f"{self.api}triples-query",
timeout=10,
json=input,
)
resp = resp.json()
num = len(resp["response"])
if num > 1:
logger.debug(f"Got {num} triples.")
return
except:
pass
time.sleep(2)
raise RuntimeError("Timeout waiting for triples")
def run(self):
logger.debug("=== TESTS BEGIN ===")
self.test_load_text()
self.test_text_completion()
self.test_prompt()
self.test_embeddings()
logger.debug("Sleep for a bit")
time.sleep(15)
self.test_triples()
self.test_graph_rag()
logger.debug("=== TESTS COMPLETED ===")
time.sleep(2)