MetaGPT
MetaGPT copied to clipboard
writen-report
User description
Features
- Combine the open source large language model and the Metagpt framework to achieve intelligent writing. In order to verify the feasibility of the technical route, "accident reports" are used as the experimental subjects, and will be expanded to paper writing or project bidding (document level) writing.(将开源大语言模型和 Metagpt框架相互结合,实现智能写作工作。为验证技术路线的可行性,以“事故报告”做实验对象,后续将拓展到论文写作,或者项目招投标(文档级)写作上)
Feature Docs
- This function is document-level writing, which imitates human writing thinking. You write a first draft first, and then submit it to the teacher for evaluation and feedback. Later, based on the feedback, the first draft was revised and improved. (该功能是文档级别写作,模仿人类的写作思维,先写出初稿,后交给老师评估,得到反馈意见。后根据反馈意见,进行对初稿修订改进)
Influence
- Liberate the writing ability of public officials. (解放公职人员写作能力) -Implement generation of long document levels(实现长文档级别的生成) Result
Generate papers, bidding documents, official documents, reports, etc.(生成论文,招投标文件,公文,报告等) 例如: 输入: “5.18”金达花园三期项目坍塌事故调查报告.json
输出: (https://github.com/geekan/MetaGPT/files/15218678/5.18._metagpt.txt)
Other
Type
enhancement
Description
- Introduced a comprehensive system for generating, evaluating, and refining accident reports using the MetaGPT framework.
- Developed a new
RewriteReport
class with methods for planning, executing tasks, and handling tools for intelligent report creation. - Added test scripts and actions for evaluating and refining the generated reports.
- Updated model configuration to "qwen-14B-Chat" for enhanced performance.
- Provided detailed guidance and structured task planning for different sections of an accident report.
Changes walkthrough
Relevant files | |||||||
---|---|---|---|---|---|---|---|
Enhancement |
| ||||||
Tests |
| ||||||
Configuration changes |
| ||||||
Documentation |
|
✨ PR-Agent usage: Comment
/help
on the PR to get a list of all available PR-Agent tools and their descriptions
PR Description updated to latest commit (https://github.com/geekan/MetaGPT/commit/81ab4a974f3ee430c72bd1f8fc637a8f6432ab29)
- [ ] Copy walkthrough table to "Files Changed" Tab
PR Review
(Review updated until commit https://github.com/geekan/MetaGPT/commit/ad8eeb7460e60392d381a1171900c347eaf8a8c8)
⏱️ Estimated effort to review [1-5] |
4, because the PR introduces a complex system involving multiple components such as planning, executing, evaluating, and refining tasks within the MetaGPT framework. The code is extensive and integrates various functionalities, which requires a thorough understanding of the system's architecture and the interactions between components. |
🧪 Relevant tests |
Yes |
🔍 Possible issues |
Possible Bug: The method |
Performance Concern: The | |
🔒 Security concerns |
No |
✨ Review tool usage guide:
Overview:
The review
tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.
The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
- When commenting, to edit configurations related to the review tool (
pr_reviewer
section), use the following template:
/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
- With a configuration file, use the following template:
[pr_reviewer]
some_config1=...
some_config2=...
See the review usage page for a comprehensive guide on using this tool.
PR Code Suggestions
Category | Suggestions | |||||||||||||
Enhancement |
Convert the prompt text into a structured JSON format for better manageability and processing.Consider using a more structured data format like JSON or YAML for the prompts and user_develop/prompt/write_report_paragraph.py [2-7]
| Simplify the conversion of
| ||||||||||||
Performance |
Optimize string concatenation by using
| |||||||||||||
Use asynchronous file operations to prevent blocking in async functions.Replace the synchronous file reading and JSON operations with asynchronous equivalents to user_develop/plan/report_planner.py [50-51]
| ||||||||||||||
Best practice |
Use a context manager for file operations to ensure proper resource management.Use a context manager when opening files to ensure that the file is properly closed after user_develop/core_report.py [126-127]
| Improve file path handling for cross-platform compatibility.Replace the direct file path concatenation with user_develop/plan/report_planner.py [50]
| Ensure files are properly closed after operations.Use a context manager when opening files to ensure that the file is properly closed after user_develop/plan/report_planner.py [51]
Maintainability |
| Refactor the message type handling using a dictionary mapping to improve scalability and manageability.Instead of using multiple if-else conditions to handle different types of messages, user_develop/core_report.py [145-153]
| Refactor method to improve readability and separation of concerns.Refactor the loop in user_develop/plan/report_planner.py [59-75]
Error handling |
| Add error handling for file operations to enhance robustness.Handle potential exceptions that may occur during file operations to prevent the program user_develop/plan/report_planner.py [50-51]
|
✨ Improve tool usage guide:
Overview:
The improve
tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
- When commenting, to edit configurations related to the improve tool (
pr_code_suggestions
section), use the following template:
/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
- With a configuration file, use the following template:
[pr_code_suggestions]
some_config1=...
some_config2=...
See the improve usage page for a comprehensive guide on using this tool.
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 70.19%. Comparing base (
f201b2f
) to head (c4f6370
). Report is 110 commits behind head on main.
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@ Coverage Diff @@
## main #1235 +/- ##
==========================================
- Coverage 70.22% 70.19% -0.04%
==========================================
Files 316 316
Lines 18860 18860
==========================================
- Hits 13245 13239 -6
- Misses 5615 5621 +6
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
按照返回意见,重新修改代码,清晰。对 原 Metagpt 结构 未作任何改变, 复用源基层代码, 模仿datainterpreter 类进行改造,实现与源代码 高耦合。
Great! Let's review
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.
PR Description updated to latest commit (https://github.com/geekan/MetaGPT/commit/ad8eeb7460e60392d381a1171900c347eaf8a8c8)
- [ ] Copy walkthrough table to "Files Changed" Tab
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.
Persistent review updated to latest commit https://github.com/geekan/MetaGPT/commit/ad8eeb7460e60392d381a1171900c347eaf8a8c8
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.
PR Description updated to latest commit (https://github.com/geekan/MetaGPT/commit/ad8eeb7460e60392d381a1171900c347eaf8a8c8)
- [ ] Copy walkthrough table to "Files Changed" Tab
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.
Persistent review updated to latest commit https://github.com/geekan/MetaGPT/commit/ad8eeb7460e60392d381a1171900c347eaf8a8c8
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.
PR Code Suggestions
Category | Suggestions | ||||||||
Bug |
Initialize
| ||||||||
Enhancement |
Provide a meaningful default value for
| ||||||||
Handle the result of the superclass
| |||||||||
Possible issue |
Add a break condition to prevent potential infinite loops in retry logic.The method tests/write_roport/core_report.py [91]
| Add a check to ensure
| |||||||
Maintainability |
Improve YAML file consistency by using uniform indentation.Consider using consistent indentation for YAML files to avoid parsing errors. The tests/data/report_writer/domain.yaml [2-10]
| ||||||||
Best practice |
Replace special formatting in guidance text with standard YAML comments or fields.Ensure that the guidance text does not contain unnecessary special characters or tests/data/report_writer/domain.yaml [7-9]
|
✨ Improve tool usage guide:
Overview:
The improve
tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
- When commenting, to edit configurations related to the improve tool (
pr_code_suggestions
section), use the following template:
/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
- With a configuration file, use the following template:
[pr_code_suggestions]
some_config1=...
some_config2=...
See the improve usage page for a comprehensive guide on using this tool.
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.
PR Code Suggestions
Category | Suggestions | ||||
Enhancement |
Improve the method signature by removing the default value for
| ||||
Performance |
Add a break statement to exit the loop early once a successful evaluation is achieved.The tests/write_roport/core_report.py [91-97]
| ||||
Possible issue |
Add checks to ensure
| ||||
Add a check to ensure
| |||||
Add a check to ensure
| |||||
Maintainability |
Standardize YAML indentation for better readability and to avoid parsing issues.Consider using a consistent indentation style for YAML files to improve readability and tests/data/report_writer/domain.yaml [2-10]
|
✨ Improve tool usage guide:
Overview:
The improve
tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
- When commenting, to edit configurations related to the improve tool (
pr_code_suggestions
section), use the following template:
/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
- With a configuration file, use the following template:
[pr_code_suggestions]
some_config1=...
some_config2=...
See the improve usage page for a comprehensive guide on using this tool.
I developed an official document writing artifact, which can be expanded to the fields of paper writing, official document generation, bidding documents and other fields according to user needs. In the future, tools such as networking and literature retrieval will continue to be integrated. The code repository is at: METAGPT\tests\metagpt\ext\write_report\report.py (我开发一款公文写作神器, 根据用户的需求可以拓展到论文写作,公文生成,招投标文档等领域。后续会继续集成 联网,文献检索等工具。代码仓库在: METAGPT\tests\metagpt\ext\write_report\report.py)
@wangwenju269 哈喽,有一些问题先请问下
- 为什么代码是写在tests目录下?
- 我看大部分的提示词都是中文,是必须使用中文提示词,还是什么原因呢?
您好:
答复如下
问题1 : 放在 test 路径下的目的:自己开发的项目代码脚本 和 源metagpt框架 能更好解耦,本项目是复用 metagpt 现有的类和方法,代码做到高内聚,低耦合。
问题2: 提示词是可以拓展的,已将提示词单独放在一个文件里。后续更换提示词文件,实现实现招投标、论文写作等应用场景。 提示词是可插拔替换的,根据具体业务场景,更换提示词
祝好!
在 2024-05-17 11:06:18,"shenchucheng" @.***> 写道:
@wangwenju269 哈喽,有一些问题先请问下
为什么代码是写在tests目录下? 我看大部分的提示词都是中文,是必须使用中文提示词,还是什么原因呢?
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
有修改意见,请及时反馈给我,谢谢
您好: 答复如下 问题1 : 放在 test 路径下的目的:自己开发的项目代码脚本 和 源metagpt框架 能更好解耦,本项目是复用 metagpt 现有的类和方法,代码做到高内聚,低耦合。 问题2: 提示词是可以拓展的,已将提示词单独放在一个文件里。后续更换提示词文件,实现实现招投标、论文写作等应用场景。 提示词是可插拔替换的,根据具体业务场景,更换提示词 祝好! 在 2024-05-17 11:06:18,"shenchucheng" @.> 写道: @wangwenju269 哈喽,有一些问题先请问下 为什么代码是写在tests目录下? 我看大部分的提示词都是中文,是必须使用中文提示词,还是什么原因呢? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.>
metagpt下有ext文件夹(external, extension之意),可将代码放入metagpt/ext下,参考stanford_town的放置方法,可与metagpt核心代码相分开
好的,收到,我尽快修改
---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年05月17日 17:32 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [geekan/MetaGPT] writen-report (PR #1235) |
@garylin2099 commented on this pull request.
代码虽然继承了MG内DataInterpreter, WritePlan, Planner等类,但仍不免需要改写大量函数,子类函数与父类函数有较多重复。这并非此PR的问题,是原来DI及DI相关类未留出足够的可配置项。若从此PR出发,可以再仔细考虑,哪些地方是可以直接使用原DI代码,哪些是必须要自定义,尽量减少些重复
In tests/metagpt/ext/write_report/core_report.py:
+from pydantic import Field, model_validator + +from metagpt.logs import logger +from metagpt.roles import Role +from metagpt.schema import Message, Task, TaskResult +from metagpt.tools.tool_recommend import BM25ToolRecommender, ToolRecommender +from tests.metagpt.ext.write_report.write_evaluator_refine import (
- EvaluatorReport,
- RefineReport,
- WriteAnalysisReport, +) +from tests.metagpt.ext.write_report.write_report_planner import WritePlanner
+class RewriteReport(Role):
应为ReportRewriter,RewriteReport是动作的意思
In config/config2.yaml:
\ No newline at end of file
- model: "qwen-14B-Chat" # or gpt-3.5-turbo
这个改动不应该提交
In tests/metagpt/ext/write_report/report.py:
+# -- coding: utf-8 -- +""" @.*** : 2024/5/06 13:54 @.*** : wangwenju269 @.*** : report.py +"""
+import fire + +from tests.metagpt.ext.write_report.core_report import RewriteReport + + +async def main(auto_run: bool = True):
- requirement = "写一份事故报告"
- di = RewriteReport(auto_run=auto_run, human_design_sop=True, use_evaluator=True)
- await di.run(f"{requirement}", upload_file="E:\workspace\MetaGPT\data\“5.18”金达花园三期项目坍塌事故调查报告.json")
建议去掉具体的路径名和文件名
In tests/metagpt/ext/write_report/write_evaluator_refine.py:
"reason": str = "评分的依据和解释",
-
"critique": str = "提供针对生成文本的具体改进建议"
-
}},
-
...
- ]
-
+"""
+
+REFINE = """请根据 user
的具体任务要求(Plan Status)以及以下的反馈建议,对 assistant
之前的回应进行深入审查,并在需要的地方进行适当的改进。
+用户反馈建议:{suggestion}
+
+在修订时,请保持与 assistant
原始回应的格式和风格一致,并确保输出的内容充分体现了用户的具体任务要求。
+"""
+
+
+def process_message(messages: Union[str, Message, list[dict], list[Message], list[str]]) -> list[dict]:
可使用llm.format_msg,见具体provider文件
In tests/metagpt/ext/write_report/write_evaluator_refine.py:
@@ -0,0 +1,170 @@ +import json +from typing import Union
+from metagpt.actions import Action +from metagpt.schema import Message +from metagpt.utils.common import CodeParser + +STRUCTUAL_PROMPT = """
可跟write_analysis_code.py保持一致,将prompt放入单独文件
In tests/metagpt/ext/write_report/write_report_planner.py:
self.PROMPT_TEMPLATE = f"{self.PROMPT_TEMPLATE}\n\n{self.CONSTRAINTS}"
-
task_type_desc = "\n".join([f"- **{v['name']}**: {v['desc']}" for k, v in usertasktype.items()])
-
prompt = self.PROMPT_TEMPLATE.format(
-
context="\n".join([str(ct) for ct in context]), max_tasks=max_tasks, task_type_desc=task_type_desc
-
)
-
rsp = await self._aask(prompt)
-
rsp = CodeParser.parse_code(block=None, text=rsp)
可改写PROMPT_TEMPLATE,这段使用super().run
In tests/metagpt/ext/write_report/write_report_planner.py:
rsp = await WriteReportPlan().run(context, max_tasks, self.human_design_sop)
-
self.working_memory.add(Message(content=rsp, role="assistant", cause_by=WritePlan))
-
# precheck plan before asking reviews
-
is_plan_valid, error = precheck_update_plan_from_rsp(rsp, self.plan)
-
if not is_plan_valid and max_retries > 0:
-
error_msg = f"The generated plan is not valid with error: {error}, try regenerating, remember to generate either the whole plan or the single changed task only"
-
logger.warning(error_msg)
-
self.working_memory.add(Message(content=error_msg, role="assistant", cause_by=WritePlan))
-
max_retries -= 1
-
continue
-
_, plan_confirmed = await self.ask_review(trigger=ReviewConst.TASK_REVIEW_TRIGGER)
-
update_plan_from_rsp(rsp=rsp, current_plan=self.plan)
-
# working_memory
-
self.working_memory.clear()
- def get_plan_status(self) -> str:
这个函数是否需要改写?PLAN_STATUS待填入的变量名可以和原PLAN_STATUS保持一致
In tests/metagpt/ext/write_report/write_report_planner.py:
- async def run(self, context: list[Message], max_tasks: int = 7, human_design_sop=True) -> str:
-
if not human_design_sop:
-
self.PROMPT_TEMPLATE = f"{self.PROMPT_TEMPLATE}\n\n{self.CONSTRAINTS}"
-
task_type_desc = "\n".join([f"- **{v['name']}**: {v['desc']}" for k, v in usertasktype.items()])
-
prompt = self.PROMPT_TEMPLATE.format(
-
context="\n".join([str(ct) for ct in context]), max_tasks=max_tasks, task_type_desc=task_type_desc
-
)
-
rsp = await self._aask(prompt)
-
rsp = CodeParser.parse_code(block=None, text=rsp)
-
else:
-
with open(TEST_DATA_PATH / "report_writer/sop.json", "r", encoding="utf-8") as file:
-
rsp = json.dumps(json.loads(file.read()), ensure_ascii=False) # 读取人类设计 `sop` 流程
-
return rsp
+class WritePlanner(Planner):
WriteReportPlanner
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
答复:文件放置在 test 目录下,方便更好测试代码是否独立执行成功。 我已遵循评审大佬的要求和反馈建议,做出相应修改,清再次查收。 祝好!
tests
答复:文件放置在 test 目录下,方便更好测试代码是否独立执行成功。 我已遵循评审大佬的要求和反馈建议,做出相应修改,清再次查收。 祝好!
tests目录是单测目录,tests/metagpt/ext/是metagpt/ext下的代码对应的单测文件