Skip to content

Commit

Permalink
Make trajectories_path support file path (#4840)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-boxuan authored Nov 8, 2024
1 parent f5003a7 commit 88dbe85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ workspace_base = "./workspace"
# Enable saving and restoring the session when run from CLI
#enable_cli_session = false

# Path to store trajectories
# Path to store trajectories, can be a folder or a file
# If it's a folder, the session id will be used as the file name
#trajectories_path="./trajectories"

# File store path
Expand Down
6 changes: 5 additions & 1 deletion openhands/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ async def on_event(event: Event):

# save trajectories if applicable
if config.trajectories_path is not None:
file_path = os.path.join(config.trajectories_path, sid + '.json')
# if trajectories_path is a folder, use session id as file name
if os.path.isdir(config.trajectories_path):
file_path = os.path.join(config.trajectories_path, sid + '.json')
else:
file_path = config.trajectories_path
os.makedirs(os.path.dirname(file_path), exist_ok=True)
histories = [event_to_trajectory(event) for event in state.history]
with open(file_path, 'w') as f:
Expand Down

0 comments on commit 88dbe85

Please sign in to comment.