mirror of
https://github.com/yuruotong1/autoMate.git
synced 2025-12-26 05:16:21 +08:00
增加配置页面
This commit is contained in:
parent
b9ac21c5e7
commit
9bbcf9e749
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,7 +2,7 @@
|
||||
# Ignore IDE and editor files
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
dist/
|
||||
# Ignore environment-specific files
|
||||
.venv
|
||||
config.yaml
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
browser:
|
||||
browser_type: edge
|
||||
|
||||
openai:
|
||||
# key
|
||||
api_key: xxx
|
||||
|
||||
@ -5,6 +5,7 @@ from PyQt6.QtWidgets import QLabel, QTextEdit, QListWidgetItem, QSpacerItem, QSi
|
||||
|
||||
from agent.woker_agent import WorkerAgent
|
||||
from pages.bse_page import BasePage
|
||||
from utils.config import Config
|
||||
from utils.qt_util import QtUtil
|
||||
|
||||
|
||||
@ -42,6 +43,10 @@ class ChatInput(QTextEdit):
|
||||
|
||||
|
||||
class ChatPage(BasePage):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setting_page = None
|
||||
|
||||
def setup_up(self):
|
||||
self.ui = QtUtil.load_ui("chat_page.ui")
|
||||
self.ui.text_edit = ChatInput()
|
||||
@ -61,9 +66,30 @@ class ChatPage(BasePage):
|
||||
# 设置 QListWidget 的焦点策略为 NoFocus
|
||||
self.ui.chat_list.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||
# self.ui.select_action.clicked.connect(self.select_action_clicked)
|
||||
setting_action = self.ui.setting_action
|
||||
setting_action.triggered.connect(self.open_setting_page)
|
||||
|
||||
def open_setting_page(self):
|
||||
self.setting_page = QtUtil.load_ui("setting_page.ui")
|
||||
config = Config()
|
||||
self.setting_page.openai_key.setText(config.OPEN_AI.get("openai_key"))
|
||||
self.setting_page.openai_url.setText(config.OPEN_AI.get("openai_url"))
|
||||
self.setting_page.openai_model.setText(config.OPEN_AI.get("openai_model"))
|
||||
self.setting_page.save_btn.clicked.connect(self.save_setting)
|
||||
self.setting_page.cancel_btn.clicked.connect(self.cancel_btn)
|
||||
self.setting_page.show()
|
||||
|
||||
def save_setting(self):
|
||||
config = Config()
|
||||
config.update_config(Config.OPENAI, Config.OPENAI_KEY, self.setting_page.openai_key.text())
|
||||
config.update_config(Config.OPENAI, Config.OPENAI_URL, self.setting_page.openai_url.text())
|
||||
config.update_config(Config.OPENAI, Config.OPENAI_MODEL, self.setting_page.openai_model.text())
|
||||
self.setting_page.close()
|
||||
|
||||
def cancel_btn(self):
|
||||
self.setting_page.close()
|
||||
|
||||
def hide_action(self, event):
|
||||
print("hello")
|
||||
action_widget = self.ui.action_widget
|
||||
if not QRect(action_widget.mapToGlobal(QPoint(0, 0)), action_widget.size()).contains(event.globalPos()):
|
||||
action_widget.hide()
|
||||
|
||||
@ -40,19 +40,6 @@
|
||||
<string notr="true">border-radius: 30px</string>
|
||||
</property>
|
||||
</widget>
|
||||
<!-- <widget class="QPushButton" name="select_action">-->
|
||||
<!-- <property name="geometry">-->
|
||||
<!-- <rect>-->
|
||||
<!-- <x>40</x>-->
|
||||
<!-- <y>550</y>-->
|
||||
<!-- <width>75</width>-->
|
||||
<!-- <height>23</height>-->
|
||||
<!-- </rect>-->
|
||||
<!-- </property>-->
|
||||
<!-- <property name="text">-->
|
||||
<!-- <string>选行为</string>-->
|
||||
<!-- </property>-->
|
||||
<!-- </widget>-->
|
||||
<widget class="QWidget" name="action_widget" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@ -116,26 +103,21 @@ border: none;</string>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu">
|
||||
<widget class="QMenu" name="file_menu">
|
||||
<property name="title">
|
||||
<string>主页</string>
|
||||
<string>文件</string>
|
||||
</property>
|
||||
<addaction name="setting_action"/>
|
||||
<addaction name="separator"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_2">
|
||||
<property name="title">
|
||||
<string>个人空间</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_3">
|
||||
<property name="title">
|
||||
<string>商店</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menu"/>
|
||||
<addaction name="menu_2"/>
|
||||
<addaction name="menu_3"/>
|
||||
<addaction name="file_menu"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="setting_action">
|
||||
<property name="text">
|
||||
<string>设置</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
120
pages/setting_page.ui
Normal file
120
pages/setting_page.ui
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>setting_window</class>
|
||||
<widget class="QMainWindow" name="setting_window">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>606</width>
|
||||
<height>443</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>设置</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>70</y>
|
||||
<width>341</width>
|
||||
<height>181</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>openai_key</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="openai_key"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>openai_url</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="openai_url">
|
||||
<property name="text">
|
||||
<string>https://api.fast-tunnel.one/v1/</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>model</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="openai_model">
|
||||
<property name="text">
|
||||
<string>gpt-4-1106-preview</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="save_btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>380</x>
|
||||
<y>330</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="cancel_btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>480</x>
|
||||
<y>330</y>
|
||||
<width>75</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>取消</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>606</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@ -6,7 +6,7 @@ authors = ["yuruotong"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
python = ">=3.9,<3.13"
|
||||
PyYAML = "6.0.1"
|
||||
requests = "2.31.0"
|
||||
selenium = "4.16.0"
|
||||
@ -18,6 +18,7 @@ pyqt6 = "^6.6.1"
|
||||
leancloud = "^2.9.12"
|
||||
pyautogui = "^0.9.54"
|
||||
langchainhub = "^0.1.15"
|
||||
pyinstaller = "^6.5.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
|
||||
@ -4,13 +4,20 @@ import yaml
|
||||
|
||||
|
||||
class Config:
|
||||
OPENAI_KEY = "openai_key"
|
||||
OPENAI_URL = "openai_url"
|
||||
OPENAI_MODEL = "openai_model"
|
||||
OPENAI = "openai"
|
||||
BROWSER = "browser"
|
||||
|
||||
def __init__(self):
|
||||
# 项目根目录
|
||||
project_root_path = os.path.abspath(os.path.dirname(__file__))
|
||||
self.path = os.path.join(project_root_path, "..", "config.yaml")
|
||||
# 上一层目录
|
||||
self.config = self._load_config(os.path.join(project_root_path, "..", "config.yaml"))
|
||||
self.OPEN_AI = self.config["openai"]
|
||||
self.BROWSER = self.config["browser"]
|
||||
self.config = self._load_config(self.path)
|
||||
self.OPEN_AI = self.config[self.OPENAI]
|
||||
self.BROWSER_CONFIG = self.config[self.BROWSER]
|
||||
self.DATA_POSITION = self.config["data_position"]
|
||||
self.LEAN_CLOUD = None
|
||||
if self.DATA_POSITION == "remote":
|
||||
@ -19,6 +26,21 @@ class Config:
|
||||
@staticmethod
|
||||
# Load content from a yaml file and return as variables
|
||||
def _load_config(file_path):
|
||||
# 如果文件不存在,则生成一个yaml文件
|
||||
if not os.path.exists(file_path):
|
||||
with open(file_path, 'w') as file:
|
||||
data = {Config.OPENAI: {Config.OPENAI_KEY: "your_api_key",
|
||||
Config.OPENAI_URL: "https://api.openai.com/v1/",
|
||||
Config.OPENAI_MODEL: "gpt-4-1106-preview"},
|
||||
"data_position": "local",
|
||||
Config.BROWSER: "edge"}
|
||||
yaml.dump(data, file)
|
||||
|
||||
with open(file_path, 'r') as file:
|
||||
config = yaml.safe_load(file)
|
||||
return config
|
||||
|
||||
def update_config(self, loc, key, value):
|
||||
self.config[loc][key] = value
|
||||
with open(self.path, 'w') as file:
|
||||
yaml.dump(self.config, file)
|
||||
|
||||
@ -5,12 +5,11 @@ class LLM_Util:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.config = Config()
|
||||
self.api_key = self.config.OPEN_AI.get("api_key")
|
||||
self.base_url = self.config.OPEN_AI.get("api_url")
|
||||
self.open_ai_model = self.config.OPEN_AI.get("model")
|
||||
self.model_name = self.config.OPEN_AI.get("model_name", self.open_ai_model)
|
||||
self.api_key = self.config.OPEN_AI.get(Config.OPENAI_KEY)
|
||||
self.base_url = self.config.OPEN_AI.get(Config.OPENAI_URL)
|
||||
self.open_ai_model = self.config.OPEN_AI.get(Config.OPENAI_MODEL)
|
||||
|
||||
def llm(self):
|
||||
from langchain_openai import ChatOpenAI
|
||||
return ChatOpenAI(temperature=0, model_name=self.model_name, openai_api_key=self.api_key,
|
||||
return ChatOpenAI(temperature=0, model_name=self.open_ai_model, openai_api_key=self.api_key,
|
||||
openai_api_base=self.base_url)
|
||||
|
||||
@ -12,7 +12,7 @@ from utils.config import Config
|
||||
class SeleniumUtil:
|
||||
def __init__(self):
|
||||
config = Config()
|
||||
browser_type = config.BROWSER.get("browser_type")
|
||||
browser_type = config.BROWSER_CONFIG.get("browser_type")
|
||||
if browser_type == "chrome":
|
||||
options = webdriver.ChromeOptions()
|
||||
options.add_argument("--headless") # Enable headless mode
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user