Skip to content

Commit 2ee079d

Browse files
authored
Merge pull request #16 from jihe520/codex/修复拼写错误和代码问题
Fix interpreter restart and improve tests
2 parents 4b7b56c + d00e613 commit 2ee079d

File tree

5 files changed

+47
-158
lines changed

5 files changed

+47
-158
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
## ✨ 功能特性
2525

2626
- 🔍 自动分析问题,数学建模,编写代码,纠正错误,撰写论文
27-
- 💻 Code Interperter
28-
- loacl Interperter: 基于 jupyter , 代码保存为 notebook 方便再编辑
29-
- 云端 code interperter: [E2B](https://e2b.dev/)[daytona](https://app.daytona.io/)
27+
- 💻 Code Interpreter
28+
- local Interpreter: 基于 jupyter , 代码保存为 notebook 方便再编辑
29+
- 云端 code interpreter: [E2B](https://e2b.dev/)[daytona](https://app.daytona.io/)
3030
- 📝 生成一份编排好格式的论文
31-
- 🤝 muti-agents: 建模手,代码手,论文手等
32-
- 🔄 muti-llms: 每个 agent 设置不同的、合适的模型
31+
- 🤝 multi-agents: 建模手,代码手,论文手等
32+
- 🔄 multi-llms: 每个 agent 设置不同的、合适的模型
3333
- 🤖 支持所有模型: [litellm](https://docs.litellm.ai/docs/providers)
3434
- 💰 成本低:workflow agentless,不依赖 agent 框架
3535
- 🧩 自定义模板:prompt inject 为每个 subtask 单独设置需求

backend/app/tests/test_cite.py

Lines changed: 0 additions & 146 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import unittest
2+
3+
from app.utils.common_utils import split_footnotes
4+
5+
6+
class TestCommonUtils(unittest.TestCase):
7+
def test_split_footnotes(self):
8+
text = "Example[^1]\n\n[^1]: Footnote content"
9+
main, notes = split_footnotes(text)
10+
self.assertEqual(main, "Example")
11+
self.assertEqual(notes, [("1", "Footnote content")])
12+
13+
14+
if __name__ == "__main__":
15+
unittest.main()

backend/app/tests/test_e2b.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
import os
2+
import asyncio
13
import unittest
24

5+
6+
from dotenv import load_dotenv
7+
8+
from app.tools.e2b_interpreter import E2BCodeInterpreter
9+
from app.utils.common_utils import create_work_dir
10+
311
try:
412
from dotenv import load_dotenv
513
except ModuleNotFoundError: # Fallback if python-dotenv is not installed
@@ -11,21 +19,26 @@ def load_dotenv(*args, **kwargs):
1119
except ModuleNotFoundError:
1220
E2BCodeInterpreter = None
1321
from app.utils.common_utils import create_task_id, create_work_dir
14-
from app.tools.notebook_serializer import NotebookSerializer
22+
1523

1624

1725
class TestE2BCodeInterpreter(unittest.TestCase):
1826
def setUp(self):
1927
load_dotenv()
28+
2029
if E2BCodeInterpreter is None:
2130
self.skipTest("e2b_code_interpreter not available")
2231
_, dirs = create_work_dir("20250312-104132-d3625cab")
2332
notebook = NotebookSerializer(dirs["jupyter"])
33+
2434
self.code_interpreter = E2BCodeInterpreter(
25-
dirs, "20250312-104132-d3625cab", notebook
35+
self.task_id, self.work_dir, notebook
2636
)
2737

2838
def test_execute_code(self):
39+
if not os.getenv("E2B_API_KEY"):
40+
self.skipTest("E2B_API_KEY not set")
41+
2942
code = """
3043
import matplotlib.pyplot as plt
3144
import numpy as np
@@ -48,6 +61,8 @@ def test_execute_code(self):
4861
plt.legend()
4962
5063
# 显示图像
51-
plt.show()
64+
plt.show()
5265
"""
53-
self.code_interpreter.execute_code(code)
66+
asyncio.run(self.code_interpreter.initialize())
67+
asyncio.run(self.code_interpreter.execute_code(code))
68+

backend/app/tools/local_interpreter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,14 @@ def send_interrupt_signal(self):
219219
self.interrupt_signal = True
220220

221221
def restart_jupyter_kernel(self):
222-
self.kernel_client.shutdown()
223-
self.kernel_manager, self.kernel_client = (
224-
jupyter_client.manager.start_new_kernel(kernel_name="python3")
222+
"""Restart the Jupyter kernel and recreate the work directory."""
223+
self.kc.shutdown()
224+
self.km, self.kc = jupyter_client.manager.start_new_kernel(
225+
kernel_name="python3"
225226
)
226227
self.interrupt_signal = False
227228
self._create_work_dir()
229+
230+
def _create_work_dir(self):
231+
"""Ensure the working directory exists after a restart."""
232+
os.makedirs(self.work_dir, exist_ok=True)

0 commit comments

Comments
 (0)