-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor I/O utils; allow 'task' command line parameter in cli.py (#6187
) Co-authored-by: OpenHands Bot <[email protected]>
- Loading branch information
1 parent
663e361
commit eed7e2d
Showing
13 changed files
with
88 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from openhands.io.io import read_input, read_task, read_task_from_file | ||
from openhands.io.json import dumps, loads | ||
|
||
__all__ = [ | ||
'read_input', | ||
'read_task_from_file', | ||
'read_task', | ||
'dumps', | ||
'loads', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import argparse | ||
import sys | ||
|
||
|
||
def read_input(cli_multiline_input: bool = False) -> str: | ||
"""Read input from user based on config settings.""" | ||
if cli_multiline_input: | ||
print('Enter your message (enter "/exit" on a new line to finish):') | ||
lines = [] | ||
while True: | ||
line = input('>> ').rstrip() | ||
if line == '/exit': # finish input | ||
break | ||
lines.append(line) | ||
return '\n'.join(lines) | ||
else: | ||
return input('>> ').rstrip() | ||
|
||
|
||
def read_task_from_file(file_path: str) -> str: | ||
"""Read task from the specified file.""" | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
return file.read() | ||
|
||
|
||
def read_task(args: argparse.Namespace, cli_multiline_input: bool) -> str: | ||
""" | ||
Read the task from the CLI args, file, or stdin. | ||
""" | ||
|
||
# Determine the task | ||
task_str = '' | ||
if args.file: | ||
task_str = read_task_from_file(args.file) | ||
elif args.task: | ||
task_str = args.task | ||
elif not sys.stdin.isatty(): | ||
task_str = read_input(cli_multiline_input) | ||
|
||
return task_str |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters