mirror of
https://github.com/jihe520/MathModelAgent.git
synced 2026-10-02 02:44:56 +08:00
Fix return type in interpreters and update tests
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import unittest
|
||||
|
||||
from dotenv import load_dotenv
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
except ModuleNotFoundError: # Fallback if python-dotenv is not installed
|
||||
def load_dotenv(*args, **kwargs):
|
||||
return None
|
||||
|
||||
from app.tools.e2b_interpreter import E2BCodeInterpreter
|
||||
try:
|
||||
from app.tools.e2b_interpreter import E2BCodeInterpreter
|
||||
except ModuleNotFoundError:
|
||||
E2BCodeInterpreter = None
|
||||
from app.utils.common_utils import create_task_id, create_work_dir
|
||||
from app.tools.notebook_serializer import NotebookSerializer
|
||||
|
||||
@@ -10,6 +17,8 @@ from app.tools.notebook_serializer import NotebookSerializer
|
||||
class TestE2BCodeInterpreter(unittest.TestCase):
|
||||
def setUp(self):
|
||||
load_dotenv()
|
||||
if E2BCodeInterpreter is None:
|
||||
self.skipTest("e2b_code_interpreter not available")
|
||||
_, dirs = create_work_dir("20250312-104132-d3625cab")
|
||||
notebook = NotebookSerializer(dirs["jupyter"])
|
||||
self.code_interpreter = E2BCodeInterpreter(
|
||||
|
||||
@@ -34,7 +34,7 @@ class BaseCodeInterpreter(abc.ABC):
|
||||
...
|
||||
|
||||
@abc.abstractmethod
|
||||
async def execute_code(self, code: str) -> tuple[str, bool, str, list[str]]:
|
||||
async def execute_code(self, code: str) -> tuple[str, bool, str]:
|
||||
"""执行一段代码,返回 (输出文本, 是否出错, 错误信息)"""
|
||||
...
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class E2BCodeInterpreter(BaseCodeInterpreter):
|
||||
)
|
||||
await self.execute_code(init_code)
|
||||
|
||||
async def execute_code(self, code: str) -> tuple[str, bool, str, list[str]]:
|
||||
async def execute_code(self, code: str) -> tuple[str, bool, str]:
|
||||
"""执行代码并返回结果"""
|
||||
|
||||
if not self.sbx:
|
||||
|
||||
@@ -53,7 +53,7 @@ class LocalCodeInterpreter(BaseCodeInterpreter):
|
||||
)
|
||||
self.execute_code_(init_code)
|
||||
|
||||
async def execute_code(self, code: str) -> tuple[str, bool, str, list[str]]:
|
||||
async def execute_code(self, code: str) -> tuple[str, bool, str]:
|
||||
logger.info(f"执行代码: {code}")
|
||||
# 添加代码到notebook
|
||||
self.notebook_serializer.add_code_cell_to_notebook(code)
|
||||
|
||||
Reference in New Issue
Block a user