-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworker.py
38 lines (34 loc) · 1.08 KB
/
worker.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
import json
import sys
from llama_index import GPTSimpleVectorIndex
import pathlib
LOCAL_PATH = pathlib.Path(__file__).resolve().parent
def main():
try:
model = GPTSimpleVectorIndex.load_from_disk(str(LOCAL_PATH / "data" / "train_data_llama.json"))
except KeyboardInterrupt as ex:
print(f"Failed to load model: {ex}", file=sys.stderr)
exit(1)
print("done")
while True:
try:
s = json.loads(input())
except EOFError as _:
break
except KeyboardInterrupt as _:
break
task = s["task"]
if task == "exit":
break
elif task == "query":
try:
ret = model.query(s["query"])
except Exception as ex:
print(json.dumps({"reply":str(ex), "ok":False}))
import traceback
traceback.print_exc(file=sys.stderr)
else:
print(json.dumps({"reply": str(ret), "ok": True}))
sys.stdout.flush()
if __name__ == "__main__":
main()