Skip to content

Commit

Permalink
batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Mac0q committed Dec 13, 2024
1 parent ee14048 commit a128f12
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
34 changes: 10 additions & 24 deletions ufo/agents/agent/host_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,16 @@ def create_app_agent(
:return: The app agent.
"""

if mode == "normal":

agent_name = "AppAgent/{root}/{process}".format(
root=application_root_name, process=application_window_name
if mode == "normal" or "batch_normal":

agent_name = (
"AppAgent/{root}/{process}".format(
root=application_root_name, process=application_window_name
)
if mode == "normal"
else "BatchAgent/{root}/{process}".format(
root=application_root_name, process=application_window_name
)
)

app_agent: AppAgent = self.create_subagent(
Expand Down Expand Up @@ -273,26 +279,6 @@ def create_app_agent(
api_prompt=configs["API_PROMPT"],
app_info_prompt=app_info_prompt,
)
elif mode == "batch_normal":

# Load additional app info prompt.
app_info_prompt = configs.get("APP_INFO_PROMPT", None)

agent_name = "BatchAgent/{root}/{process}".format(
root=application_root_name, process=application_window_name
)

# Create the app agent in the batch_normal mode.
app_agent: AppAgent = self.create_subagent(
agent_type="app",
agent_name=agent_name,
process_name=application_window_name,
app_root_name=application_root_name,
is_visual=configs["APP_AGENT"]["VISUAL_MODE"],
main_prompt=configs["APPAGENT_PROMPT"],
example_prompt=configs["APPAGENT_EXAMPLE_PROMPT"],
api_prompt=configs["API_PROMPT"],
)

else:
raise ValueError(f"The {mode} mode is not supported.")
Expand Down
13 changes: 11 additions & 2 deletions ufo/module/sessions/plan_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, plan_file: str):
with open(plan_file, "r") as f:
self.plan = json.load(f)
self.remaining_steps = self.get_steps()
self.support_apps = ["word", "excel", "powerpoint"]

def get_close(self) -> bool:
"""
Expand Down Expand Up @@ -56,7 +57,7 @@ def get_operation_object(self) -> str:
:return: The operation object.
"""

return self.plan.get("object", None)
return self.plan.get("object", None).lower()

def get_initial_request(self) -> str:
"""
Expand Down Expand Up @@ -99,6 +100,14 @@ def get_file_path(self):

return os.path.join(file_path, file)

def get_support_apps(self) -> List[str]:
"""
Get the support apps in the plan.
:return: The support apps in the plan.
"""

return self.support_apps

def get_host_request(self) -> str:
"""
Get the request for the host agent.
Expand All @@ -107,7 +116,7 @@ def get_host_request(self) -> str:

task = self.get_task()
object_name = self.get_operation_object()
if object_name:
if object_name in self.support_apps:
request = task
else:
request = f"Open the application of {task}. You must output the selected application with their control text and label even if it is already open."
Expand Down
7 changes: 5 additions & 2 deletions ufo/module/sessions/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def __init__(
super().__init__(task, should_evaluate, id)
self.plan_file = plan_file
self.plan_reader = PlanReader(plan_file)
self.support_apps = self.plan_reader.get_support_apps()
self.close = self.plan_reader.get_close()
self.task_name = task.split("/")[1]
self.object_name = ""
Expand Down Expand Up @@ -474,13 +475,15 @@ def setup_application_environment(self):
if self.object_name:
suffix = os.path.splitext(self.object_name)[1]
self.app_name = self.get_app_name(suffix)
app_com = self.get_app_com(suffix)
if self.app_name not in self.support_apps:
return # The app is not supported, so we don't need to setup the environment.
file = self.plan_reader.get_file_path()
code_snippet = f"import os\nos.system('start {self.app_name} \"{file}\"')"
code_snippet = code_snippet.replace("\\", "\\\\") # escape backslashes
try:
exec(code_snippet, globals())
time.sleep(3) # wait for the app to boot
app_com = self.get_app_com(suffix)
time.sleep(2) # wait for the app to boot
word_app = win32com.client.Dispatch(app_com)
word_app.WindowState = 1 # wdWindowStateMaximize
except Exception as e:
Expand Down

0 comments on commit a128f12

Please sign in to comment.