Add confirmation function and re-execution logic in AIProcessor; clean up web server request handling

This commit is contained in:
2025-05-19 09:30:58 +02:00
parent f7feb12946
commit e573ecb553
3 changed files with 32 additions and 2 deletions

View File

@@ -37,6 +37,8 @@ class AIProcessor:
# -------------------------- main entry -------------------------- #
def process(self, prompt: str, img_data: str | bytes | None = None) -> str | list[str | dict]:
outputs = [] # type: list[str | dict]
reexec = True
nextsteps = ""
try:
self.session.messages.append(
aic.Message(role="user", content=prompt, image=img_data)
@@ -51,6 +53,9 @@ class AIProcessor:
tool_calls = getattr(response.choices[0].message, "tool_calls", None)
if tool_calls:
for tc in tool_calls:
if tc.function.name == "confirm":
reexec = False
nextsteps = tc.function.arguments.get("goal", "")
r = ai.compute._execute(
name=tc.function.name,
args=json.loads(tc.function.arguments),
@@ -72,6 +77,16 @@ class AIProcessor:
self.session.messages.append(
aic.Message(role="assistant", content=output_text)
)
# re-execute if needed
if reexec:
img = ai.compute.screenshot_to_base64(
ai.compute.take_screenshot()
)
outputs.append(
*self.process(nextsteps, img)
)
return outputs
except Exception as e:
traceback.print_exc()