New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
writen-report #1235
base: main
Are you sure you want to change the base?
writen-report #1235
Conversation
PR Description updated to latest commit (81ab4a9)
|
PR Review(Review updated until commit ad8eeb7)
✨ Review tool usage guide:Overview: The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
See the review usage page for a comprehensive guide on using this tool. |
PR Code Suggestions
✨ Improve tool usage guide:Overview:
See the improve usage page for a comprehensive guide on using this tool. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ 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 ☔ View full report in Codecov by Sentry. |
按照返回意见,重新修改代码,清晰。对 原 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 (ad8eeb7)
|
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 ad8eeb7 |
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 (ad8eeb7)
|
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 ad8eeb7 |
PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here. PR Code Suggestions
✨ Improve tool usage guide:Overview:
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
✨ Improve tool usage guide:Overview:
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 |
@wangwenju269 哈喽,有一些问题先请问下
|
您好:
答复如下
问题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核心代码相分开 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码虽然继承了MG内DataInterpreter, WritePlan, Planner等类,但仍不免需要改写大量函数,子类函数与父类函数有较多重复。这并非此PR的问题,是原来DI及DI相关类未留出足够的可配置项。若从此PR出发,可以再仔细考虑,哪些地方是可以直接使用原DI代码,哪些是必须要自定义,尽量减少些重复
from tests.metagpt.ext.write_report.write_report_planner import WritePlanner | ||
|
||
|
||
class RewriteReport(Role): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应为ReportRewriter,RewriteReport是动作的意思
config/config2.yaml
Outdated
model: "qwen-14B-Chat" # or gpt-3.5-turbo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个改动不应该提交
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只是为了接开源模型测试代码是否通过
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议去掉具体的路径名和文件名
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
""" | ||
|
||
|
||
def process_message(messages: Union[str, Message, list[dict], list[Message], list[str]]) -> list[dict]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可使用llm.format_msg,见具体provider文件
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
METAgpt 版本代码 更新速度有点快,二次开发不一定能跟上。
from metagpt.schema import Message | ||
from metagpt.utils.common import CodeParser | ||
|
||
STRUCTUAL_PROMPT = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可跟write_analysis_code.py保持一致,将prompt放入单独文件
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这只是提示词应用模板,且是通用的,没必要存在单独文件里。
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可改写PROMPT_TEMPLATE,这段使用super().run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不大认可,super().run函数里有TaskType这个枚举类型。在不改变源代码接触上,我之前考虑重新设置UserTaskType,但还需要外层封装一下,因此将 UserTaskType 里的内容卸载外部 yaml 文件里。
# working_memory | ||
self.working_memory.clear() | ||
|
||
def get_plan_status(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数是否需要改写?PLAN_STATUS待填入的变量名可以和原PLAN_STATUS保持一致
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,之前我想复用来着,后来取消 TaskType 这个类的使用,就不能直接访问其中的方法了,就简单重写了
return rsp | ||
|
||
|
||
class WritePlanner(Planner): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WriteReportPlanner
好的,收到,我尽快修改
---- 回复的原邮件 ----
| 发件人 | ***@***.***> |
| 日期 | 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 目录下,方便更好测试代码是否独立执行成功。 |
User description
Features
Feature Docs
(该功能是文档级别写作,模仿人类的写作思维,先写出初稿,后交给老师评估,得到反馈意见。后根据反馈意见,进行对初稿修订改进)
Influence
-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
RewriteReport
class with methods for planning, executing tasks, and handling tools for intelligent report creation.Changes walkthrough
core_report.py
Implement RewriteReport Class for Accident Report Generation
tests/write_roport/core_report.py
RewriteReport
to handle the process of writing,evaluating, and refining accident reports.
recommendations.
based on feedback.
creation.
write_evaluator_refine.py
Define Actions for Report Writing, Evaluation, and Refinement
tests/write_roport/write_evaluator_refine.py
reports.
refining text.
write_report_planner.py
Implement Planner for Structured Report Writing Tasks
tests/write_roport/write_report_planner.py
requirements and SOP.
test_write_report.py
Test Script for RewriteReport Functionality
tests/write_roport/test_write_report.py
RewriteReport
classwith specified parameters.
config2.yaml
Update Model Configuration in YAML
config/config2.yaml
sop.json
Structured Order of Tasks for Report Writing in JSON
tests/data/report_writer/sop.json
based on user-provided information.
domain.yaml
Define Domain-Specific Guidance for Report Writing
tests/data/report_writer/domain.yaml
of an accident report.