From e573ecb55312cfea2482d4c5e6a56018c4c504ee Mon Sep 17 00:00:00 2001 From: Showdown76py Date: Mon, 19 May 2025 09:30:58 +0200 Subject: [PATCH] Add confirmation function and re-execution logic in AIProcessor; clean up web server request handling --- ai/processor.py | 15 +++++++++++++++ objects/aic.py | 17 +++++++++++++++++ webserver/web.py | 2 -- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ai/processor.py b/ai/processor.py index 5b9c6be..d80d8a1 100644 --- a/ai/processor.py +++ b/ai/processor.py @@ -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() diff --git a/objects/aic.py b/objects/aic.py index 784d1b2..48ae31f 100644 --- a/objects/aic.py +++ b/objects/aic.py @@ -92,6 +92,23 @@ FUNCTIONS = [ "required": ["nextsteps"], } } + }, + { + "type": "function", + "function": { + "name": "confirm", + "description": "Confirm that the task is completed and no further actions are needed. ONLY execute this when no other functions/actions are needed. This can be the only function called.", + "parameters": { + "type": "object", + "properties": { + "goal": { + "type": "string", + "description": "The goal to achieve/that was achieved." + } + }, + "required": ["goal"], + } + } } ] diff --git a/webserver/web.py b/webserver/web.py index ca276d4..b5673c8 100644 --- a/webserver/web.py +++ b/webserver/web.py @@ -27,8 +27,6 @@ class WebServerApp: # Process the data as needed prompt = data.get('prompt', '') - - if not prompt: return jsonify({"error": "No prompt provided"}), 400 img_data = None