Skip to content

Commit

Permalink
Merge branch 'main' into fix_naming_cli_exec
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgerrits authored Mar 5, 2024
2 parents efd8216 + 09a4918 commit 6631697
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 19 additions & 0 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,25 @@ def _generate_code_execution_reply_using_executor(
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"
Expand Down
10 changes: 0 additions & 10 deletions autogen/coding/local_commandline_code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
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",
Expand Down Expand Up @@ -139,14 +137,6 @@ def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> CommandLineCodeRe
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"]:
Expand Down

0 comments on commit 6631697

Please sign in to comment.