mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
(refactor) Make Runtime class synchronous (#3661)
* change runtime to be synchronous * fix test runtime with the new interface * fix arg * fix eval * fix missing config attribute * fix plugins * fix on_event by revert it back to async * update upload_file endpoint * fix argument to upload file * remove unncessary async for eval; fix evaluation run in parallel * use asyncio to run controller for eval * revert file upload * truncate eval test result output
This commit is contained in:
@@ -406,7 +406,7 @@ async def list_files(request: Request, path: str | None = None):
|
||||
content={'error': 'Runtime not yet initialized'},
|
||||
)
|
||||
runtime: Runtime = request.state.session.agent_session.runtime
|
||||
file_list = await runtime.list_files(path)
|
||||
file_list = runtime.list_files(path)
|
||||
return file_list
|
||||
|
||||
|
||||
@@ -440,7 +440,7 @@ async def select_file(file: str, request: Request):
|
||||
)
|
||||
|
||||
read_action = FileReadAction(file)
|
||||
observation = await runtime.run_action(read_action)
|
||||
observation = runtime.run_action(read_action)
|
||||
|
||||
if isinstance(observation, FileReadObservation):
|
||||
content = observation.content
|
||||
@@ -519,7 +519,7 @@ async def upload_file(request: Request, files: list[UploadFile]):
|
||||
tmp_file.flush()
|
||||
|
||||
runtime: Runtime = request.state.session.agent_session.runtime
|
||||
await runtime.copy_to(
|
||||
runtime.copy_to(
|
||||
tmp_file_path, runtime.config.workspace_mount_path_in_sandbox
|
||||
)
|
||||
uploaded_files.append(safe_filename)
|
||||
@@ -686,7 +686,7 @@ async def save_file(request: Request):
|
||||
# Save the file to the agent's runtime file store
|
||||
runtime: Runtime = request.state.session.agent_session.runtime
|
||||
write_action = FileWriteAction(file_path, content)
|
||||
observation = await runtime.run_action(write_action)
|
||||
observation = runtime.run_action(write_action)
|
||||
|
||||
if isinstance(observation, FileWriteObservation):
|
||||
return JSONResponse(
|
||||
|
||||
@@ -69,7 +69,7 @@ class AgentSession:
|
||||
end_state.save_to_session(self.sid, self.file_store)
|
||||
await self.controller.close()
|
||||
if self.runtime is not None:
|
||||
await self.runtime.close()
|
||||
self.runtime.close()
|
||||
if self.security_analyzer is not None:
|
||||
await self.security_analyzer.close()
|
||||
self._closed = True
|
||||
@@ -95,7 +95,6 @@ class AgentSession:
|
||||
sid=self.sid,
|
||||
plugins=agent.sandbox_plugins,
|
||||
)
|
||||
await self.runtime.ainit()
|
||||
|
||||
async def _create_controller(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user