mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-05 14:55:18 +02:00
使用code block做reflection
This commit is contained in:
parent
defca81ebb
commit
0e27e3d8be
2 changed files with 15 additions and 14 deletions
|
|
@ -6,8 +6,6 @@
|
|||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from metagpt.actions import Action
|
||||
from metagpt.prompts.di.write_analysis_code import (
|
||||
CHECK_DATA_PROMPT,
|
||||
|
|
@ -30,9 +28,10 @@ class WriteAnalysisCode(Action):
|
|||
)
|
||||
|
||||
rsp = await self._aask(reflection_prompt, system_msgs=[REFLECTION_SYSTEM_MSG])
|
||||
reflection = json.loads(CodeParser.parse_code(block=None, text=rsp))
|
||||
|
||||
return reflection["improved_impl"]
|
||||
# reflection = json.loads(CodeParser.parse_code(block=None, text=rsp))
|
||||
# return reflection["improved_impl"]
|
||||
reflection = CodeParser.parse_code(block=None, text=rsp)
|
||||
return reflection
|
||||
|
||||
async def run(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -40,15 +40,17 @@ Tests failed:
|
|||
assert add(1, 2) == 3 # output: -1
|
||||
assert add(1, 3) == 4 # output: -2
|
||||
|
||||
[reflection on previous impl]:
|
||||
[reflection on previous impl]
|
||||
The implementation failed the test cases where the input integers are 1 and 2. The issue arises because the code does not add the two integers together, but instead subtracts the second integer from the first. To fix this issue, we should change the operator from `-` to `+` in the return statement. This will ensure that the function returns the correct output for the given input.
|
||||
|
||||
[improved impl]:
|
||||
[improved impl]
|
||||
```python
|
||||
def add(a: int, b: int) -> int:
|
||||
"""
|
||||
Given integers a and b, return the total value of a and b.
|
||||
"""
|
||||
return a + b
|
||||
```
|
||||
'''
|
||||
|
||||
REFLECTION_PROMPT = """
|
||||
|
|
@ -60,17 +62,17 @@ Here is an example of debugging with reflection.
|
|||
[context]
|
||||
{context}
|
||||
|
||||
[previous impl]:
|
||||
[previous impl]
|
||||
{previous_impl}
|
||||
|
||||
[instruction]
|
||||
Analyze your previous code and error in [context] step by step, provide me with improved method and code. Remember to follow [context] requirement. Don't forget to write code for steps behind the error step.
|
||||
Output a json following the format:
|
||||
```json
|
||||
{{
|
||||
"reflection": str = "Reflection on previous implementation",
|
||||
"improved_impl": str = "Refined code after reflection (do not include nested code block here).",
|
||||
}}
|
||||
Output in the following format:
|
||||
[reflection on previous impl]
|
||||
...
|
||||
[improved impl]:
|
||||
```python
|
||||
# your code
|
||||
```
|
||||
"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue