mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-10 07:18:10 -05:00
Feat: Async Goodies for OpenHands (#4347)
This commit is contained in:
@@ -14,6 +14,7 @@ from pathspec.patterns import GitWildMatchPattern
|
||||
from openhands.security.options import SecurityAnalyzers
|
||||
from openhands.server.data_models.feedback import FeedbackDataModel, store_feedback
|
||||
from openhands.storage import get_file_store
|
||||
from openhands.utils.async_utils import sync_from_async
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore')
|
||||
@@ -439,9 +440,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 asyncio.get_event_loop().run_in_executor(
|
||||
None, runtime.list_files, path
|
||||
)
|
||||
file_list = await sync_from_async(runtime.list_files, path)
|
||||
if path:
|
||||
file_list = [os.path.join(path, f) for f in file_list]
|
||||
|
||||
@@ -490,7 +489,7 @@ async def select_file(file: str, request: Request):
|
||||
|
||||
file = os.path.join(runtime.config.workspace_mount_path_in_sandbox, file)
|
||||
read_action = FileReadAction(file)
|
||||
observation = await runtime.async_run_action(read_action)
|
||||
observation = await sync_from_async(runtime.run_action, read_action)
|
||||
|
||||
if isinstance(observation, FileReadObservation):
|
||||
content = observation.content
|
||||
@@ -732,7 +731,7 @@ async def save_file(request: Request):
|
||||
runtime.config.workspace_mount_path_in_sandbox, file_path
|
||||
)
|
||||
write_action = FileWriteAction(file_path, content)
|
||||
observation = await runtime.async_run_action(write_action)
|
||||
observation = await sync_from_async(runtime.run_action, write_action)
|
||||
|
||||
if isinstance(observation, FileWriteObservation):
|
||||
return JSONResponse(
|
||||
|
||||
Reference in New Issue
Block a user