From f2476d53a392590fce6cebfdd5e64ea59528baa2 Mon Sep 17 00:00:00 2001 From: yuruo Date: Wed, 26 Mar 2025 08:48:21 +0800 Subject: [PATCH] update fewshot --- ui/recording_manager.py | 19 +++++++++++++++--- ui/recording_panel.py | 43 ----------------------------------------- util/auto_control.py | 7 +------ 3 files changed, 17 insertions(+), 52 deletions(-) delete mode 100644 ui/recording_panel.py diff --git a/ui/recording_manager.py b/ui/recording_manager.py index ddc4a67..94eb090 100644 --- a/ui/recording_manager.py +++ b/ui/recording_manager.py @@ -2,12 +2,13 @@ Recording manager for autoMate Handles recording and demonstration functionality """ +import yaml +from auto_control.agent.few_shot_generate_agent import FewShotGenerateAgent from util.auto_control import AutoControl -from ui.recording_panel import RecordingIndicator from ui.demonstration_panel import DemonstrationPanel from PyQt6.QtCore import QThread, pyqtSignal import time - +import os class ActionListenThread(QThread): finished_signal = pyqtSignal() @@ -81,4 +82,16 @@ class RecordingManager: """process all recorded actions""" # get all collected actions recorded_actions = self.action_listen.auto_list - print("recorded_actions: ", recorded_actions) + few_shot_generate_agent = FewShotGenerateAgent() + few_shot = few_shot_generate_agent(recorded_actions) + # Save few shot examples to ~/.automate directory + + # Create .automate directory if not exists + automate_dir = os.path.expanduser("~/.automate") + if not os.path.exists(automate_dir): + os.makedirs(automate_dir) + # Save few shot examples + few_shot_path = os.path.join(automate_dir, "few_shot.yaml") + with open(few_shot_path, "w", encoding="utf-8") as f: + yaml.dump(few_shot, f, allow_unicode=True) + print(f"Few shot examples saved to {few_shot_path}") diff --git a/ui/recording_panel.py b/ui/recording_panel.py deleted file mode 100644 index e36d4c8..0000000 --- a/ui/recording_panel.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -Recording indicator panel for autoMate -""" -from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QApplication -from PyQt6.QtCore import Qt, QPoint - -class RecordingIndicator(QWidget): - def __init__(self, parent=None, stop_callback=None): - super().__init__(parent, Qt.WindowType.WindowStaysOnTopHint | Qt.WindowType.FramelessWindowHint) - self.stop_callback = stop_callback - self.setup_ui() - self.position_to_bottom_right() - - def setup_ui(self): - layout = QVBoxLayout() - - # Recording status label - self.status_label = QLabel("Recording in progress") - self.status_label.setStyleSheet("color: red; font-weight: bold;") - layout.addWidget(self.status_label) - - # Stop button - self.stop_button = QPushButton("Stop Recording") - self.stop_button.clicked.connect(self.on_stop_clicked) - layout.addWidget(self.stop_button) - - self.setLayout(layout) - self.resize(200, 100) - self.setStyleSheet("background-color: #f0f0f0; border: 1px solid #999;") - - def position_to_bottom_right(self): - screen = QApplication.primaryScreen() - screen_geometry = screen.availableGeometry() - window_geometry = self.frameGeometry() - position = QPoint( - screen_geometry.width() - window_geometry.width() - 20, - screen_geometry.height() - window_geometry.height() - 20 - ) - self.move(position) - - def on_stop_clicked(self): - if self.stop_callback: - self.stop_callback() \ No newline at end of file diff --git a/util/auto_control.py b/util/auto_control.py index 4d2886c..b11f4c9 100644 --- a/util/auto_control.py +++ b/util/auto_control.py @@ -1,9 +1,6 @@ import sys import os import time -import json - -from auto_control.agent.few_shot_generate_agent import FewShotGenerateAgent # Add the project root directory to Python path sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from pynput import mouse, keyboard @@ -33,7 +30,6 @@ class ActionRecord: class AutoControl: def __init__(self): self.auto_list = [] - self.tmp_auto_list = [] self.text_buffer = [] # Buffer for collecting continuous text input self.last_key_time = 0 # Timestamp of last keypress self.input_timeout = 1.0 # Input timeout in seconds @@ -170,8 +166,7 @@ class AutoControl: """Stop listening and prepare data for LLM analysis""" self.keyboard_listener.stop() self.mouse_listener.stop() - few_shot_generate_agent = FewShotGenerateAgent() - return few_shot_generate_agent(self.auto_list) + if __name__ == "__main__": auto_control = AutoControl()