MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / try_to_replace

Function try_to_replace

eval_heldout/science-world/eval_utils.py:368–418  ·  view source on GitHub ↗
(action, validActions, look=None, inventory=None)

Source from the content-addressed store, hash-verified

366 return action
367
368def try_to_replace(action, validActions, look=None, inventory=None):
369 if action.startswith("wait"):
370 return "wait"
371 if action in validActions:
372 return action
373 try_action = action.replace("green house", "greenhouse")
374 try_action = try_action.replace("adult", "adult adult")
375 try_action = try_action.replace("baby", "baby baby")
376 if try_action in validActions:
377 return try_action
378 if action.startswith("go to"):
379 if action.replace("go to", "teleport to") in validActions:
380 return action.replace("go to", "teleport to")
381 elif action.replace("go to", "open door to") in validActions:
382 return action.replace("go to", "open door to")
383 if action.startswith("pick up"):
384 action = find_object(action, look)
385 if action in validActions:
386 return action
387 if action.replace("substance in ","") in validActions:
388 return action
389 if action.startswith("focus on"):
390 obj = action.replace("focus on", "").strip()
391 todo = "focus on substance in inventory"
392 if obj in inventory and todo in validActions:
393 return todo
394 if action.startswith("move") and "to" in action:
395 pattern = r"move (.*?) to"
396 obj = re.search(pattern, action)
397 if obj is None:
398 return action
399 else:
400 obj = obj.group(1)
401 todo = action.replace(obj, "substance in inventory")
402 if obj in inventory and todo in validActions:
403 return todo
404
405
406 split_string = action.rsplit(" in ", 1) # Split the string from the last occurrence of " in "
407 if split_string[0] in validActions:
408 return split_string[0]
409
410 if " unknown substance " in action:
411 action = split_string[0]
412 action = clean_obj_name(action)
413 if action in validActions:
414 return action
415
416 for r in rooms:
417 action = action.replace("in " + r, "")
418 return action
419
420
421def findValidActionWithSystem2(predictions, env, task_id, task_description, look,

Callers 1

Calls 3

find_objectFunction · 0.85
clean_obj_nameFunction · 0.85
searchMethod · 0.80

Tested by

no test coverage detected