MCPcopy
hub / github.com/TencentQQGYLab/AppAgent / parse_explore_rsp

Function parse_explore_rsp

scripts/model.py:101–142  ·  view source on GitHub ↗
(rsp)

Source from the content-addressed store, hash-verified

99
100
101def parse_explore_rsp(rsp):
102 try:
103 observation = re.findall(r"Observation: (.*?)$", rsp, re.MULTILINE)[0]
104 think = re.findall(r"Thought: (.*?)$", rsp, re.MULTILINE)[0]
105 act = re.findall(r"Action: (.*?)$", rsp, re.MULTILINE)[0]
106 last_act = re.findall(r"Summary: (.*?)$", rsp, re.MULTILINE)[0]
107 print_with_color("Observation:", "yellow")
108 print_with_color(observation, "magenta")
109 print_with_color("Thought:", "yellow")
110 print_with_color(think, "magenta")
111 print_with_color("Action:", "yellow")
112 print_with_color(act, "magenta")
113 print_with_color("Summary:", "yellow")
114 print_with_color(last_act, "magenta")
115 if "FINISH" in act:
116 return ["FINISH"]
117 act_name = act.split("(")[0]
118 if act_name == "tap":
119 area = int(re.findall(r"tap\((.*?)\)", act)[0])
120 return [act_name, area, last_act]
121 elif act_name == "text":
122 input_str = re.findall(r"text\((.*?)\)", act)[0][1:-1]
123 return [act_name, input_str, last_act]
124 elif act_name == "long_press":
125 area = int(re.findall(r"long_press\((.*?)\)", act)[0])
126 return [act_name, area, last_act]
127 elif act_name == "swipe":
128 params = re.findall(r"swipe\((.*?)\)", act)[0]
129 area, swipe_dir, dist = params.split(",")
130 area = int(area)
131 swipe_dir = swipe_dir.strip()[1:-1]
132 dist = dist.strip()[1:-1]
133 return [act_name, area, swipe_dir, dist, last_act]
134 elif act_name == "grid":
135 return [act_name]
136 else:
137 print_with_color(f"ERROR: Undefined act {act_name}!", "red")
138 return ["ERROR"]
139 except Exception as e:
140 print_with_color(f"ERROR: an exception occurs while parsing the model response: {e}", "red")
141 print_with_color(rsp, "red")
142 return ["ERROR"]
143
144
145def parse_grid_rsp(rsp):

Callers 2

task_executor.pyFile · 0.90
self_explorer.pyFile · 0.90

Calls 1

print_with_colorFunction · 0.90

Tested by

no test coverage detected