Skip to content

Commit f14341b

Browse files
h-jooThe android_world Authors
authored andcommitted
Automated Code Change
PiperOrigin-RevId: 944185836
1 parent d9c569f commit f14341b

39 files changed

Lines changed: 148 additions & 144 deletions

android_world/agents/infer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __init__(
116116
raise RuntimeError('GCP API key not set.')
117117
genai.configure(api_key=os.environ['GCP_API_KEY'])
118118
self.llm = genai.GenerativeModel(
119-
model_name,
119+
model_name, # pyrefly: ignore[bad-argument-type]
120120
safety_settings=None
121121
if enable_safety_checks
122122
else SAFETY_SETTINGS_BLOCK_NONE,
@@ -305,7 +305,7 @@ def predict_mm(
305305
for image in images:
306306
payload['messages'][0]['content'].append({
307307
'type': 'image_url',
308-
'image_url': {
308+
'image_url': { # pyrefly: ignore[bad-assignment]
309309
'url': f'data:image/jpeg;base64,{self.encode_image(image)}'
310310
},
311311
})

android_world/agents/m3a.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ def _action_selection_prompt(
285285
The text prompt for action selection that will be sent to gpt4v.
286286
"""
287287
if history:
288-
history = '\n'.join(history)
288+
history = '\n'.join(history) # pyrefly: ignore[bad-assignment]
289289
else:
290-
history = 'You just started, no action has been performed yet.'
290+
history = 'You just started, no action has been performed yet.' # pyrefly: ignore[bad-assignment]
291291

292292
extra_guidelines = ''
293293
if additional_guidelines:
@@ -392,7 +392,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
392392
before_ui_elements_list = _generate_ui_elements_description_list(
393393
before_ui_elements, logical_screen_size
394394
)
395-
step_data['raw_screenshot'] = state.pixels.copy()
395+
step_data['raw_screenshot'] = state.pixels.copy() # pyrefly: ignore[bad-assignment]
396396
before_screenshot = state.pixels.copy()
397397
for index, ui_element in enumerate(before_ui_elements):
398398
if m3a_utils.validate_ui_element(ui_element, logical_screen_size):
@@ -404,7 +404,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
404404
physical_frame_boundary,
405405
orientation,
406406
)
407-
step_data['before_screenshot_with_som'] = before_screenshot.copy()
407+
step_data['before_screenshot_with_som'] = before_screenshot.copy() # pyrefly: ignore[bad-assignment]
408408

409409
action_prompt = _action_selection_prompt(
410410
goal,
@@ -415,10 +415,10 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
415415
before_ui_elements_list,
416416
self.additional_guidelines,
417417
)
418-
step_data['action_prompt'] = action_prompt
418+
step_data['action_prompt'] = action_prompt # pyrefly: ignore[bad-assignment]
419419
action_output, is_safe, raw_response = self.llm.predict_mm(
420420
action_prompt,
421-
[
421+
[ # pyrefly: ignore[bad-argument-type]
422422
step_data['raw_screenshot'],
423423
before_screenshot,
424424
],
@@ -431,7 +431,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
431431

432432
if not raw_response:
433433
raise RuntimeError('Error calling LLM in action selection phase.')
434-
step_data['action_output'] = action_output
434+
step_data['action_output'] = action_output # pyrefly: ignore[bad-assignment]
435435
step_data['action_raw_response'] = raw_response
436436

437437
reason, action = m3a_utils.parse_reason_action_output(action_output)
@@ -441,6 +441,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
441441
if (not reason) or (not action):
442442
logging.info('Action prompt output is not in the correct format.')
443443
step_data['summary'] = (
444+
# pyrefly: ignore[bad-assignment]
444445
'Output for action selection is not in the correct format, so no'
445446
' action is performed.'
446447
)
@@ -453,17 +454,18 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
453454

454455
logging.info('Action: %s', action)
455456
logging.info('Reason: %s', reason)
456-
step_data['action_reason'] = reason
457+
step_data['action_reason'] = reason # pyrefly: ignore[bad-assignment]
457458

458459
try:
459460
converted_action = json_action.JSONAction(
460-
**agent_utils.extract_json(action),
461+
**agent_utils.extract_json(action), # pyrefly: ignore[bad-unpacking]
461462
)
462-
step_data['action_output_json'] = converted_action
463+
step_data['action_output_json'] = converted_action # pyrefly: ignore[bad-assignment]
463464
except Exception as e: # pylint: disable=broad-exception-caught
464465
logging.info('Failed to convert the output to a valid action.')
465466
logging.info(str(e))
466467
step_data['summary'] = (
468+
# pyrefly: ignore[bad-assignment]
467469
'Can not parse the output to a valid action. Please make sure to pick'
468470
' the action from the list with required parameters (if any) in the'
469471
' correct JSON format!'
@@ -482,14 +484,15 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
482484
in ['click', 'long_press', 'input_text', 'scroll']
483485
and action_index is not None
484486
):
485-
if action_index >= num_ui_elements:
487+
if action_index >= num_ui_elements: # pyrefly: ignore[unsupported-operation]
486488
logging.info(
487489
'Index out of range, prediction index is %s, but the'
488490
' UI element list only has %d elements.',
489491
action_index,
490492
num_ui_elements,
491493
)
492494
step_data['summary'] = (
495+
# pyrefly: ignore[bad-assignment]
493496
'The parameter index is out of range. Remember the index must be in'
494497
' the UI element list!'
495498
)
@@ -498,8 +501,8 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
498501

499502
# Add mark to the target element.
500503
m3a_utils.add_ui_element_mark(
501-
step_data['raw_screenshot'],
502-
before_ui_elements[action_index],
504+
step_data['raw_screenshot'], # pyrefly: ignore[bad-argument-type]
505+
before_ui_elements[action_index], # pyrefly: ignore[bad-index]
503506
action_index,
504507
logical_screen_size,
505508
physical_frame_boundary,
@@ -509,7 +512,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
509512
if converted_action.action_type == 'status':
510513
if converted_action.goal_status == 'infeasible':
511514
logging.info('Agent stopped since it thinks mission impossible.')
512-
step_data['summary'] = 'Agent thinks the request has been completed.'
515+
step_data['summary'] = 'Agent thinks the request has been completed.' # pyrefly: ignore[bad-assignment]
513516
self.history.append(step_data)
514517
return base_agent.AgentInteractionResult(
515518
True,
@@ -525,6 +528,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
525528
logging.info('Failed to execute action.')
526529
logging.info(str(e))
527530
step_data['summary'] = (
531+
# pyrefly: ignore[bad-assignment]
528532
'Can not execute the action, make sure to select the action with'
529533
' the required parameters (if any) in the correct JSON format!'
530534
)
@@ -556,10 +560,10 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
556560
)
557561

558562
m3a_utils.add_screenshot_label(
559-
step_data['before_screenshot_with_som'], 'before'
563+
step_data['before_screenshot_with_som'], 'before' # pyrefly: ignore[bad-argument-type]
560564
)
561565
m3a_utils.add_screenshot_label(after_screenshot, 'after')
562-
step_data['after_screenshot_with_som'] = after_screenshot.copy()
566+
step_data['after_screenshot_with_som'] = after_screenshot.copy() # pyrefly: ignore[bad-assignment]
563567

564568
summary_prompt = _summarize_prompt(
565569
action,
@@ -587,7 +591,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
587591
summary,
588592
)
589593
step_data['summary'] = (
590-
'Some error occurred calling LLM during summarization phase: %s'
594+
'Some error occurred calling LLM during summarization phase: %s' # pyrefly: ignore[bad-assignment]
591595
% summary
592596
)
593597
self.history.append(step_data)
@@ -596,8 +600,8 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
596600
step_data,
597601
)
598602

599-
step_data['summary_prompt'] = summary_prompt
600-
step_data['summary'] = f'Action selected: {action}. {summary}'
603+
step_data['summary_prompt'] = summary_prompt # pyrefly: ignore[bad-assignment]
604+
step_data['summary'] = f'Action selected: {action}. {summary}' # pyrefly: ignore[bad-assignment]
601605
logging.info('Summary: %s', summary)
602606
step_data['summary_raw_response'] = raw_response
603607

android_world/agents/random_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def _generate_random_action(
6262
json_action.SWIPE,
6363
json_action.INPUT_TEXT,
6464
]:
65-
action_details['x'] = random.randint(0, screen_size[0] - 1)
66-
action_details['y'] = random.randint(0, screen_size[1] - 1)
65+
action_details['x'] = random.randint(0, screen_size[0] - 1) # pyrefly: ignore[bad-assignment]
66+
action_details['y'] = random.randint(0, screen_size[1] - 1) # pyrefly: ignore[bad-assignment]
6767
if action_type == json_action.INPUT_TEXT:
6868
action_details['text'] = ''.join(
6969
random.choices(text_characters, k=10)

android_world/agents/seeact.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def step(
200200
try:
201201
action_ground_response = result["action_ground_response"]
202202
seeact_action = seeact_utils.extract_element_action_value(
203-
action_ground_response.split("\n")
203+
action_ground_response.split("\n") # pyrefly: ignore[missing-attribute]
204204
)
205205
action = seeact_utils.convert_seeact_action_to_json_action(
206206
seeact_action, actionable_elements
@@ -217,7 +217,7 @@ def step(
217217
seeact_action, actionable_elements
218218
)
219219
action_description = seeact_utils.generate_action_description(
220-
seeact_action, target_element
220+
seeact_action, target_element # pyrefly: ignore[bad-argument-type]
221221
)
222222
actuation.execute_adb_action(
223223
action,

android_world/agents/seeact_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ def extract_element_action_value(lines: list[str]) -> SeeActAction:
430430
elif line.startswith("VALUE:"):
431431
value = line.split(":")[1].strip().strip(".")
432432

433-
_validate_action(element, action, value)
434-
return SeeActAction(action=action, element=element, value=value)
433+
_validate_action(element, action, value) # pyrefly: ignore[bad-argument-type]
434+
return SeeActAction(action=action, element=element, value=value) # pyrefly: ignore[bad-argument-type]
435435

436436

437437
@dataclasses.dataclass
@@ -699,7 +699,7 @@ def convert_seeact_action_to_json_action(
699699
if action_type == json_action.INPUT_TEXT:
700700
text = action.value
701701
elif action_type == json_action.SCROLL:
702-
direction = _swipe_to_scroll(action.value)
702+
direction = _swipe_to_scroll(action.value) # pyrefly: ignore[bad-argument-type]
703703
elif action_type == json_action.OPEN_APP:
704704
app_name = action.value
705705
elif action_type == json_action.ANSWER:

android_world/agents/t3a.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def _action_selection_prompt(
221221
The text prompt for action selection that will be sent to gpt4v.
222222
"""
223223
if history:
224-
history = '\n'.join(history)
224+
history = '\n'.join(history) # pyrefly: ignore[bad-assignment]
225225
else:
226-
history = 'You just started, no action has been performed yet.'
226+
history = 'You just started, no action has been performed yet.' # pyrefly: ignore[bad-assignment]
227227

228228
extra_guidelines = ''
229229
if additional_guidelines:
@@ -372,7 +372,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
372372

373373
try:
374374
converted_action = json_action.JSONAction(
375-
**agent_utils.extract_json(action),
375+
**agent_utils.extract_json(action), # pyrefly: ignore[bad-unpacking]
376376
)
377377
except Exception as e: # pylint: disable=broad-exception-caught
378378
print('Failed to convert the output to a valid action.')
@@ -389,7 +389,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
389389
)
390390

391391
if converted_action.action_type in ['click', 'long-press', 'input-text']:
392-
if converted_action.index is not None and converted_action.index >= len(
392+
if converted_action.index is not None and converted_action.index >= len( # pyrefly: ignore[unsupported-operation]
393393
ui_elements
394394
):
395395
print('Index out of range.')
@@ -403,8 +403,8 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
403403
# Add mark for the target ui element, just used for visualization.
404404
m3a_utils.add_ui_element_mark(
405405
step_data['before_screenshot'],
406-
ui_elements[converted_action.index],
407-
converted_action.index,
406+
ui_elements[converted_action.index], # pyrefly: ignore[bad-index]
407+
converted_action.index, # pyrefly: ignore[bad-argument-type]
408408
logical_screen_size,
409409
adb_utils.get_physical_frame_boundary(self.env.controller),
410410
adb_utils.get_orientation(self.env.controller),
@@ -421,7 +421,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
421421
)
422422

423423
if converted_action.action_type == 'answer':
424-
print('Agent answered with: ' + converted_action.text)
424+
print('Agent answered with: ' + converted_action.text) # pyrefly: ignore[unsupported-operation]
425425

426426
try:
427427
self.env.execute_action(converted_action)
@@ -432,7 +432,7 @@ def step(self, goal: str) -> base_agent.AgentInteractionResult:
432432
)
433433
print(str(e))
434434
step_data['summary'] = (
435-
'Some error happened executing the action '
435+
'Some error happened executing the action ' # pyrefly: ignore[unsupported-operation]
436436
+ converted_action.action_type
437437
)
438438
self.history.append(step_data)

android_world/env/actuation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def execute_adb_action(
4444
x = action.x
4545
y = action.y
4646
if idx is not None:
47-
if idx < 0 or idx >= len(screen_elements):
47+
if idx < 0 or idx >= len(screen_elements): # pyrefly: ignore[unsupported-operation]
4848
raise ValueError(
4949
f'Invalid element index: {idx}, must be between 0 and'
5050
f' {len(screen_elements)-1}.'
5151
)
52-
element = screen_elements[idx]
52+
element = screen_elements[idx] # pyrefly: ignore[bad-index]
5353
if element.bbox_pixels is None:
5454
raise ValueError('Bbox is not present on element.')
5555
x, y = element.bbox_pixels.center
@@ -119,7 +119,7 @@ def execute_adb_action(
119119
adb_utils.press_back_button(env)
120120

121121
elif action.action_type == 'press_keyboard':
122-
adb_utils.press_keyboard_generic(action.keycode, env)
122+
adb_utils.press_keyboard_generic(action.keycode, env) # pyrefly: ignore[bad-argument-type]
123123
elif action.action_type == 'drag_and_drop':
124124
if action.touch_xy is not None and action.lift_xy is not None:
125125
command = adb_utils.generate_drag_and_drop_command(
@@ -140,10 +140,10 @@ def execute_adb_action(
140140
screen_width, screen_height = screen_size
141141
if action.index:
142142
x_min, y_min, x_max, y_max = (
143-
max(screen_elements[action.index].bbox_pixels.x_min, 0),
144-
max(screen_elements[action.index].bbox_pixels.y_min, 0),
145-
min(screen_elements[action.index].bbox_pixels.x_max, screen_width),
146-
min(screen_elements[action.index].bbox_pixels.y_max, screen_height),
143+
max(screen_elements[action.index].bbox_pixels.x_min, 0), # pyrefly: ignore[bad-index]
144+
max(screen_elements[action.index].bbox_pixels.y_min, 0), # pyrefly: ignore[bad-index]
145+
min(screen_elements[action.index].bbox_pixels.x_max, screen_width), # pyrefly: ignore[bad-index]
146+
min(screen_elements[action.index].bbox_pixels.y_max, screen_height), # pyrefly: ignore[bad-index]
147147
)
148148
else:
149149
x_min, y_min, x_max, y_max = (0, 0, screen_width, screen_height)
@@ -218,7 +218,7 @@ def execute_adb_action(
218218
)
219219
adb_utils.issue_generic_request(request, env)
220220
elif action.action_type == 'change_orientation':
221-
adb_utils.change_orientation(action.orientation, env)
221+
adb_utils.change_orientation(action.orientation, env) # pyrefly: ignore[bad-argument-type]
222222
elif action.action_type == json_action.UNKNOWN:
223223
print('Unknown action type; no action will be executed. Try again...')
224224
else:

android_world/env/adb_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ def retry(n: int) -> Callable[[Any], Any]:
17301730
"""Decorator to retry ADB commands."""
17311731

17321732
def decorator(func: Callable[..., T]) -> Callable[..., T]:
1733-
def wrapper(*args: Any, **kwargs: Any) -> T:
1733+
def wrapper(*args: Any, **kwargs: Any) -> T: # pyrefly: ignore[bad-return]
17341734
attempts = 0
17351735
while attempts < n:
17361736
try:

android_world/env/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def get_state(self, wait_to_stabilize: bool = False) -> State:
296296

297297
def execute_action(self, action: json_action.JSONAction) -> None:
298298
if action.action_type == json_action.ANSWER:
299-
self.interaction_cache = action.text
299+
self.interaction_cache = action.text # pyrefly: ignore[bad-assignment]
300300
if action.text:
301301
self.display_message(action.text, header='Agent answered:')
302302
return

0 commit comments

Comments
 (0)