Move executor diag print to conversable_agent (#1867)

* print in conversable agent, not in executor

* fix fstring
This commit is contained in:
Jack Gerrits 2024-03-05 18:09:18 -05:00 committed by GitHub
parent 434b75e6fd
commit 09a4918921
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 10 deletions

View File

@ -1271,6 +1271,25 @@ class ConversableAgent(LLMAgent):
code_blocks = self._code_executor.code_extractor.extract_code_blocks(message["content"])
if len(code_blocks) == 0:
continue
num_code_blocks = len(code_blocks)
if num_code_blocks > 1:
print(
colored(
f"\n>>>>>>>> EXECUTING CODE BLOCK (inferred language is {code_blocks[0].language})...",
"red",
),
flush=True,
)
else:
print(
colored(
f"\n>>>>>>>> EXECUTING {num_code_blocks} CODE BLOCKS (inferred languages are [{', '.join([x.language for x in code_blocks])}])...",
"red",
),
flush=True,
)
# found code blocks, execute code.
code_result = self._code_executor.execute_code_blocks(code_blocks)
exitcode2str = "execution succeeded" if code_result.exit_code == 0 else "execution failed"

View File

@ -5,13 +5,11 @@ import warnings
from typing import Any, ClassVar, List, Optional
from pydantic import BaseModel, Field, field_validator
from autogen.agentchat.conversable_agent import colored
from ..agentchat.agent import LLMAgent
from ..code_utils import execute_code
from .base import CodeBlock, CodeExtractor, CodeResult
from .markdown_code_extractor import MarkdownCodeExtractor
__all__ = (
"LocalCommandlineCodeExecutor",
"CommandlineCodeResult",
@ -139,14 +137,6 @@ If you want the user to save the code in a file before executing it, put # filen
lang, code = code_block.language, code_block.code
LocalCommandlineCodeExecutor.sanitize_command(lang, code)
print(
colored(
f"\n>>>>>>>> EXECUTING CODE BLOCK {i} (inferred language is {lang})...",
"red",
),
flush=True,
)
filename_uuid = uuid.uuid4().hex
filename = None
if lang in ["bash", "shell", "sh", "pwsh", "powershell", "ps1"]: