MCPcopy Create free account
hub / github.com/THUDM/AutoWebGLM / parse_args

Method parse_args

webarena/browser_env/html_tools/html_parser.py:23–87  ·  view source on GitHub ↗
(self, args: dict[str]={})

Source from the content-addressed store, hash-verified

21 self.init_time = time.time() - stt
22
23 def parse_args(self, args: dict[str]={}) -> None:
24 def attr_check(attr, type_model='str'):
25 if attr is None:
26 return False
27 attr_type = type(attr)
28 if attr_type != type(type_model):
29 return False
30 if attr_type == type('str') and len(attr) == 0:
31 return False
32 return True
33
34 args = {} if args is None else args
35
36 # [Position] use_pos: False -> use full page, otherwise use window_size
37 dataset = args.get('dataset', '')
38 use_position = args.get('use_position', False)
39 window_size = args.get('window_size', None)
40 rect = args.get('rect_dict', None)
41 if use_position:
42 if not attr_check(window_size, ()):
43 raise ValueError('window_size must be set when use_position is True')
44 if not attr_check(rect, {}):
45 raise ValueError('rect_dict must be set when use_position is True')
46
47 if not attr_check(rect, {}):
48 rect = {}
49
50 # [Label] for vimium is temp_clickable_label, otherwise keep all of it
51 label_attr = args.get('label_attr', '')
52 get_new_label = args.get('regenerate_label', False)
53 label_method = args.get('label_generator', None)
54 regen_label = not attr_check(label_method)
55
56 # [id] for mind2web is backend_node_id, for normal website use our method
57 id_attr = args.get('id_attr', '')
58 regen_id = not attr_check(id_attr)
59
60 if regen_id:
61 id_attr = 'temp_id'
62
63 # [attributes]
64 keep_attrs = args.get('attr_list', [])
65 if not attr_check(keep_attrs, []):
66 keep_attrs = []
67
68 # [Tags] for clickable elem, keep: must keep, obs: keep if follow specific rule
69 parent_chain = args.get('parent_chain', False)
70 keep_elem = args.get('keep_elem', [])
71 obs_elem = args.get('obs_elem', [])
72
73 # sanity check
74 self.set_args(use_position, window_size, rect, label_attr, id_attr, keep_attrs, keep_elem, obs_elem, parent_chain, get_new_label, dataset)
75
76 # [Prompt]
77 prompt = args.get('prompt', None)
78 self.prompt = HtmlPrompt(prompt)
79
80 # traverse and get special data

Callers 5

__init__Method · 0.95
configFunction · 0.45
auto_login.pyFile · 0.45
html2json.pyFile · 0.45

Calls 4

set_argsMethod · 0.95
mark_idMethod · 0.95
HtmlPromptClass · 0.70
IdentifierToolClass · 0.70

Tested by

no test coverage detected