fix: code Interpreter error handling not work (#21736)
This commit is contained in:
parent
a67441689a
commit
4198a533ad
1 changed files with 6 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ from typing import Any, Optional
|
||||||
from core.helper.code_executor.code_executor import CodeExecutor, CodeLanguage
|
from core.helper.code_executor.code_executor import CodeExecutor, CodeLanguage
|
||||||
from core.tools.builtin_tool.tool import BuiltinTool
|
from core.tools.builtin_tool.tool import BuiltinTool
|
||||||
from core.tools.entities.tool_entities import ToolInvokeMessage
|
from core.tools.entities.tool_entities import ToolInvokeMessage
|
||||||
|
from core.tools.errors import ToolInvokeError
|
||||||
|
|
||||||
|
|
||||||
class SimpleCode(BuiltinTool):
|
class SimpleCode(BuiltinTool):
|
||||||
|
|
@ -25,6 +26,8 @@ class SimpleCode(BuiltinTool):
|
||||||
if language not in {CodeLanguage.PYTHON3, CodeLanguage.JAVASCRIPT}:
|
if language not in {CodeLanguage.PYTHON3, CodeLanguage.JAVASCRIPT}:
|
||||||
raise ValueError(f"Only python3 and javascript are supported, not {language}")
|
raise ValueError(f"Only python3 and javascript are supported, not {language}")
|
||||||
|
|
||||||
result = CodeExecutor.execute_code(language, "", code)
|
try:
|
||||||
|
result = CodeExecutor.execute_code(language, "", code)
|
||||||
yield self.create_text_message(result)
|
yield self.create_text_message(result)
|
||||||
|
except Exception as e:
|
||||||
|
raise ToolInvokeError(str(e))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue