Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

writen-report #1235

wants to merge 7 commits into from

Conversation

wangwenju269
Copy link

@wangwenju269 wangwenju269 commented Apr 29, 2024

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
core_report.py
Implement RewriteReport Class for Accident Report Generation

tests/write_roport/core_report.py

  • Introduced a new class RewriteReport to handle the process of writing,
    evaluating, and refining accident reports.
  • Implemented methods for planning, acting on tasks, and handling tool
    recommendations.
  • Added functionality to write initial drafts, evaluate them, and refine
    based on feedback.
  • Integrated with the MetaGPT framework for intelligent document
    creation.
  • +151/-0 
    write_evaluator_refine.py
    Define Actions for Report Writing, Evaluation, and Refinement

    tests/write_roport/write_evaluator_refine.py

  • Defined actions for writing analysis, evaluation, and refinement of
    reports.
  • Utilized structured prompts and evaluation criteria for generating and
    refining text.
  • +110/-0 
    write_report_planner.py
    Implement Planner for Structured Report Writing Tasks       

    tests/write_roport/write_report_planner.py

  • Implemented a planner for report writing tasks based on user
    requirements and SOP.
  • Added functionality to update and manage plans for report writing.
  • +102/-0 
    Tests
    test_write_report.py
    Test Script for RewriteReport Functionality                           

    tests/write_roport/test_write_report.py

  • Created a test script to instantiate and run the RewriteReport class
    with specified parameters.
  • +13/-0   
    Configuration changes
    config2.yaml
    Update Model Configuration in YAML                                             

    config/config2.yaml

  • Updated the model configuration from "gpt-4-turbo" to "qwen-14B-Chat".

  • +1/-1     
    sop.json
    Structured Order of Tasks for Report Writing in JSON         

    tests/data/report_writer/sop.json

  • Defined a structured order of tasks for writing an accident report
    based on user-provided information.
  • +38/-0   
    Documentation
    domain.yaml
    Define Domain-Specific Guidance for Report Writing             

    tests/data/report_writer/domain.yaml

  • Added detailed descriptions and guidance for writing various sections
    of an accident report.
  • +98/-0   

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    PR Description updated to latest commit (81ab4a9)

    Copy link

    codiumai-pr-agent-pro bot commented Apr 29, 2024

    PR Review

    (Review updated until commit ad8eeb7)

    ⏱️ 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 _check_data in RewriteReport might not handle cases where the custom key is not present in working_memory.index, potentially leading to unhandled exceptions or logical errors.

    Performance Concern: The run method in RewriteReport and other asynchronous methods might face performance issues due to multiple await calls and complex logic, especially when handling large data or multiple requests concurrently.

    🔒 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=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    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
    templates. This would make it easier to manage and modify the content, as well as
    potentially simplify the code that processes these templates.

    user_develop/prompt/write_report_paragraph.py [2-7]

    -FIRST_PROMPT = """
    -请根据以下关键信息撰写一个合理的事故报告开头的第一自然段,主要介绍事故概要。在段落的结尾处,加入一段官方声明,声明应体现事故调查的严谨性和全面性。
    -*** 注意事项 ***
    -    1. 在段落的结尾,请务必补充一段官方声明。eg:<事故调查组按照“实事求是、客观公正、尊重科学”的原则,...,  ... ,现将有关情况报告如下>
    -    2. 事件描述 简短扼要。
    -请确保您的文本不仅简要记录了事故概要,而且语言表达准确、连贯,体现出调查报告的权威性和专业性。字数要求 300 - 500 之间。
    -"""
    +FIRST_PROMPT = {
    +  "description": "请根据以下关键信息撰写一个合理的事故报告开头的第一自然段,主要介绍事故概要。",
    +  "requirements": [
    +    "在段落的结尾,请务必补充一段官方声明。eg:<事故调查组按照“实事求是、客观公正、尊重科学”的原则,...,  ... ,现将有关情况报告如下>",
    +    "事件描述 简短扼要。"
    +  ],
    +  "note": "请确保您的文本不仅简要记录了事故概要,而且语言表达准确、连贯,体现出调查报告的权威性和专业性。字数要求 300 - 500 之间。"
    +}
     
    Simplify the conversion of messages to a list using Python's built-in list() function.

    Instead of manually checking and converting the type of messages into a list, use Python's
    built-in list() function which can handle various iterable types and simplifies the code.

    user_develop/core_report.py [139-140]

    -if not isinstance(messages, list):
    -    messages = [messages]
    +messages = list(messages) if not isinstance(messages, list) else messages
     
    Performance
    Optimize string concatenation by using str.join() directly with a generator expression.

    Replace the repeated string concatenation with a more efficient method such as using
    str.join() which is generally faster and more readable when concatenating multiple
    strings.

    user_develop/action/evaluator_report.py [79-82]

    -info = (
    -    "\n".join([str(ct) for ct in working_memory if str(ct).startswith("user")])
    -    if working_memory
    -    else ""
    -)
    +info = "\n".join(str(ct) for ct in working_memory if str(ct).startswith("user")) if working_memory else ""
     
    Use asynchronous file operations to prevent blocking in async functions.

    Replace the synchronous file reading and JSON operations with asynchronous equivalents to
    avoid blocking the event loop in an async function.

    user_develop/plan/report_planner.py [50-51]

    -with open(DATA_PATH / "sop.json", "r", encoding="utf-8") as file:
    -    rsp = json.dumps(json.loads(file.read()), ensure_ascii=False)
    +import aiofiles
    +import orjson
    +async with aiofiles.open(DATA_PATH / "sop.json", "r", encoding="utf-8") as file:
    +    data = await file.read()
    +    rsp = orjson.dumps(orjson.loads(data), ensure_ascii=False).decode()
     
    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
    its suite finishes, even if an exception is raised.

    user_develop/core_report.py [126-127]

     with open(file_path, "r", encoding="utf-8") as file:
    -    data_info = json.loads(file.read())
    +    data_info = json.load(file)
     
    Improve file path handling for cross-platform compatibility.

    Replace the direct file path concatenation with os.path.join for better compatibility
    across different operating systems.

    user_develop/plan/report_planner.py [50]

    -with open(DATA_PATH / "sop.json", "r", encoding="utf-8") as file:
    +with open(os.path.join(DATA_PATH, "sop.json"), "r", encoding="utf-8") as file:
     
    Ensure files are properly closed after operations.

    Use a context manager when opening files to ensure that the file is properly closed after
    its suite finishes.

    user_develop/plan/report_planner.py [51]

    -rsp = json.dumps(json.loads(file.read()), ensure_ascii=False)
    +with open(DATA_PATH / "sop.json", "r", encoding="utf-8") as file:
    +    rsp = json.dumps(json.loads(file.read()), ensure_ascii=False)
     
    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,
    consider using a dictionary mapping to streamline the type handling and make the code more
    scalable and easier to manage.

    user_develop/core_report.py [145-153]

    -if isinstance(msg, str):
    -    processed_messages.append({"role": "user", "content": msg})
    -elif isinstance(msg, dict):
    -    assert set(msg.keys()) == set(["role", "content"])
    -    processed_messages.append(msg)
    -elif isinstance(msg, Message):
    -    processed_messages.append(msg.to_dict())
    -else:
    -    raise ValueError(
    -        f"Only support message type are: str, Message, dict, but got {type(messages).__name__}!"
    -    )
    +message_type_handlers = {
    +    str: lambda m: {"role": "user", "content": m},
    +    dict: lambda m: m,
    +    Message: lambda m: m.to_dict()
    +}
    +try:
    +    processed_messages.append(message_type_handlers[type(msg)](msg))
    +except KeyError:
    +    raise ValueError(f"Unsupported message type: {type(msg).__name__}")
     
    Refactor method to improve readability and separation of concerns.

    Refactor the loop in update_plan to separate concerns and improve readability by
    extracting methods.

    user_develop/plan/report_planner.py [59-75]

     while not plan_confirmed:
         context = self.get_useful_memories()
         rsp = await WriteReportPlan().run(context, max_tasks, self.human_design_sop)
    +    if not self.process_response(rsp):
    +        continue
    +    _, plan_confirmed = await self.ask_review(trigger=ReviewConst.TASK_REVIEW_TRIGGER)
    +
    +def process_response(self, rsp):
         self.working_memory.add(Message(content=rsp, role="assistant", cause_by=WritePlan))
         is_plan_valid, error = precheck_update_plan_from_rsp(rsp, self.plan)
    -    if not is_plan_valid and max_retries > 0:
    +    if not is_plan_valid and self.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)
    +        self.max_retries -= 1
    +        return False
    +    return True
     
    Error handling
    Add error handling for file operations to enhance robustness.

    Handle potential exceptions that may occur during file operations to prevent the program
    from crashing.

    user_develop/plan/report_planner.py [50-51]

    -with open(DATA_PATH / "sop.json", "r", encoding="utf-8") as file:
    -    rsp = json.dumps(json.loads(file.read()), ensure_ascii=False)
    +try:
    +    with open(DATA_PATH / "sop.json", "r", encoding="utf-8") as file:
    +        rsp = json.dumps(json.loads(file.read()), ensure_ascii=False)
    +except IOError as e:
    +    logger.error(f"Failed to read file: {e}")
    +    return ""
     

    ✨ 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=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @codecov-commenter
    Copy link

    codecov-commenter commented Apr 29, 2024

    Codecov Report

    All modified and coverable lines are covered by tests ✅

    Project coverage is 70.19%. Comparing base (f201b2f) to head (c4f6370).
    Report is 110 commits behind head on main.

    ❗ 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.
    📢 Have feedback on the report? Share it here.

    @wangwenju269
    Copy link
    Author

    按照返回意见,重新修改代码,清晰。对 原 Metagpt 结构 未作任何改变, 复用源基层代码, 模仿datainterpreter 类进行改造,实现与源代码 高耦合。

    @geekan
    Copy link
    Owner

    geekan commented Apr 30, 2024

    Great! Let's review

    Copy link

    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)

    Copy link

    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

    Copy link

    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)

    Copy link

    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

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Bug
    Initialize tool_recommender with a default instance to prevent potential AttributeError.

    The tool_recommender attribute is initialized to None and later conditionally assigned to
    BM25ToolRecommender based on the tools attribute. This could lead to a scenario where
    tool_recommender remains None and is used before assignment, causing an AttributeError. To
    avoid this, initialize tool_recommender with a default instance of ToolRecommender.

    tests/write_roport/core_report.py [29]

    -tool_recommender: ToolRecommender = None
    +tool_recommender: ToolRecommender = ToolRecommender()
     
    Enhancement
    Provide a meaningful default value for upload_file to prevent file path errors.

    The upload_file attribute is used to determine the file path for reading and writing
    operations but is initialized as an empty string, which could lead to errors if not
    properly set before use. Ensure that upload_file is validated or has a meaningful default
    value that points to a valid file path.

    tests/write_roport/core_report.py [34]

    -upload_file: str = ""
    +upload_file: str = "/default/path/to/file.txt"  # Update this path as necessary
     
    Handle the result of the superclass run method to ensure proper flow and data handling.

    The run method in RewriteReport class uses await super().run(with_message) without
    returning its result. If the superclass run method returns a value that should be used or
    checked, ensure to handle or return it appropriately.

    tests/write_roport/core_report.py [60]

    -await super().run(with_message)
    +result = await super().run(with_message)
    +return result  # Ensure to handle or return the result appropriately
     
    Possible issue
    Add a break condition to prevent potential infinite loops in retry logic.

    The method _ready_write_report uses a while loop for retries which could potentially lead
    to an infinite loop if success is never set to True. Implement a maximum retry limit to
    prevent infinite loops.

    tests/write_roport/core_report.py [91]

     while not success and counter < max_retry:
    +    if counter == max_retry - 1:
    +        break  # Prevent infinite loop by breaking out after max retries
     
    Add a check to ensure working_memory.index exists to prevent AttributeError.

    The method _check_data checks if "custom" is in working_memory.index but does not handle
    the case where working_memory.index might not exist or be accessible, which could raise an
    AttributeError. Ensure that working_memory.index is initialized and accessible before
    checking its contents.

    tests/write_roport/core_report.py [147]

    -if "custom" not in self.working_memory.index:
    +if hasattr(self.working_memory, 'index') and "custom" not in self.working_memory.index:
     
    Maintainability
    Improve YAML file consistency by using uniform indentation.

    Consider using consistent indentation for YAML files to avoid parsing errors. The
    indentation for the name, desc, and guidance fields under first_paragraph is inconsistent
    with the rest of the document.

    tests/data/report_writer/domain.yaml [2-10]

     first_paragraph:
    -     name: first_paragraph
    -     desc: 请帮我依据用户所提供事故要点信息进行简要扩写, 完整事故报告的第一自然段。
    -     guidance: |
    -          请根据以下关键信息撰写一个合理的事故报告开头的第一自然段,主要介绍事故概要。在段落的结尾处,加入一段官方声明,声明应体现事故调查的严谨性和全面性。
    +  name: first_paragraph
    +  desc: 请帮我依据用户所提供事故要点信息进行简要扩写, 完整事故报告的第一自然段。
    +  guidance: |
    +    请根据以下关键信息撰写一个合理的事故报告开头的第一自然段,主要介绍事故概要。在段落的结尾处,加入一段官方声明,声明应体现事故调查的严谨性和全面性。
     
    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
    formatting issues that might confuse the users or parsers. The use of
    * 注意事项 * could
    be replaced with a more standard YAML comment or a separate field if needed.

    tests/data/report_writer/domain.yaml [7-9]

     guidance: |
    -     *** 注意事项 ***
    -     1. 在段落的结尾,请务必补充一段官方声明。eg:<事故调查组按照“实事求是、客观公正、尊重科学”的原则,...,  ... ,现将有关情况报告如下>
    +  # 注意事项
    +  - 在段落的结尾,请务必补充一段官方声明。例如: "事故调查组按照“实事求是、客观公正、尊重科学”的原则,...,  ... ,现将有关情况报告如下"
     

    ✨ 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=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Enhancement
    Improve the method signature by removing the default value for upload_file to prevent potential misuse.

    The RewriteReport class has a method run that uses the upload_file parameter to set the
    instance variable self.upload_file. However, this parameter is also provided as a default
    argument in the method signature, which can lead to confusion and potential bugs if the
    method is called without specifying the upload_file parameter. To improve clarity and
    avoid potential issues, remove the default value from the method signature and handle the
    case where upload_file is not provided within the method.

    tests/write_roport/core_report.py [58-59]

    -async def run(self, with_message=None, upload_file="") -> Message | None:
    +async def run(self, with_message=None, upload_file: str) -> Message | None:
    +    if not upload_file:
    +        raise ValueError("upload_file must be provided")
         self.upload_file = upload_file
         await super().run(with_message)
     
    Performance
    Add a break statement to exit the loop early once a successful evaluation is achieved.

    The RewriteReport class uses a method _ready_write_report that has a loop for retrying the
    evaluation of a report. The loop uses a counter to limit retries, but it does not break
    out of the loop once a successful evaluation is achieved. This can lead to unnecessary
    iterations even after a successful evaluation. To optimize performance and avoid
    unnecessary operations, add a break statement once a successful evaluation is achieved.

    tests/write_roport/core_report.py [91-97]

     while not success and counter < max_retry:
         suggestion, success = await self.evaluator.run(working_memory=self.working_memory.get())
         if not success:
             report = await self.refine.run(suggestion=suggestion, working_memory=self.working_memory.get())
             self.working_memory.delete(self.working_memory.get()[-1])
             self.working_memory.add(Message(content=report, role="assistant", cause_by=RefineReport))
    +    else:
    +        break
         counter += 1
     
    Possible issue
    Add checks to ensure self.rc and self.rc.todo are initialized before accessing them.

    The RewriteReport class method _write_report uses a local variable todo which is assigned
    from self.rc.todo, assuming it always exists. This can lead to AttributeError if self.rc
    or self.rc.todo is not properly initialized. To make the code more robust, add a check to
    ensure that self.rc and self.rc.todo are not None before accessing them.

    tests/write_roport/core_report.py [107-108]

    +if not hasattr(self, 'rc') or not hasattr(self.rc, 'todo'):
    +    raise AttributeError("Expected 'rc' and 'rc.todo' to be initialized")
     todo = self.rc.todo  # todo is WriteAnalysisCode
     logger.info(f"ready to {todo.name}")
     
    Add a check to ensure self.working_memory.index is not None before accessing it.

    The method _check_data in the RewriteReport class checks if "custom" is in
    self.working_memory.index but does not handle the case where self.working_memory.index
    might be uninitialized or None. This can lead to an AttributeError. To prevent this, add a
    check to ensure self.working_memory.index is not None before checking for "custom" in it.

    tests/write_roport/core_report.py [147-149]

    -if "custom" not in self.working_memory.index:
    +if self.working_memory.index is None or "custom" not in self.working_memory.index:
         logger.info("add user additional data into working_memory")
         self.read_data_info()
     
    Add a check to ensure self.planner is initialized before accessing its methods.

    The method _ready_write_report in the RewriteReport class uses a conditional to check if
    self.use_plan is True to get the plan status. However, this method does not handle the
    case where self.planner might be None, which can lead to AttributeError. To make the code
    more robust, add a check to ensure that self.planner is not None before accessing its
    methods.

    tests/write_roport/core_report.py [74]

    -plan_status = self.planner.get_plan_status() if self.use_plan else ""
    +if self.use_plan:
    +    if self.planner is None:
    +        raise AttributeError("Planner is not initialized")
    +    plan_status = self.planner.get_plan_status()
    +else:
    +    plan_status = ""
     
    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
    prevent parsing errors. The indentation levels in the first_paragraph and second_paragraph
    sections are inconsistent.

    tests/data/report_writer/domain.yaml [2-10]

     first_paragraph:
    -     name: first_paragraph
    -     desc: 请帮我依据用户所提供事故要点信息进行简要扩写, 完整事故报告的第一自然段。
    -     guidance: |
    -          请根据以下关键信息撰写一个合理的事故报告开头的第一自然段,主要介绍事故概要。在段落的结尾处,加入一段官方声明,声明应体现事故调查的严谨性和全面性。
    -          *** 注意事项 ***
    -          1. 在段落的结尾,请务必补充一段官方声明。eg:<事故调查组按照“实事求是、客观公正、尊重科学”的原则,...,  ... ,现将有关情况报告如下>
    -          2. 事件描述 简短扼要。
    -          请确保您的文本不仅简要记录了事故概要,而且语言表达准确、连贯,体现出调查报告的权威性和专业性。字数要求 300 - 500 之间。
    +  name: first_paragraph
    +  desc: 请帮我依据用户所提供事故要点信息进行简要扩写, 完整事故报告的第一自然段。
    +  guidance: |
    +    请根据以下关键信息撰写一个合理的事故报告开头的第一自然段,主要介绍事故概要。在段落的结尾处,加入一段官方声明,声明应体现事故调查的严谨性和全面性。
    +    *** 注意事项 ***
    +    1. 在段落的结尾,请务必补充一段官方声明。eg:<事故调查组按照“实事求是、客观公正、尊重科学”的原则,...,  ... ,现将有关情况报告如下>
    +    2. 事件描述 简短扼要。
    +    请确保您的文本不仅简要记录了事故概要,而且语言表达准确、连贯,体现出调查报告的权威性和专业性。字数要求 300 - 500 之间。
     

    ✨ 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=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @wangwenju269
    Copy link
    Author

    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)

    @shenchucheng
    Copy link
    Collaborator

    @wangwenju269 哈喽,有一些问题先请问下

    1. 为什么代码是写在tests目录下?
    2. 我看大部分的提示词都是中文,是必须使用中文提示词,还是什么原因呢?

    @wangwenju269
    Copy link
    Author

    wangwenju269 commented May 17, 2024 via email

    @wangwenju269
    Copy link
    Author

    有修改意见,请及时反馈给我,谢谢

    @garylin2099
    Copy link
    Collaborator

    您好: 答复如下 问题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核心代码相分开

    Copy link
    Collaborator

    @garylin2099 garylin2099 left a 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):
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    应为ReportRewriter,RewriteReport是动作的意思

    model: "qwen-14B-Chat" # or gpt-3.5-turbo
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    这个改动不应该提交

    Copy link
    Author

    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")
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    建议去掉具体的路径名和文件名

    Copy link
    Author

    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]:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    可使用llm.format_msg,见具体provider文件

    Copy link
    Author

    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 = """
    Copy link
    Collaborator

    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放入单独文件

    Copy link
    Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    这只是提示词应用模板,且是通用的,没必要存在单独文件里。

    Comment on lines +48 to +54
    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)
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    可改写PROMPT_TEMPLATE,这段使用super().run

    Copy link
    Author

    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:
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    这个函数是否需要改写?PLAN_STATUS待填入的变量名可以和原PLAN_STATUS保持一致

    Copy link
    Author

    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):
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    WriteReportPlanner

    @wangwenju269
    Copy link
    Author

    wangwenju269 commented May 23, 2024 via email

    @wangwenju269
    Copy link
    Author

    答复:文件放置在 test 目录下,方便更好测试代码是否独立执行成功。
    我已遵循评审大佬的要求和反馈建议,做出相应修改,清再次查收。
    祝好!

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    5 participants