mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
更新
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -14,4 +14,6 @@ cache
|
||||
**/__pycache__/
|
||||
/session
|
||||
|
||||
*.spec
|
||||
*.spec
|
||||
|
||||
agent/model
|
||||
@@ -1,11 +1,9 @@
|
||||
import pickle
|
||||
from typing import List
|
||||
import uuid
|
||||
from PyQt6 import QtCore
|
||||
from PyQt6.QtCore import Qt, QMimeData, QByteArray, QPoint, pyqtSignal
|
||||
from PyQt6.QtGui import QDrag
|
||||
from PyQt6.QtWidgets import QListWidget, QApplication, QStyle, QMenu
|
||||
from actions.action_base import ActionBase
|
||||
from actions.action_list_item import ActionListItem
|
||||
from actions.action_signal import ActionSignal
|
||||
from pages.styled_item_delegate import StyledItemDelegate
|
||||
@@ -98,6 +96,7 @@ class ActionList(QListWidget):
|
||||
# 获取双击的项
|
||||
item = self.itemAt(event.pos())
|
||||
item.action.config_page_show()
|
||||
event.accept()
|
||||
|
||||
|
||||
# 记录拖拽初始位置
|
||||
@@ -135,9 +134,13 @@ class ActionList(QListWidget):
|
||||
|
||||
def mouseReleaseEvent(self, e):
|
||||
# 鼠标release时才选中
|
||||
index = self.indexAt(e.pos())
|
||||
index = self.indexAt(e.pos())
|
||||
# 取消其他 action_list 的选中
|
||||
self.clear_selection()
|
||||
self.setCurrentIndex(index)
|
||||
e.accept()
|
||||
print(self)
|
||||
|
||||
|
||||
def mouseMoveEvent(self, e):
|
||||
# 如果在历史事件中左键点击过
|
||||
@@ -265,7 +268,6 @@ class ActionList(QListWidget):
|
||||
GlobalUtil.current_page.q_undo_stack.push(ActionListAddCommand(self, self.the_insert_row, drag_action_item))
|
||||
# 取消选中
|
||||
self.clear_selection()
|
||||
# self.setCurrentRow(self.the_insert_row)
|
||||
e.setDropAction(Qt.DropAction.MoveAction)
|
||||
e.accept()
|
||||
|
||||
@@ -280,7 +282,8 @@ class ActionList(QListWidget):
|
||||
|
||||
# 取消选中
|
||||
def clear_selection(self):
|
||||
for widget in GlobalUtil.all_widget:
|
||||
if isinstance(widget, ActionList):
|
||||
for widget in GlobalUtil.all_widget["action_list"]:
|
||||
if isinstance(widget, ActionList) and \
|
||||
widget.uuid != self.uuid and \
|
||||
widget.currentRow() != -1:
|
||||
widget.setCurrentRow(-1)
|
||||
widget.update()
|
||||
@@ -1,26 +0,0 @@
|
||||
|
||||
|
||||
class AgentBase:
|
||||
def __init__(self, role):
|
||||
"""
|
||||
Initialize an Agent object.
|
||||
|
||||
Args:
|
||||
role (str): The role of the agent.
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
self.role = role
|
||||
|
||||
def set_role(self, new_role):
|
||||
"""
|
||||
Set the role of the agent.
|
||||
|
||||
Args:
|
||||
new_role (str): The new role of the agent.
|
||||
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
self.role = new_role
|
||||
21
agent/gemma.py
Normal file
21
agent/gemma.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||
import os
|
||||
import torch
|
||||
from utils.qt_util import QtUtil
|
||||
|
||||
|
||||
def gemma():
|
||||
print(torch.version)
|
||||
# 项目根目录
|
||||
model_path = os.path.join(QtUtil.get_root_path(), "agent", "model")
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
||||
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto")
|
||||
while True:
|
||||
input_text = input("请输入问题?")
|
||||
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
|
||||
outputs = model.generate(**input_ids, max_length=512)
|
||||
print(tokenizer.decode(outputs[0]))
|
||||
|
||||
if __name__ == "__main__":
|
||||
gemma()
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import json
|
||||
from agent.agent_base import AgentBase
|
||||
from agent.plan_agent import PlanAgent
|
||||
from work_principle.okr_principle import OKR_Object
|
||||
import logging
|
||||
|
||||
class ManagerAgent(AgentBase):
|
||||
def __init__(self):
|
||||
super().__init__("你是一名总经理,负责与客户对齐目标,与计划拆解者对齐关键结果")
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
# 与用户对齐目标,填充缺失的信息
|
||||
def optimization_Object(self, okr_object: OKR_Object):
|
||||
# todo 待加入 PDCA循环规则
|
||||
for i in okr_object.task.content:
|
||||
call_openai_res = {'isOk': 'no', 'content': ''}
|
||||
while call_openai_res["isOk"] == "no":
|
||||
prompt = f"这是一个任务描述:'{okr_object.raw_user_task}'。你觉得这个任务描述具备{i['descriptions']}吗?如果具备返回格式如下:{{\"isOk\":\"yes\", \"content\":\"提炼出任务的{i['descriptions']}\"}},如果不具备返回格式如下:{{\"isOk\":\"no\",\"content\":\"返回不具备的原因并给出完善建议\"}}"
|
||||
call_openai_res = json.loads(self.call_gpt(prompt))
|
||||
if call_openai_res["isOk"] == "no":
|
||||
okr_object.raw_user_task = okr_object.raw_user_task + f",{i['target']}:" + input(
|
||||
f"【任务】{okr_object.raw_user_task}\n\n【警告】{call_openai_res['content']}\n请您补充信息:")
|
||||
i['content'] = call_openai_res["content"]
|
||||
|
||||
|
||||
# 与计划拆解者对齐关键结果,填充缺失的信息
|
||||
def assign_task_to_plan_agent(self, okr_object: OKR_Object):
|
||||
okr_object.task.raw_user_task
|
||||
PlanAgent()
|
||||
@@ -1,26 +0,0 @@
|
||||
import logging
|
||||
from agent.agent_base import AgentBase
|
||||
from tools.tool_base import ToolBase
|
||||
from tools.tools_factory import ToolsFactory
|
||||
from work_principle.okr_principle import OKR_Object
|
||||
|
||||
class PlanAgent(AgentBase):
|
||||
def __init__(self):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
super().__init__('#Goals:\n你是一名计划拆解者,将object拆解成key_result,\n#Workflow:1.')
|
||||
'''
|
||||
'''
|
||||
# '多个key_result完成这一个目标,返回格式如下:{"tools_name":"web_browser","request_param":"请求参数"}'
|
||||
# 根据object和已有的工具能力拆解成key result,key
|
||||
def aligning(self, okr_object: OKR_Object):
|
||||
raw = okr_object.raw_user_task
|
||||
r = self.call_gpt(f"object为'{raw}', 工具列表为{list(ToolsFactory().get_tools())}")
|
||||
self.logger.info(f"prompt:object为'{raw}', 工具列表为{list(ToolsFactory().get_tools())}")
|
||||
self.logger.info(f"Alignment result: {r}")
|
||||
# return r
|
||||
|
||||
def get_subclasses(self, cls):
|
||||
subclasses = []
|
||||
for subclass in cls.__subclasses__():
|
||||
subclasses.append(subclass)
|
||||
return subclasses
|
||||
1
main.py
1
main.py
@@ -2,7 +2,6 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
import leancloud
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
from pages.chat_page import ChatPage
|
||||
|
||||
@@ -30,6 +30,7 @@ class StyledItemDelegate(QStyledItemDelegate):
|
||||
# 选中时,最左边会出现小块块
|
||||
painter.setBrush(QColor(0, 0, 255))
|
||||
painter.drawRect(0, rect.topLeft().y(), 6, rect.height())
|
||||
|
||||
# 开始拖拽
|
||||
if is_drag:
|
||||
if index.row() == drag_widget.the_highlighted_row:
|
||||
|
||||
Reference in New Issue
Block a user