Compare commits

...

2 Commits

Author SHA1 Message Date
openhands 4cbe46b56c Fix unit tests for new CLI LLM arguments
- Update test_help_message to include new CLI arguments (--llm-model, --llm-base-url, --llm-api-key)
- Update expected option count from 20 to 23
- Add tests for default and custom values of new CLI arguments
- All arg parser tests now pass
2025-06-17 14:34:37 +00:00
openhands f777029546 Fix formatting issues from pre-commit hooks 2025-06-16 12:11:14 +00:00
2 changed files with 52 additions and 1 deletions
+36
View File
@@ -744,6 +744,27 @@ def get_parser() -> argparse.ArgumentParser:
type=bool,
default=False,
)
# LLM configuration arguments for local models
parser.add_argument(
'--llm-model',
help='LLM model to use (e.g., "lm_studio/devstral", "openai/gpt-4")',
type=str,
default=None,
)
parser.add_argument(
'--llm-base-url',
help='Base URL for LLM API (required for local models, e.g., "http://localhost:1234/v1")',
type=str,
default=None,
)
parser.add_argument(
'--llm-api-key',
help='API key for LLM (use "dummy" for local models)',
type=str,
default=None,
)
return parser
@@ -821,6 +842,21 @@ def setup_config_from_args(args: argparse.Namespace) -> OpenHandsConfig:
raise ValueError(f'Invalid toml file, cannot read {args.llm_config}')
config.set_llm_config(llm_config)
# Override LLM settings with direct CLI arguments
if args.llm_model or args.llm_base_url or args.llm_api_key:
from pydantic import SecretStr
llm_config = config.get_llm_config()
if args.llm_model:
llm_config.model = args.llm_model
if args.llm_base_url:
llm_config.base_url = args.llm_base_url
if args.llm_api_key:
llm_config.api_key = SecretStr(args.llm_api_key)
config.set_llm_config(llm_config)
# Override default agent if provided
if args.agent_cls:
config.default_agent = args.agent_cls
+16 -1
View File
@@ -21,6 +21,9 @@ def test_parser_default_values():
assert args.name == ''
assert not args.no_auto_continue
assert args.selected_repo is None
assert args.llm_model is None
assert args.llm_base_url is None
assert args.llm_api_key is None
def test_parser_custom_values():
@@ -55,6 +58,12 @@ def test_parser_custom_values():
'--no-auto-continue',
'--selected-repo',
'owner/repo',
'--llm-model',
'openai/gpt-4',
'--llm-base-url',
'http://localhost:1234/v1',
'--llm-api-key',
'test-api-key',
]
)
@@ -73,6 +82,9 @@ def test_parser_custom_values():
assert args.no_auto_continue
assert args.version
assert args.selected_repo == 'owner/repo'
assert args.llm_model == 'openai/gpt-4'
assert args.llm_base_url == 'http://localhost:1234/v1'
assert args.llm_api_key == 'test-api-key'
def test_parser_file_overrides_task():
@@ -138,13 +150,16 @@ def test_help_message(capsys):
'--no-auto-continue',
'--selected-repo SELECTED_REPO',
'--override-cli-mode OVERRIDE_CLI_MODE',
'--llm-model LLM_MODEL',
'--llm-base-url LLM_BASE_URL',
'--llm-api-key LLM_API_KEY',
]
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 == 20, f'Expected 20 options, found {option_count}'
assert option_count == 23, f'Expected 23 options, found {option_count}'
def test_selected_repo_format():