forked from OpenBMB/XAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
57 lines (49 loc) · 2.26 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
import os
import sys
import argparse
from XAgent.config import CONFIG
from command import CommandLine,XAgentServerEnv
def parse_args():
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, default=None,)
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, default=30)
parser.add_argument("--enable_ask_human_for_help", action="store_true",default=False)
parser.add_argument("--max_plan_refine_chain_length", type=int, default=3)
parser.add_argument("--max_plan_tree_depth", type=int, default=3)
parser.add_argument("--max_plan_tree_width", type=int, default=7)
parser.add_argument("--max_retry_times", type=int, default=3)
parser.add_argument("--config_file",type=str,default="config.yml")
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_args()
CONFIG.reload(args.config_file)
if args.model is not None:
CONFIG.default_completion_kwargs['model'] = args.model
CONFIG.enable_ask_human_for_help = args.enable_ask_human_for_help
CONFIG.max_subtask_chain_length = args.max_subtask_chain_length
CONFIG.max_plan_refine_chain_length = args.max_plan_refine_chain_length
CONFIG.max_plan_tree_depth = args.max_plan_tree_depth
CONFIG.max_plan_tree_width = args.max_plan_tree_width
CONFIG.max_retry_times = args.max_retry_times
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")
cmd.start(
args.task,
role="Assistant",
mode=args.mode,
upload_files=args.upload_files,
)
if args.quiet:
sys.stdout.close()
sys.stdout = original_stdout