Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor fix for stablility #5

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ def generate_code_execution_reply(
):
"""Generate a reply using code execution."""
code_execution_config = config if config is not None else self._code_execution_config
exitcode = None
sonichi marked this conversation as resolved.
Show resolved Hide resolved
exitcode2str = None
if code_execution_config is False:
return False, None
if messages is None:
Expand Down
11 changes: 9 additions & 2 deletions autogen/code_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ def infer_lang(code):
"""
if code.startswith("python ") or code.startswith("pip") or code.startswith("python3 "):
return "sh"
return "python"

# check if code is a valid python code
try:
compile(code, "test", "exec")
return "python"
except SyntaxError:
# not a valid python code
return UNKNOWN


def extract_code(
Expand Down Expand Up @@ -252,7 +259,7 @@ def execute_code(
file_dir = os.path.dirname(filepath)
os.makedirs(file_dir, exist_ok=True)
if code is not None:
with open(filepath, "w") as fout:
with open(filepath, "w", encoding='utf-8') as fout:
sonichi marked this conversation as resolved.
Show resolved Hide resolved
fout.write(code)
# check if already running in a docker container
in_docker_container = os.path.exists("/.dockerenv")
Expand Down
Loading