优化操作逻辑

This commit is contained in:
yuruo
2025-03-12 13:21:10 +08:00
parent 15d18b0c7d
commit 458a0c5cbe
3 changed files with 7 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ from datetime import datetime
from enum import StrEnum
from functools import partial
from pathlib import Path
import time
from typing import cast
import argparse
import gradio as gr
@@ -170,7 +171,8 @@ def process_input(user_input, state, vision_agent_state):
# Reset the stop flag
if state["stop"]:
state["stop"] = False
# wait 3 seconds
time.sleep(3)
config = Config()
config.set_openai_config(base_url=state["base_url"], api_key=state["api_key"], model=state["model"])
# Append the user message to state["messages"]

View File

@@ -1,10 +1,8 @@
"""
Agentic sampling loop that calls the Anthropic API and local implenmentation of anthropic-defined computer use tools.
"""
import base64
from collections.abc import Callable
from time import time
from time import sleep
import cv2
from gradio_ui.agent.vision_agent import VisionAgent
from gradio_ui.tools.screen_capture import get_screenshot
@@ -54,7 +52,7 @@ def sampling_loop_sync(
while True:
parsed_screen = parse_screen(vision_agent)
tools_use_needed, __ = task_run_agent(task_plan=plan, parsed_screen=parsed_screen)
time.sleep(1)
sleep(2)
for message, tool_result_content in executor(tools_use_needed, messages):
yield message
if not tool_result_content:

View File

@@ -1,6 +1,5 @@
import base64
import time
from enum import StrEnum
from typing import Literal, TypedDict
from PIL import Image
from util import tool
@@ -175,6 +174,8 @@ class ComputerTool(BaseAnthropicTool):
pyautogui.click()
elif action == "right_click":
pyautogui.rightClick()
# 等待5秒等待菜单弹出
time.sleep(5)
elif action == "middle_click":
pyautogui.middleClick()
elif action == "double_click":