Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiline and default user messages #5400

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openhands/core/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ def get_parser() -> argparse.ArgumentParser:
type=str,
help='The comma-separated list (in quotes) of IDs of the instances to evaluate',
)
parser.add_argument(
'--no-auto-continue',
action='store_true',
help='Disable automatic "continue" responses. Will read from stdin instead.',
)
return parser


Expand Down
18 changes: 17 additions & 1 deletion openhands/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ async def on_event(event: Event):
if exit_on_message:
message = '/exit'
elif fake_user_response_fn is None:
message = input('Request user input >> ')
# read until EOF (Ctrl+D on Unix, Ctrl+Z on Windows)
print('Request user input (press Ctrl+D/Z when done) >> ')
message = sys.stdin.read().rstrip()
else:
message = fake_user_response_fn(controller.get_state())
action = MessageAction(content=message)
Expand Down Expand Up @@ -241,6 +243,17 @@ def generate_sid(config: AppConfig, session_name: str | None = None) -> str:
return f'{session_name}-{hash_str[:16]}'


def auto_continue_response(
state: State,
encapsulate_solution: bool = False,
try_parse: Callable[[Action | None], str] | None = None,
) -> str:
"""Default function to generate user responses.
Returns 'continue' to tell the agent to proceed without asking for more input.
"""
return 'continue'


if __name__ == '__main__':
args = parse_arguments()

Expand Down Expand Up @@ -284,5 +297,8 @@ def generate_sid(config: AppConfig, session_name: str | None = None) -> str:
config=config,
initial_user_action=initial_user_action,
sid=sid,
fake_user_response_fn=None
if args.no_auto_continue
else auto_continue_response,
)
)
6 changes: 5 additions & 1 deletion tests/unit/test_arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_parser_default_values():
assert args.eval_note is None
assert args.llm_config is None
assert args.name == 'default'
assert not args.no_auto_continue


def test_parser_custom_values():
Expand Down Expand Up @@ -49,6 +50,7 @@ def test_parser_custom_values():
'gpt4',
'-n',
'test_session',
'--no-auto-continue',
]
)

Expand All @@ -64,6 +66,7 @@ def test_parser_custom_values():
assert args.eval_note == 'Test run'
assert args.llm_config == 'gpt4'
assert args.name == 'test_session'
assert args.no_auto_continue


def test_parser_file_overrides_task():
Expand Down Expand Up @@ -124,10 +127,11 @@ def test_help_message(capsys):
'-l LLM_CONFIG, --llm-config LLM_CONFIG',
'-n NAME, --name NAME',
'--config-file CONFIG_FILE',
'--no-auto-continue',
]

for element in expected_elements:
assert element in help_output, f"Expected '{element}' to be in the help message"

option_count = help_output.count(' -')
assert option_count == 15, f'Expected 15 options, found {option_count}'
assert option_count == 16, f'Expected 16 options, found {option_count}'
Loading