mirror of
https://github.com/yuruotong1/autoMate.git
synced 2025-12-26 05:16:21 +08:00
增加登陆页面
This commit is contained in:
parent
c577952f51
commit
476ba6585e
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,4 +9,5 @@ config.yaml
|
||||
|
||||
**.lock
|
||||
# Ignore Python cache files
|
||||
**/__pycache__/
|
||||
**/__pycache__/
|
||||
/session
|
||||
|
||||
32
main.py
32
main.py
@ -1,10 +1,17 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import leancloud
|
||||
from PyQt6.QtWidgets import QApplication, QWidget
|
||||
from langchain.agents import create_openai_functions_agent, AgentExecutor, AgentType, create_react_agent
|
||||
from langchain_core.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, MessagesPlaceholder, PromptTemplate, \
|
||||
HumanMessagePromptTemplate
|
||||
|
||||
from ui.login_page import LoginPage
|
||||
from agent.manager_agent import ManagerAgent
|
||||
from agent.plan_agent import PlanAgent
|
||||
from tools.search_engine_tool import SearchEngineTool
|
||||
from utils.config import Config
|
||||
from utils.llm_util import LLMUtil
|
||||
from work_principle.okr_principle import OKR_Object
|
||||
import logging
|
||||
@ -47,8 +54,31 @@ class AutoMate:
|
||||
r = input("请输入你的问题:\n")
|
||||
agent_executor.invoke({"input": r})
|
||||
|
||||
def run_ui(self):
|
||||
config = Config()
|
||||
leancloud.init(config.LEAN_CLOUD["id"], config.LEAN_CLOUD["key"])
|
||||
# 从文件中判断是否有session
|
||||
tmp_file = "./session"
|
||||
if os.path.exists(tmp_file):
|
||||
with open(tmp_file, 'rb') as file:
|
||||
session_token = file.read()
|
||||
leancloud.User.become(session_token)
|
||||
authenticated = leancloud.User.get_current().is_authenticated()
|
||||
if not authenticated:
|
||||
self.goto_login_page()
|
||||
else:
|
||||
print("登陆成功")
|
||||
else:
|
||||
self.goto_login_page()
|
||||
|
||||
def goto_login_page(self):
|
||||
app = QApplication(sys.argv)
|
||||
w = LoginPage()
|
||||
w.show()
|
||||
sys.exit(app.exec())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
automator = AutoMate()
|
||||
automator.run()
|
||||
automator.run_ui()
|
||||
# print(automator.call_chatgpt_api("Hello"))
|
||||
|
||||
@ -14,6 +14,9 @@ webdriver-manager = "4.0.1"
|
||||
langchain = "0.1.7"
|
||||
langchain-openai = "0.0.6"
|
||||
pytest = "^8.0.1"
|
||||
pyqt6 = "^6.6.1"
|
||||
leancloud = "^2.9.12"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
|
||||
@ -16,5 +16,5 @@ class TestLangChain:
|
||||
chain = prompt | model | StrOutputParser() | SearchEngineTool()
|
||||
search_datas = chain.invoke({"input": "谁是李一舟"})
|
||||
info = "\n".join(f"{i+1}. {data.title}" for i, data in enumerate(search_datas))
|
||||
choice = input(f"下面是百度搜索结果,请选择你觉得有用的信息以逗号分割,如1,3,4:\n{info}")
|
||||
|
||||
choice = input(f"下面是百度搜索结果,请选择你觉得有用的信息以逗号分割,如1,3,4,直接回车代表all in:\n{info}")
|
||||
choice = list(map(int, choice.split(",")))
|
||||
|
||||
@ -18,6 +18,7 @@ class SearchEngineTool(ToolBase):
|
||||
description = "利用搜索引擎搜索关键词,得到结果列表"
|
||||
args_schema: Type[BaseModel] = SearchInput
|
||||
|
||||
|
||||
def _run(self, key: str, run_manager: Optional[CallbackManagerForToolRun] = None) -> list[SearchData]:
|
||||
"""Use the tool."""
|
||||
selenium = SeleniumUtil()
|
||||
|
||||
@ -24,7 +24,7 @@ class WebBrowserUrl():
|
||||
driver = webdriver.Chrome(service=ChromeService(webdriver_manager.install()), options=options)
|
||||
elif browser_type == "edge":
|
||||
options = webdriver.EdgeOptions()
|
||||
options.add_argument("--headless") # Enable headless mode
|
||||
# options.add_argument("--headless") # Enable headless mode
|
||||
webdriver_manager = EdgeChromiumDriverManager()
|
||||
driver = webdriver.Edge(service=EdgeService(webdriver_manager.install()), options=options)
|
||||
else:
|
||||
|
||||
91
ui/login.ui
Normal file
91
ui/login.ui
Normal file
@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>508</width>
|
||||
<height>424</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>autoMate</string>
|
||||
</property>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>120</y>
|
||||
<width>54</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>用户</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>130</x>
|
||||
<y>110</y>
|
||||
<width>251</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="textEdit_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>130</x>
|
||||
<y>210</y>
|
||||
<width>251</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>220</y>
|
||||
<width>54</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>密码</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>190</x>
|
||||
<y>280</y>
|
||||
<width>121</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>没有账户?点击注册</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>200</x>
|
||||
<y>320</y>
|
||||
<width>81</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>登陆</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@ -11,6 +11,7 @@ class Config:
|
||||
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.LEAN_CLOUD = self.config["leancloud"]
|
||||
|
||||
# Load content from a yaml file and return as variables
|
||||
def _load_config(self, file_path):
|
||||
|
||||
@ -20,7 +20,7 @@ class SeleniumUtil:
|
||||
driver = webdriver.Chrome(service=ChromeService(webdriver_manager.install()), options=options)
|
||||
elif browser_type == "edge":
|
||||
options = webdriver.EdgeOptions()
|
||||
options.add_argument("--headless") # Enable headless mode
|
||||
# options.add_argument("--headless") # Enable headless mode
|
||||
webdriver_manager = EdgeChromiumDriverManager()
|
||||
driver = webdriver.Edge(service=EdgeService(webdriver_manager.install()), options=options)
|
||||
else:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user