refine: add terminate in Interpreter instead of Role.

This commit is contained in:
刘棒棒 2024-03-11 11:25:23 +08:00
parent 1e04e34103
commit 803359a758
3 changed files with 6 additions and 4 deletions

View file

@ -58,7 +58,8 @@ class ExecuteNbCode(Action):
async def terminate(self):
"""kill NotebookClient"""
await self.nb_client._async_cleanup_kernel()
if self.nb_client.km is not None:
await self.nb_client._async_cleanup_kernel()
async def reset(self):
"""reset NotebookClient"""

View file

@ -42,6 +42,10 @@ class Interpreter(Role):
def working_memory(self):
return self.rc.working_memory
async def _plan_and_act(self) -> Message:
await super()._plan_and_act()
await self.execute_code.terminate()
async def _act_on_task(self, current_task: Task) -> TaskResult:
code, result, is_success = await self._write_and_exec_code()
task_result = TaskResult(code=code, result=result, is_success=is_success)

View file

@ -503,9 +503,6 @@ class Role(SerializationMixin, ContextMixin, BaseModel):
self.rc.memory.add(rsp) # add to persistent memory
if hasattr(self, "execute_code") and hasattr(self.execute_code, "terminate"):
await self.execute_code.terminate()
return rsp
async def _act_on_task(self, current_task: Task) -> TaskResult: