Skip to content
Open
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
3 changes: 3 additions & 0 deletions openevolve/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ async def main_async() -> int:
# Apply command-line overrides
if args.api_base:
config.llm.api_base = args.api_base
# Models already got their api_base from the config file when it was
# loaded, and requests use the per-model value
config.llm.update_model_params({"api_base": args.api_base}, overwrite=True)
print(f"Using API base: {config.llm.api_base}")

if args.primary_model:
Expand Down
37 changes: 37 additions & 0 deletions tests/test_cli_model_override.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""
Test CLI model override functionality (GitHub issue #245)
"""
import asyncio
import sys
import unittest
import tempfile
import os
from unittest.mock import AsyncMock, MagicMock, patch

from openevolve.cli import main_async
from openevolve.config import Config, load_config


Expand Down Expand Up @@ -129,6 +133,39 @@ def test_evaluator_models_updated_after_rebuild(self):
self.assertEqual(len(config.llm.evaluator_models), 1)
self.assertEqual(config.llm.evaluator_models[0].name, "test-model")

def test_cli_api_base_alone_overrides_config_file_models(self):
"""--api-base without a model flag must reach the models from the config file"""
with tempfile.TemporaryDirectory() as tmp:
config_path = os.path.join(tmp, "config.yaml")
with open(config_path, "w") as f:
f.write('llm:\n models:\n - name: "gpt-4o-mini"\n weight: 1.0\n')
program_path = os.path.join(tmp, "program.py")
with open(program_path, "w") as f:
f.write("x = 1\n")
eval_path = os.path.join(tmp, "evaluator.py")
with open(eval_path, "w") as f:
f.write("def evaluate(program_path):\n return {'combined_score': 1.0}\n")

argv = [
"openevolve-run",
program_path,
eval_path,
"--config",
config_path,
"--output",
tmp,
"--api-base",
"http://localhost:8000/v1",
]
with patch.object(sys, "argv", argv), patch("openevolve.cli.OpenEvolve") as mock_cls:
mock_cls.return_value.run = AsyncMock(return_value=MagicMock(metrics={}))
mock_cls.return_value.output_dir = tmp
self.assertEqual(asyncio.run(main_async()), 0)

config = mock_cls.call_args.kwargs["config"]
for model in config.llm.models + config.llm.evaluator_models:
self.assertEqual(model.api_base, "http://localhost:8000/v1")


if __name__ == '__main__':
unittest.main()