Skip to content

Commit

Permalink
reorder how lang chosen
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudotensor committed Oct 30, 2024
1 parent 3c62b28 commit 5a79e1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
42 changes: 23 additions & 19 deletions openai_server/autogen_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,11 @@ def __execute_code_dont_check_setup(self, code_blocks: List[CodeBlock]) -> Comma
exitcode = -2
for code_block in code_blocks:
lang, code = code_block.language, code_block.code
lang = lang.lower()

if self.autogen_code_restrictions_level >= 2:
self.sanitize_command(lang, code)
elif self.autogen_code_restrictions_level == 1:
LocalCommandLineCodeExecutor.sanitize_command(lang, code)
code = silence_pip(code, lang)

if lang in PYTHON_VARIANTS:
lang = "python"

if WIN32 and lang in ["sh", "shell"]:
lang = "ps1"

if lang not in self.SUPPORTED_LANGUAGES:
# In case the language is not supported, we return an error message.
exitcode = 1
logs_all += "\n" + f"unknown language {lang}"
break
# DETERMINE LANGUAGE
lang = lang.lower()

execute_code = self.execution_policies.get(lang, False)
# GET FILENAME and adjust LANGUAGE
try:
# Check if there is a filename comment
filename = self._get_file_name_from_content(code, self._work_dir)
Expand All @@ -318,6 +302,26 @@ def __execute_code_dont_check_setup(self, code_blocks: List[CodeBlock]) -> Comma
except ValueError:
return CommandLineCodeResult(exit_code=1, output="Filename is not in the workspace")

if self.autogen_code_restrictions_level >= 2:
self.sanitize_command(lang, code)
elif self.autogen_code_restrictions_level == 1:
LocalCommandLineCodeExecutor.sanitize_command(lang, code)
code = silence_pip(code, lang)

if lang in PYTHON_VARIANTS:
lang = "python"

if WIN32 and lang in ["sh", "shell"]:
lang = "ps1"

if lang not in self.SUPPORTED_LANGUAGES:
# In case the language is not supported, we return an error message.
exitcode = 1
logs_all += "\n" + f"unknown language {lang}"
break

execute_code = self.execution_policies.get(lang, False)

if filename is None:
# create a file with an automatically generated name
code_hash = md5(code.encode()).hexdigest()
Expand Down
2 changes: 1 addition & 1 deletion src/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1b6738dffe5cec66f9f0d668548929080a878cc5"
__version__ = "3c62b283779854f719110bdb6e18b014496e2d08"

0 comments on commit 5a79e1f

Please sign in to comment.