Support Gemini 4 Argon models across GenerateContent and Interactions APIs
This commit is contained in:
@@ -56,6 +56,8 @@ def structured_client(monkeypatch):
|
||||
("gemini-2.5-flash", {}), ("gemini-3.1-pro-preview", {"thinking_level": "high"}),
|
||||
(gemini_nodes.SSL_GeminiTextPrompt.GEMINI_3_7_FLASH, {"thinking_level": "medium"}),
|
||||
(gemini_nodes.SSL_GeminiTextPrompt.GEMINI_3_8_FLASH, {"thinking_level": "medium"}),
|
||||
(gemini_nodes.SSL_GeminiTextPrompt.GEMINI_4_ARGON, {"thinking_level": "medium"}),
|
||||
(gemini_nodes.SSL_GeminiTextPrompt.GEMINI_4_ARGON_CYBER_PERMISSIVE, {"thinking_level": "high"}),
|
||||
])
|
||||
@pytest.mark.parametrize("client_config", [{}, {"vertexai_express": True}, {"use_vertexai_env": True, "vertexai_project": "test", "vertexai_location": "global"}])
|
||||
def test_builder_schema_reaches_generate_content(structured_client, monkeypatch, model, settings, client_config):
|
||||
@@ -1193,6 +1195,8 @@ def test_confirmed_current_models_are_visible_without_deprecated_image_aliases()
|
||||
image_size = next(input_ for input_ in schema.inputs if input_.id == "image_size")
|
||||
|
||||
for model in (
|
||||
"gemini-4-argon",
|
||||
"gemini-4-argon-cyber-permissive",
|
||||
"gemini-3.7-flash",
|
||||
"gemini-3.8-flash",
|
||||
"gemini-3.5-flash",
|
||||
@@ -1390,6 +1394,110 @@ def test_gemini_3_8_rejects_minimal_thinking_level():
|
||||
)
|
||||
|
||||
|
||||
def test_gemini_4_argon_uses_gemini_3_thinking_config():
|
||||
config = gemini_nodes.SSL_GeminiTextPrompt._build_generate_content_config(
|
||||
model="gemini-4-argon",
|
||||
temperature=0.4,
|
||||
top_p=0.8,
|
||||
top_k=20,
|
||||
max_output_tokens=1024,
|
||||
seed=7,
|
||||
include_images=False,
|
||||
response_modalities=["TEXT"],
|
||||
aspect_ratio="None",
|
||||
padded_system_instruction="system",
|
||||
thinking_level="None",
|
||||
thinking_budget=4096,
|
||||
include_thoughts=True,
|
||||
media_resolution="unspecified",
|
||||
)
|
||||
|
||||
assert config.thinking_config.thinking_level.value == "MEDIUM"
|
||||
assert config.thinking_config.thinking_budget is None
|
||||
assert config.temperature is None
|
||||
assert config.top_p is None
|
||||
assert config.top_k is None
|
||||
|
||||
# Cyber permissive variant defaults to HIGH thinking level
|
||||
config_cyber = gemini_nodes.SSL_GeminiTextPrompt._build_generate_content_config(
|
||||
model="gemini-4-argon-cyber-permissive",
|
||||
temperature=0.4,
|
||||
top_p=0.8,
|
||||
top_k=20,
|
||||
max_output_tokens=1024,
|
||||
seed=7,
|
||||
include_images=False,
|
||||
response_modalities=["TEXT"],
|
||||
aspect_ratio="None",
|
||||
padded_system_instruction="system",
|
||||
thinking_level="None",
|
||||
thinking_budget=4096,
|
||||
include_thoughts=True,
|
||||
media_resolution="unspecified",
|
||||
)
|
||||
assert config_cyber.thinking_config.thinking_level.value == "HIGH"
|
||||
assert config_cyber.thinking_config.thinking_budget is None
|
||||
assert config_cyber.temperature is None
|
||||
assert config_cyber.top_p is None
|
||||
assert config_cyber.top_k is None
|
||||
|
||||
|
||||
def test_gemini_4_argon_rejects_minimal_thinking_level():
|
||||
with pytest.raises(ValueError, match="gemini-4-argon thinking_level"):
|
||||
gemini_nodes.SSL_GeminiTextPrompt._resolve_gemini_3_7_thinking_level(
|
||||
"minimal", gemini_nodes.SSL_GeminiTextPrompt.GEMINI_4_ARGON
|
||||
)
|
||||
with pytest.raises(ValueError, match="gemini-4-argon-cyber-permissive thinking_level"):
|
||||
gemini_nodes.SSL_GeminiTextPrompt._resolve_gemini_3_7_thinking_level(
|
||||
"minimal", gemini_nodes.SSL_GeminiTextPrompt.GEMINI_4_ARGON_CYBER_PERMISSIVE
|
||||
)
|
||||
|
||||
|
||||
def test_gemini_4_argon_fingerprint_omits_sampling_params():
|
||||
common = {
|
||||
"config": {"api_key": "key", "api_version": "v1"},
|
||||
"prompt": "prompt",
|
||||
"system_instruction": "system",
|
||||
"model": "gemini-4-argon",
|
||||
"max_output_tokens": 1024,
|
||||
"include_images": False,
|
||||
"aspect_ratio": "None",
|
||||
"bypass_mode": "None",
|
||||
"use_seed": False,
|
||||
"seed": 0,
|
||||
"include_thoughts": True,
|
||||
}
|
||||
|
||||
fp1, _ = gemini_nodes.SSL_GeminiTextPrompt._compute_fingerprint_and_check_cache(
|
||||
**common,
|
||||
temperature=0.1,
|
||||
top_p=0.5,
|
||||
top_k=10,
|
||||
thinking_budget=0,
|
||||
thinking_level="medium",
|
||||
)
|
||||
fp2, _ = gemini_nodes.SSL_GeminiTextPrompt._compute_fingerprint_and_check_cache(
|
||||
**common,
|
||||
temperature=0.9,
|
||||
top_p=0.99,
|
||||
top_k=90,
|
||||
thinking_budget=1000,
|
||||
thinking_level="medium",
|
||||
)
|
||||
assert fp1 == fp2
|
||||
|
||||
|
||||
def test_gemini_4_argon_skips_explicit_context_cache(structured_client):
|
||||
structured_client.responses = [[("final", "argon response")]]
|
||||
args = _execute_kwargs(_config(use_cache=True, cache_seed=42))
|
||||
args["model"] = "gemini-4-argon"
|
||||
output = gemini_nodes.SSL_GeminiTextPrompt.execute(**args)
|
||||
assert output[0] == "argon response"
|
||||
assert len(structured_client.calls) == 1
|
||||
# Explicit cache was not set on the request config
|
||||
assert structured_client.calls[0]["config"].cached_content is None
|
||||
|
||||
|
||||
def test_gemini_3_7_fingerprint_matches_effective_request_controls():
|
||||
common = {
|
||||
"config": {"api_key": "key", "api_version": "v1"},
|
||||
|
||||
@@ -155,6 +155,10 @@ def test_interactions_define_schema():
|
||||
assert "response_schema" in input_names
|
||||
assert "image_inputs" in input_names
|
||||
|
||||
model_input = next(i for i in schema.inputs if i.id == "model")
|
||||
assert "gemini-4-argon" in model_input.options
|
||||
assert "gemini-4-argon-cyber-permissive" in model_input.options
|
||||
|
||||
output_names = [o.id for o in schema.outputs]
|
||||
assert output_names == ["text", "image", "final_actual_seed", "structured_output", "thoughts", "interaction_id"]
|
||||
|
||||
@@ -341,6 +345,47 @@ def test_thinking_and_thoughts_extraction(mock_interactions_client):
|
||||
assert call["generation_config"]["thinking_summaries"] == "auto"
|
||||
|
||||
|
||||
def test_interactions_gemini_4_argon_thinking(mock_interactions_client):
|
||||
mock_interactions_client.responses = [
|
||||
{"text": "argon 1", "thoughts": "think 1", "id": "int_argon_1"},
|
||||
{"text": "argon 2", "thoughts": "think 2", "id": "int_argon_2"},
|
||||
]
|
||||
|
||||
# gemini-4-argon defaults to medium thinking level
|
||||
args1 = _execute_kwargs(
|
||||
model="gemini-4-argon",
|
||||
thinking_level="None",
|
||||
include_thoughts=True,
|
||||
)
|
||||
interactions_nodes.SSL_GeminiInteractionsTextPrompt.execute(**args1)
|
||||
call1 = mock_interactions_client.calls[0]
|
||||
assert call1["model"] == "gemini-4-argon"
|
||||
assert call1["generation_config"]["thinking_level"] == "medium"
|
||||
assert call1["generation_config"]["thinking_summaries"] == "auto"
|
||||
|
||||
# gemini-4-argon-cyber-permissive defaults to high thinking level
|
||||
args2 = _execute_kwargs(
|
||||
model="gemini-4-argon-cyber-permissive",
|
||||
thinking_level="None",
|
||||
include_thoughts=True,
|
||||
)
|
||||
interactions_nodes.SSL_GeminiInteractionsTextPrompt.execute(**args2)
|
||||
call2 = mock_interactions_client.calls[1]
|
||||
assert call2["model"] == "gemini-4-argon-cyber-permissive"
|
||||
assert call2["generation_config"]["thinking_level"] == "high"
|
||||
|
||||
|
||||
def test_interactions_gemini_4_argon_rejects_minimal():
|
||||
with pytest.raises(ValueError, match="gemini-4-argon thinking_level"):
|
||||
interactions_nodes.SSL_GeminiInteractionsTextPrompt._resolve_gemini_3_7_thinking_level(
|
||||
"minimal", interactions_nodes.SSL_GeminiInteractionsTextPrompt.GEMINI_4_ARGON
|
||||
)
|
||||
with pytest.raises(ValueError, match="gemini-4-argon-cyber-permissive thinking_level"):
|
||||
interactions_nodes.SSL_GeminiInteractionsTextPrompt._resolve_gemini_3_7_thinking_level(
|
||||
"minimal", interactions_nodes.SSL_GeminiInteractionsTextPrompt.GEMINI_4_ARGON_CYBER_PERMISSIVE
|
||||
)
|
||||
|
||||
|
||||
def test_multi_turn_chaining(mock_interactions_client):
|
||||
mock_interactions_client.responses = [
|
||||
{"text": "Turn 1 answer", "id": "int_turn_1"},
|
||||
|
||||
Reference in New Issue
Block a user