-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathexec.py
More file actions
executable file
·56 lines (49 loc) · 1.73 KB
/
exec.py
File metadata and controls
executable file
·56 lines (49 loc) · 1.73 KB
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
#!/usr/bin/python3
import sys
from modules.clients import ClientFactory, get_client_config
from modules.client_api import TextClientAPI
from modules.graph import GraphExecutor
import json
from modules.client_api.logger import Logger, stop_logger
client_config = get_client_config()
ClientFactory.load_config(client_config)
client = ClientFactory.get_client()
def perform_cleaning(message):
if message.startswith("<think>"):
message = message.split("</think>",1)[-1].lstrip()
return message
def run_graph(args,parameters, print_json=False, clean_output=False):
logger = Logger()
executor_config = {"client": client, "client_parameters": parameters, "logger": logger, "client_api": TextClientAPI()}
seqExec = GraphExecutor(executor_config)
try:
cl_args = seqExec.load_config(args)
res = seqExec(cl_args[1:])
print("--------------- Result:")
res2 = [str(el) for el in res]
#print(json.dumps(res2, indent=4))
for el in res:
print(el)
if clean_output:
res2[0] = perform_cleaning(res2[0])
if print_json:
print("--------------- Json result:")
print(json.dumps(res2))
except KeyboardInterrupt as e:
pass
finally:
stop_logger()
if __name__ == "__main__":
parameters = {}
parameters["repeat_penalty"] = 1.0
parameters["penalize_nl"] = False
parameters["seed"] = -1
print_json = False
clean_output = False
import getopt
opts, args = getopt.getopt(sys.argv[1:], 'js:k')
for (k, v) in opts:
if k == "-j": print_json = True
if k == "-s": parameters["stop"] = [v]
if k == "-k": clean_output = True
run_graph(args,parameters,print_json,clean_output)