Skip to content
Draft
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
6 changes: 4 additions & 2 deletions langextract/providers/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'tools',
'stop_sequences',
'candidate_count',
'thinking_config',
}


Expand Down Expand Up @@ -125,8 +126,9 @@ def __init__(
Gemini handles this based on schema).
**kwargs: Additional Gemini API parameters. Only allowlisted keys are
forwarded to the API (response_schema, response_mime_type, tools,
safety_settings, stop_sequences, candidate_count, system_instruction).
See https://ai.google.dev/api/generate-content for details.
safety_settings, stop_sequences, candidate_count,
system_instruction, thinking_config). See
https://ai.google.dev/api/generate-content for details.
"""
try:
# pylint: disable=import-outside-toplevel
Expand Down
15 changes: 14 additions & 1 deletion tests/inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def test_gemini_allowlist_filtering(self, mock_client_class):
tools=["tool1", "tool2"],
stop_sequences=["\n\n"],
system_instruction="Be helpful",
thinking_config={"thinking_level": "minimal"},
# Unknown parameters to test filtering
unknown_param="should_be_ignored",
another_unknown="also_ignored",
Expand All @@ -372,6 +373,7 @@ def test_gemini_allowlist_filtering(self, mock_client_class):
"tools": ["tool1", "tool2"],
"stop_sequences": ["\n\n"],
"system_instruction": "Be helpful",
"thinking_config": {"thinking_level": "minimal"},
}
self.assertEqual(
expected_extra_kwargs,
Expand All @@ -386,7 +388,12 @@ def test_gemini_allowlist_filtering(self, mock_client_class):
call_args = mock_client.models.generate_content.call_args
config = call_args.kwargs["config"]

for key in ["tools", "stop_sequences", "system_instruction"]:
for key in [
"tools",
"stop_sequences",
"system_instruction",
"thinking_config",
]:
self.assertIn(key, config, f"Expected {key} to be in API config")
self.assertEqual(
expected_extra_kwargs[key],
Expand Down Expand Up @@ -415,6 +422,7 @@ def test_gemini_runtime_kwargs_filtered(self, mock_client_class):
prompts,
candidate_count=2,
safety_settings={"HARM_CATEGORY_DANGEROUS": "BLOCK_NONE"},
thinking_config={"thinking_level": "minimal"},
unknown_runtime_param="ignored",
)
)
Expand All @@ -432,6 +440,11 @@ def test_gemini_runtime_kwargs_filtered(self, mock_client_class):
config.get("safety_settings"),
"safety_settings should be passed through to API",
)
self.assertEqual(
{"thinking_level": "minimal"},
config.get("thinking_config"),
"thinking_config should be passed through to API",
)
self.assertNotIn(
"unknown_runtime_param", config, "Unknown kwargs should be filtered out"
)
Expand Down
Loading