mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-07-02 16:01:04 +02:00
fix:line numbers and line contents do not match.
This commit is contained in:
parent
a8aaece8fb
commit
e495ea90d0
3 changed files with 32 additions and 33 deletions
|
|
@ -248,22 +248,22 @@ class RoleZero(Role):
|
|||
return memory
|
||||
|
||||
async def parse_editor_result(self, memory: list[Message]) -> list[Message]:
|
||||
"""Retain the latest result for each editor command and remove outdated editor results."""
|
||||
# Set to keep track of unique editor commands
|
||||
record = set()
|
||||
"""Retain the latest result and remove outdated editor results."""
|
||||
keep_count = 5
|
||||
pattern = re.compile(r"Command Editor\.(\w+) executed")
|
||||
# Iterate over the memory in reverse order
|
||||
new_memory = []
|
||||
for msg in reversed(memory):
|
||||
matches = pattern.findall(msg.content)
|
||||
if not matches:
|
||||
continue
|
||||
# If all matches are already in the record, remove the editor content
|
||||
if all(match in record for match in matches):
|
||||
msg.content = msg.content[: msg.content.find("Command Editor")]
|
||||
else:
|
||||
# Add new matches to the record
|
||||
record.update(matches)
|
||||
return memory
|
||||
if matches:
|
||||
if keep_count < 0:
|
||||
new_content = msg.content[: msg.content.find("Command Editor")]
|
||||
new_content += "\n".join([f"Command Editor\.{match} executed." for match in matches])
|
||||
msg = UserMessage(content=new_content)
|
||||
keep_count -= 1
|
||||
new_memory.append(msg)
|
||||
# Reverse the new memory list so the latest message is at the end
|
||||
new_memory.reverse()
|
||||
return new_memory
|
||||
|
||||
def parse_images(self, memory: list[Message]) -> list[Message]:
|
||||
if not self.llm.support_image_input():
|
||||
|
|
@ -446,11 +446,7 @@ class RoleZero(Role):
|
|||
if command_flag.count(False) > 1:
|
||||
# Keep only the first exclusive command
|
||||
index_of_first_exclusive = command_flag.index(False)
|
||||
commands = [
|
||||
cmd
|
||||
for index, cmd in enumerate(commands)
|
||||
if index == index_of_first_exclusive or cmd["command_name"] not in self.exclusive_tool_commands
|
||||
]
|
||||
commands = commands[: index_of_first_exclusive + 1]
|
||||
command_rsp = "```json\n" + json.dumps(commands, indent=4, ensure_ascii=False) + "\n```"
|
||||
logger.info(
|
||||
"exclusive command more than one in current command list. change the command list.\n" + command_rsp
|
||||
|
|
|
|||
|
|
@ -780,14 +780,17 @@ class Editor(BaseModel):
|
|||
if lines[line_number - 1].rstrip() != line_content:
|
||||
start = max(1, line_number - 3)
|
||||
end = min(total_lines, line_number + 3)
|
||||
context = "".join(
|
||||
[f"{line_number:03d}|{lines[line_number-1]}" for line_number in range(start, end + 1)]
|
||||
context = "\n".join(
|
||||
[
|
||||
f'The {line_number:03d} line is "{lines[line_number-1].rstrip()}"'
|
||||
for line_number in range(start, end + 1)
|
||||
]
|
||||
)
|
||||
mismatch_error += LINE_NUMBER_AND_CONTENT_MISMATCH.format(
|
||||
position=position,
|
||||
line_number=line_number,
|
||||
true_content=lines[line_number - 1].rstrip(),
|
||||
fake_content=line_content,
|
||||
fake_content=line_content.replace("\n", "\\n"),
|
||||
context=context.strip(),
|
||||
)
|
||||
if mismatch_error:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue