1. 动作优化

1. SummarizeCode动作:用于基于代码进行总结,思考bug、逻辑、todo
  2. CodeReview动作优化:目前强制要求回答问题,有更高的成功率了
    1. 增加了LGTM/LBTM的回答,在LGTM时会及时停止,不重写代码
    2. 目前增加了设置中的参数code_review_k_times,与reflexion类似,设置为2
    3. 仍然有概率发生指令不遵循,尤其是会有比较高的概率发生同时review多个代码文件,还没想好怎么解决 #FIXME
  3. 增加了env到Action结构中,现在可以直接调用环境接口了
  4. WriteDesign:去除了对project_name的纠正代码,现在引导下可以一次生成对
    1. 修改了提示词中的##格式,改为了JSON格式
2. 数据结构
  1. Document的标准化:Env->Repo->Document,其中Document/Asset/Code都是Document
    1. 原用于检索的Document改为IndexableDocument
  2. Repo结构引入:用于Document装载与元数据装载
  3. RepoParser引入:写了一个简单的AST parser(后续可能要换tree-sitter),给出了整库symbol
  4. Env中增加了set/get/set_doc/get_doc接口,用于set/get单个变量或者一个Document。这个逻辑后续或许会进一步简化
3. 配置优化
  1. 默认更换为gpt-4-1106-preview,以获得最好的效果与成本
  2. 提供~/.metagpt作为配置最高优先级目录,从中读取config.yaml
  3. workspace可以灵活指定了,在config中配置
  4. project_name可以由命令行指定,并且改为由ProductManager生成
4. metagpt作为默认命令行,而非python startup.py
metagpt --help

metagpt --project-name game_2048 "make a 2048 game"
metagpt "make a 2048 game"

metagpt --project-name game_2048 --inc "将2048改为4096"

metagpt --project-name game_2048 --auto-inc "make a 2048 game"
  1. 使用新的METAGPT_ROOT生成方式,而非寻找git,以便cli安装
  2. 命令行由fire换为了typer,它会带来相对更好的体验
  3. project_name可以灵活指定了,在metagpt命令行输入中配置
5. 其他
  1. 现在支持多国语言了,中文已测试
  2. BossRequirement -> UserRequirement
  3. 大量错误文本的修正,增加了可读性
  4. 中量提示词优化,稍微提升了一些准确率
  5. 暂时屏蔽了LongtermMemory相关逻辑,这个逻辑底层调用了langchain的FAISS,会带来~5秒加载耗时
  6. 修复了安装包中的部分描述错误
  7. 去除了config中在openai_proxy设定时对base的重复修改,这个修改应该在openai初始化时发生
  8. 修复了JSON在中文存储时的特定问题,ensure_ascii=False
This commit is contained in:
geekan 2023-11-27 15:36:50 +08:00
parent 715a1d874a
commit 22288a342d
24 changed files with 359 additions and 203 deletions

View file

@ -11,7 +11,7 @@ from collections import OrderedDict
from pathlib import Path
from metagpt.actions import WriteCode, WriteCodeReview, WriteDesign, WriteTasks
from metagpt.actions.SummarizeCode import SummarizeCode
from metagpt.actions.summarize_code import SummarizeCode
from metagpt.config import CONFIG
from metagpt.logs import logger
from metagpt.roles import Role
@ -74,8 +74,8 @@ class Engineer(Role):
super().__init__(name, profile, goal, constraints)
self._init_actions([WriteCode])
self.use_code_review = use_code_review
if self.use_code_review:
self._init_actions([WriteCode, WriteCodeReview])
# if self.use_code_review:
# self._init_actions([WriteCode, WriteCodeReview])
self._watch([WriteTasks])
self.todos = []
self.n_borg = n_borg
@ -93,8 +93,8 @@ class Engineer(Role):
@classmethod
def parse_workspace(cls, system_design_msg: Message) -> str:
if system_design_msg.instruct_content:
return system_design_msg.instruct_content.dict().get("Python package name").strip().strip("'").strip('"')
return CodeParser.parse_str(block="Python package name", text=system_design_msg.content)
return system_design_msg.instruct_content.dict().get("project_name").strip().strip("'").strip('"')
return CodeParser.parse_str(block="project_name", text=system_design_msg.content)
def get_workspace(self) -> Path:
msg = self._rc.memory.get_by_action(WriteDesign)[-1]
@ -182,16 +182,16 @@ class Engineer(Role):
msg = self._rc.memory.get_by_actions([WriteDesign, WriteTasks, WriteCode])
for m in msg:
context.append(m.content)
context_str = "\n".join(context)
context_str = "\n----------\n".join(context)
# Write code
code = await WriteCode().run(context=context_str, filename=todo)
# Code review
if self.use_code_review:
try:
rewrite_code = await WriteCodeReview().run(context=context_str, code=code, filename=todo)
code = rewrite_code
except Exception as e:
logger.error("code review failed!", e)
# try:
rewrite_code = await WriteCodeReview().run(context=context_str, code=code, filename=todo)
code = rewrite_code
# except Exception as e:
# logger.error("code review failed!", e)
file_path = self.write_file(todo, code)
msg = Message(content=code, role=self.profile, cause_by=WriteCode)
self._rc.memory.add(msg)
@ -203,8 +203,8 @@ class Engineer(Role):
msg = self._rc.memory.get_by_actions([WriteDesign, WriteTasks, WriteCode])
for m in msg:
context.append(m.content)
context_str = "\n".join(context)
code_review_all = await SummarizeCode().run(context=context_str)
context_str = "\n----------\n".join(context)
summary = await SummarizeCode().run(context=context_str)
logger.info(f"Done {self.get_workspace()} generating.")
msg = Message(

View file

@ -45,8 +45,8 @@ class QaEngineer(Role):
@classmethod
def parse_workspace(cls, system_design_msg: Message) -> str:
if system_design_msg.instruct_content:
return system_design_msg.instruct_content.dict().get("Python package name")
return CodeParser.parse_str(block="Python package name", text=system_design_msg.content)
return system_design_msg.instruct_content.dict().get("project_name")
return CodeParser.parse_str(block="project_name", text=system_design_msg.content)
def get_workspace(self, return_proj_dir=True) -> Path:
msg = self._rc.memory.get_by_action(WriteDesign)[-1]

View file

@ -50,6 +50,7 @@ ROLE_TEMPLATE = """Your response should be based on the previous conversation hi
{name}: {result}
"""
class RoleReactMode(str, Enum):
REACT = "react"
BY_ORDER = "by_order"
@ -59,6 +60,7 @@ class RoleReactMode(str, Enum):
def values(cls):
return [item.value for item in cls]
class RoleSetting(BaseModel):
"""Role Settings"""
name: str
@ -131,6 +133,7 @@ class Role:
logger.warning(f"is_human attribute does not take effect,"
f"as Role's {str(action)} was initialized using LLM, try passing in Action classes instead of initialized instances")
i = action
i.set_env(self._rc.env)
i.set_prefix(self._get_prefix(), self.profile)
self._actions.append(i)
self._states.append(f"{idx}. {action}")
@ -172,6 +175,18 @@ class Role:
"""Set the environment in which the role works. The role can talk to the environment and can also receive messages by observing."""
self._rc.env = env
def set_doc(self, content: str, filename: str):
return self._rc.env.set_doc(content, filename)
def get_doc(self, filename: str):
return self._rc.env.get_doc(filename)
def set(self, k, v):
return self._rc.env.set(k, v)
def get(self, k):
return self._rc.env.get(k)
@property
def profile(self):
"""Get the role description (position)"""