forked from OpenBMB/XAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
73 lines (56 loc) · 2.33 KB
/
run.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
import os
import sys
import argparse
from copy import deepcopy
from XAgent.config import CONFIG,ARGS
from command import CommandLine,XAgentServerEnv
def parse_args():
"""
Parse command line arguments
Returns:
argparse.Namespace: Object containing command line arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument("--task", type=str,
help="task description",required=True)
parser.add_argument("--upload_files", nargs='+',
help="upload files")
parser.add_argument("--model", type=str,)
parser.add_argument("--record_dir", type=str,)
parser.add_argument("--mode", type=str, default="auto",
help="mode, only support auto and manual, if you choose manual, you need to press enter to continue in each step")
parser.add_argument("--quiet", action="store_true",default=False)
parser.add_argument("--max_subtask_chain_length", type=int,)
parser.add_argument("--enable_ask_human_for_help", action="store_true",)
parser.add_argument("--max_plan_refine_chain_length", type=int,)
parser.add_argument("--max_plan_tree_depth", type=int,)
parser.add_argument("--max_plan_tree_width", type=int,)
parser.add_argument("--max_retry_times", type=int,)
parser.add_argument("--config_file",type=str,default=os.getenv('CONFIG_FILE', 'assets/config.yml'))
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
os.environ['CONFIG_FILE'] = args.config_file
cmd = CommandLine(XAgentServerEnv)
if args.quiet:
original_stdout = sys.stdout
from XAgent.running_recorder import recorder
sys.stdout = open(os.path.join(recorder.record_root_dir,"command_line.ansi"),"w",encoding="utf-8")
args = vars(args)
for key,value in args.items():
if value is not None:
if key == 'model':
ARGS['default_completion_kwargs'] = deepcopy(CONFIG['default_completion_kwargs'])
ARGS['default_completion_kwargs']['model'] = value
else:
ARGS[key] = value
cmd.start(
args['task'],
role="Assistant",
mode=args['mode'],
upload_files=args['upload_files'],
)
if args['quiet']:
sys.stdout.close()
sys.stdout = original_stdout