mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-11 15:15:18 +02:00
Merge branch 'fix_truncate' into 'dev'
Fix truncate See merge request agents/data_agents_opt!24
This commit is contained in:
commit
6fb65c547e
2 changed files with 11 additions and 5 deletions
|
|
@ -186,14 +186,13 @@ class ExecutePyCode(ExecuteCode, Action):
|
|||
def truncate(result: str, keep_len: int = 2000) -> str:
|
||||
desc = f"Truncated to show only the last {keep_len} characters\n"
|
||||
if result.startswith(desc):
|
||||
result = result[-len(desc) :]
|
||||
result = result[len(desc) :]
|
||||
|
||||
if len(result) > keep_len:
|
||||
result = result[-keep_len:]
|
||||
|
||||
if not result.startswith(desc):
|
||||
return desc + result
|
||||
return desc
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def remove_escape_and_color_codes(input_str):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from metagpt.actions.execute_code import ExecutePyCode
|
||||
from metagpt.actions.execute_code import ExecutePyCode, truncate
|
||||
from metagpt.schema import Message
|
||||
|
||||
|
||||
|
|
@ -81,3 +81,10 @@ async def test_plotting_bug():
|
|||
pi = ExecutePyCode()
|
||||
output = await pi.run(code)
|
||||
assert output[1] is True
|
||||
|
||||
|
||||
def test_truncate():
|
||||
output = "hello world"
|
||||
assert truncate(output) == output
|
||||
output = "hello world"
|
||||
assert truncate(output, 5) == "Truncated to show only the last 5 characters\nworld"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue