diff --git a/maseval/interface/inference/google_genai.py b/maseval/interface/inference/google_genai.py index 7d1024f..6af3d0f 100644 --- a/maseval/interface/inference/google_genai.py +++ b/maseval/interface/inference/google_genai.py @@ -343,12 +343,27 @@ def _structured_chat( if self._seed is not None and "seed" not in params: params["seed"] = self._seed + # Instructor's genai handler expects generation params (temperature, seed, etc.) + # inside a "generation_config" dict, not as top-level kwargs. Top-level kwargs + # pass through to generate_content() which rejects them. Separate params that + # instructor handles as top-level kwargs from those that must be in generation_config. + _INSTRUCTOR_TOP_LEVEL_KEYS = {"thinking_config", "safety_settings", "config"} + instructor_kwargs: Dict[str, Any] = {} + gen_config: Dict[str, Any] = {} + for key, value in params.items(): + if key in _INSTRUCTOR_TOP_LEVEL_KEYS: + instructor_kwargs[key] = value + else: + gen_config[key] = value + if gen_config: + instructor_kwargs["generation_config"] = gen_config + result = self._instructor_client.chat.completions.create( model=self._model_id, response_model=response_model, # ty: ignore[invalid-argument-type] messages=messages, # ty: ignore[invalid-argument-type] max_retries=max_retries, - **params, + **instructor_kwargs, ) return ChatResponse( diff --git a/tests/test_interface/test_model_integration/test_model_adapters.py b/tests/test_interface/test_model_integration/test_model_adapters.py index 3956afb..e2c14fd 100644 --- a/tests/test_interface/test_model_integration/test_model_adapters.py +++ b/tests/test_interface/test_model_integration/test_model_adapters.py @@ -2385,7 +2385,10 @@ def __init__(self): ) call_kwargs = mock_instructor.chat.completions.create.call_args - assert call_kwargs.kwargs.get("seed") == 99 + # Generation params should be nested inside generation_config for the + # Google GenAI instructor adapter (not passed as top-level kwargs). + gen_config = call_kwargs.kwargs.get("generation_config", {}) + assert gen_config.get("seed") == 99 @pytest.mark.interface