99from pathlib import Path
1010
1111from openevolve import run_evolution , evolve_function , evolve_code , evolve_algorithm
12+ from openevolve .config import Config , LLMModelConfig
13+
14+
15+ def _get_library_test_config (port : int = 8000 ) -> Config :
16+ """Get config for library API tests with optillm server"""
17+ config = Config ()
18+ config .max_iterations = 100
19+ config .checkpoint_interval = 25
20+ config .database .in_memory = True
21+ config .evaluator .cascade_evaluation = False
22+ config .evaluator .parallel_evaluations = 1
23+ config .evaluator .timeout = 60
24+
25+ # Configure to use optillm server
26+ base_url = f"http://localhost:{ port } /v1"
27+ config .llm .api_base = base_url
28+ config .llm .timeout = 120
29+ config .llm .retries = 0
30+ config .llm .models = [
31+ LLMModelConfig (
32+ name = "google/gemma-3-270m-it" ,
33+ api_key = "optillm" ,
34+ api_base = base_url ,
35+ weight = 1.0 ,
36+ timeout = 120 ,
37+ retries = 0
38+ )
39+ ]
40+ return config
1241
1342
1443class TestLibraryAPIIntegration :
@@ -45,7 +74,8 @@ def simple_multiply(x, y):
4574 test_cases ,
4675 iterations = 2 , # Very small number for CI speed
4776 output_dir = str (temp_workspace / "evolve_function_output" ),
48- cleanup = False # Keep files for inspection
77+ cleanup = False , # Keep files for inspection
78+ config = _get_library_test_config (optillm_server ['port' ])
4979 )
5080
5181 # Verify the result structure
@@ -136,7 +166,8 @@ def fibonacci_evaluator(program_path):
136166 fibonacci_evaluator ,
137167 iterations = 1 , # Minimal for CI speed
138168 output_dir = str (temp_workspace / "evolve_code_output" ),
139- cleanup = False # Keep output directory
169+ cleanup = False , # Keep output directory
170+ config = _get_library_test_config (optillm_server ['port' ])
140171 )
141172
142173 # Verify result structure
@@ -233,7 +264,8 @@ def evaluate(program_path):
233264 evaluator = str (evaluator_file ),
234265 iterations = 1 , # Minimal for CI speed
235266 output_dir = str (temp_workspace / "run_evolution_output" ),
236- cleanup = False # Keep output directory
267+ cleanup = False , # Keep output directory
268+ config = _get_library_test_config (optillm_server ['port' ])
237269 )
238270
239271 # Verify result
@@ -258,7 +290,9 @@ def evaluate(program_path):
258290 initial_program = initial_program .read_text (),
259291 evaluator = lambda path : {"score" : 0.8 , "test" : "passed" }, # Simple callable evaluator
260292 iterations = 1 ,
261- output_dir = str (temp_workspace / "run_evolution_string_output" )
293+ output_dir = str (temp_workspace / "run_evolution_string_output" ),
294+ cleanup = False , # Keep output directory
295+ config = _get_library_test_config (optillm_server ['port' ])
262296 )
263297
264298 assert result2 is not None
0 commit comments