/ examples / di / fix_github_issue.py
fix_github_issue.py
 1  """This example is from a real issue from MetaGPT: https://github.com/geekan/MetaGPT/issues/1067 with corresponding bugfix as https://github.com/geekan/MetaGPT/pull/1069
 2  We demonstrate that DataInterpreter has the capability to fix such issues.
 3  Prerequisite: You need to manually add the bug back to your local file metagpt/utils/repair_llm_raw_output.py to test DataInterpreter's debugging ability. For detail, please check the issue and PR link above.
 4  """
 5  
 6  import asyncio
 7  
 8  from metagpt.roles.di.data_interpreter import DataInterpreter
 9  
10  REQ = """
11  # Requirement
12  Below is a github issue, solve it. Use Editor to search for the function, understand it, and modify the relevant code.
13  Write a new test file test.py with Editor and use Terminal to python the test file to ensure you have fixed the issue.
14  When writing test.py, you should import the function from the file you modified and test it with the given input.
15  Notice: Don't write all codes in one response, each time, just write code for one step.
16  
17  # Issue
18  >> s = "-1"
19  >> print(extract_state_value_from_output(s))
20  >> 1
21  The extract_state_value_from_output function will process -1 into 1,
22  resulted in an infinite loop for the react mode.
23  """
24  
25  
26  async def main():
27      di = DataInterpreter(tools=["Terminal", "Editor"], react_mode="react")
28      await di.run(REQ)
29  
30  
31  if __name__ == "__main__":
32      asyncio.run(main())