Skip to content
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
17 changes: 16 additions & 1 deletion maseval/interface/inference/google_genai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading