mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
new
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,3 +6,6 @@
|
||||
# Ignore environment-specific files
|
||||
.venv
|
||||
config.yaml
|
||||
|
||||
# Ignore Python cache files
|
||||
**/__pycache__/
|
||||
13
README.md
13
README.md
@@ -43,6 +43,17 @@ print(objective.progress) # 输出应该是两个关键成果进度的平均值
|
||||
```
|
||||
|
||||
# 工具
|
||||
使用selenium工具操作浏览器进行网络搜索和内容爬取。
|
||||
使用selenium工具操作浏览器进行网络搜索和内容爬取。以下是一个简单的示例:
|
||||
|
||||
```python
|
||||
from selenium import webdriver
|
||||
|
||||
driver = webdriver.Firefox()
|
||||
driver.get("http://www.python.org")
|
||||
assert "Python" in driver.title
|
||||
driver.quit()
|
||||
```
|
||||
# 安装和运行
|
||||
```commandline
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,4 @@
|
||||
import openai
|
||||
import yaml
|
||||
from tools.llm_tools import LLMTools
|
||||
|
||||
|
||||
class AgentBase:
|
||||
@@ -14,7 +13,6 @@ class AgentBase:
|
||||
None
|
||||
"""
|
||||
self.role = role
|
||||
|
||||
|
||||
def set_role(self, new_role):
|
||||
"""
|
||||
@@ -28,34 +26,5 @@ class AgentBase:
|
||||
"""
|
||||
self.role = new_role
|
||||
|
||||
|
||||
|
||||
def call_gpt(self, input_text):
|
||||
"""
|
||||
Make a call to the OpenAI chat API.
|
||||
|
||||
Args:
|
||||
input_text (str): The input text for the chat API.
|
||||
|
||||
Returns:
|
||||
str: The generated text from the chat API.
|
||||
"""
|
||||
# Load API configuration from YAML file
|
||||
with open("config.yaml", "r") as file:
|
||||
config = yaml.safe_load(file).get("openai")
|
||||
|
||||
openai.api_key = config.get("api_key")
|
||||
openai.base_url = config.get("api_url")
|
||||
|
||||
response = openai.chat.completions.create(
|
||||
model="gpt-3.5-turbo", # GPT-3.5 model
|
||||
messages=[
|
||||
{"role": "system", "content": self.role},
|
||||
{"role": "user", "content": input_text}
|
||||
],
|
||||
temperature=0.2
|
||||
)
|
||||
|
||||
generated_text = response.choices[0].message.content
|
||||
|
||||
return generated_text
|
||||
return LLMTools().run(param={"role": self.role, "content": input_text})
|
||||
|
||||
@@ -3,28 +3,27 @@ from agent.agent_base import AgentBase
|
||||
from agent.plan_agent import PlanAgent
|
||||
from work_principle.okr_principle import OKR_Object
|
||||
import logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
class ManagerAgent(AgentBase):
|
||||
def __init__(self):
|
||||
super().__init__("你是一名总经理,负责与客户对齐目标,与计划拆解者对齐关键结果")
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
# 与用户对齐目标,填充缺失的信息
|
||||
def optimization_Object(self, okr_object:OKR_Object):
|
||||
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" :
|
||||
while call_openai_res["isOk"] == "no":
|
||||
prompt = f"这是一个任务描述:'{okr_object.raw_user_task}'。你觉得这个任务描述具备{i['descriptions']}吗?如果具备返回格式如下:{{\"isOk\":\"yes\", \"content\":\"提炼出任务的{i['descriptions']}\"}},如果不具备返回格式如下:{{\"isOk\":\"no\",\"content\":\"返回不具备的原因并给出完善建议\"}}"
|
||||
self.logger.info(prompt)
|
||||
call_openai_res = json.loads(self.call_gpt(prompt))
|
||||
self.logger.info(call_openai_res)
|
||||
if call_openai_res["isOk"]=="no":
|
||||
okr_object.raw_user_task = okr_object.raw_user_task + f",{i['target']}:" +input(f"【警告】{call_openai_res['content']}\n请您补充信息:")
|
||||
if call_openai_res["isOk"] == "no":
|
||||
okr_object.raw_user_task = okr_object.raw_user_task + f",{i['target']}:" + input(
|
||||
f"【警告】{call_openai_res['content']}\n请您补充信息:")
|
||||
i['content'] = call_openai_res["content"]
|
||||
|
||||
|
||||
|
||||
# 与计划拆解者对齐关键结果,填充缺失的信息
|
||||
def assign_task_to_plan_agent(self, okr_object:OKR_Object):
|
||||
def assign_task_to_plan_agent(self, okr_object: OKR_Object):
|
||||
okr_object.task.raw_user_task
|
||||
PlanAgent()
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
import logging
|
||||
from agent.agent_base import AgentBase
|
||||
from tools.tools_base import ToolsBase
|
||||
from work_principle.okr_principle import OKR_Object
|
||||
|
||||
class PlanAgent(AgentBase):
|
||||
def __init__(self):
|
||||
super().__init__("你是一名计划拆解者,负责对OKR中的O进行拆解并制定KR,向总经理汇报")
|
||||
self.logger = logging.getLogger(__name__)
|
||||
super().__init__('你是一名计划拆解者,利用工具将object拆解成key_result,请你返回json格式的内容,比如["使用工具a进行xx操作", "使用工具b进行xx操作"]')
|
||||
|
||||
# 根据object和已有的工具能力拆解成key result,key
|
||||
def aligning(self, okr_object: OKR_Object):
|
||||
raw = okr_object.raw_user_task
|
||||
tools_list = [i().get_info() for i in self.get_subclasses(ToolsBase)]
|
||||
r = self.call_gpt(f"object为'{raw}', 工具列表为{tools_list}")
|
||||
print(r)
|
||||
self.logger.info(f"Alignment result: {r}")
|
||||
|
||||
# 与用户对齐目标,填充缺失的信息
|
||||
def aligning(self, okr_object:OKR_Object):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
def get_subclasses(self, cls):
|
||||
subclasses = []
|
||||
for subclass in cls.__subclasses__():
|
||||
subclasses.append(subclass)
|
||||
return subclasses
|
||||
|
||||
9
main.py
9
main.py
@@ -1,6 +1,10 @@
|
||||
from agent.manager_agent import ManagerAgent
|
||||
from agent.plan_agent import PlanAgent
|
||||
from work_principle.okr_principle import OKR_Object
|
||||
import logging
|
||||
|
||||
# 设置日志
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
class AutoMate:
|
||||
def __init__(self):
|
||||
@@ -10,11 +14,14 @@ class AutoMate:
|
||||
def rule_define(self):
|
||||
# 与用户对齐任务
|
||||
while True:
|
||||
o_kr = OKR_Object("对比一下copilot和curson谁更好用,比较提示词数量、安装易用性,给出不少于100字的文章")
|
||||
o_kr = OKR_Object("因为想要增加编程效率,对比一下copilot和curson谁更好用,比较提示词数量、安装易用性,给出不少于100字的文章")
|
||||
ManagerAgent().optimization_Object(o_kr)
|
||||
r = input(f"最终对齐的任务是:{o_kr.raw_user_task},一切都OK对吧?y/n")
|
||||
if r == "y":
|
||||
break
|
||||
|
||||
# 让计划拆解者拆解任务
|
||||
PlanAgent().aligning(o_kr)
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
requirements.txt
Normal file
BIN
requirements.txt
Normal file
Binary file not shown.
@@ -1,7 +1,39 @@
|
||||
|
||||
import openai
|
||||
import yaml
|
||||
from tools.tools_base import ToolsBase
|
||||
|
||||
|
||||
class LLMTools(ToolsBase):
|
||||
def get_describe(self):
|
||||
return "利用大模型进行回答"
|
||||
def __init__(self):
|
||||
self.name = "llm_tools"
|
||||
self.description = "利用大模型进行回答,入参格式为字典:{role:大模型的角色, content:问题}"
|
||||
|
||||
def run(self, param=None):
|
||||
"""
|
||||
Make a call to the OpenAI chat API.
|
||||
|
||||
Args:
|
||||
param: The input text for the chat API.
|
||||
|
||||
Returns:
|
||||
str: The generated text from the chat API.
|
||||
"""
|
||||
with open("config.yaml", "r") as file:
|
||||
config = yaml.safe_load(file).get("openai")
|
||||
|
||||
openai.api_key = config.get("api_key")
|
||||
openai.base_url = config.get("api_url")
|
||||
messages = []
|
||||
if "role" in param:
|
||||
messages.append({"role": "system", "content": param["role"]})
|
||||
messages.append({"role": "user", "content": param["content"]})
|
||||
|
||||
response = openai.chat.completions.create(
|
||||
model="gpt-3.5-turbo", # GPT-3.5 model
|
||||
messages=messages,
|
||||
temperature=0.2
|
||||
)
|
||||
|
||||
generated_text = response.choices[0].message.content
|
||||
|
||||
return generated_text
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
class ToolsBase:
|
||||
def get_describe(self):
|
||||
return ["内容总结", "感性信息"]
|
||||
def __init__(self):
|
||||
self.name = ""
|
||||
self.description = ""
|
||||
|
||||
def get_info(self):
|
||||
return {"name": self.name, "description": self.description}
|
||||
|
||||
|
||||
def run(self):
|
||||
def run(self, param=None):
|
||||
pass
|
||||
|
||||
@@ -12,10 +12,11 @@ from selenium.webdriver.common.by import By
|
||||
from tools.tools_base import ToolsBase
|
||||
|
||||
class WebBrowser(ToolsBase):
|
||||
def get_describe(self):
|
||||
return ["最新信息", "链接", "具体针对性信息", "专业信息"]
|
||||
def __init__(self):
|
||||
self.name = "web_browser"
|
||||
self.description = "利用浏览器进行搜索,入参格式为字符串"
|
||||
|
||||
def run(self):
|
||||
def run(self, param=None):
|
||||
# Load browser configuration from YAML file
|
||||
with open("config.yaml", "r") as file:
|
||||
config = yaml.safe_load(file)
|
||||
|
||||
Binary file not shown.
@@ -3,7 +3,7 @@ class ObjectComponents:
|
||||
self.content = [
|
||||
{"target": "任务主体", "content": "", "descriptions": "任务主体"},
|
||||
{"target": "执行动作", "content": "", "descriptions": "执行动作"},
|
||||
{"target": "任务背景", "content": "", "descriptions": "任务背景或原因"},
|
||||
{"target": "任务背景", "content": "", "descriptions": "任务背景,为了xx、因为xx"},
|
||||
# "how": {"content": "", "descriptions": "这个任务如何做", "example": ["通过线上直播发布会,合作伙伴渠道和社交媒体宣传", "通过增加人员、改善流程和引入新的服务软件"]},
|
||||
{"target": "任务完成程度", "content": "", "descriptions": "任务要做到什么程度,给出具体的几个要求"}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user