mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-02 07:13:02 +00:00
fix(gemini): set responseLogprobs when top_logprobs is the only logprob param
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
9155c43c01
commit
ffb199d05c
3 changed files with 23 additions and 4 deletions
|
|
@ -1690,6 +1690,7 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig):
|
|||
optional_params["responseLogprobs"] = value
|
||||
elif param == "top_logprobs":
|
||||
optional_params["logprobs"] = value
|
||||
optional_params["responseLogprobs"] = True
|
||||
elif (param == "tools" or param == "functions") and isinstance(value, list) and value:
|
||||
# Pass optional_params so _map_function can add toolConfig if needed
|
||||
mapped_tools = with_integer_enums_that_fit(
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ GEMINI_3_5_FLASH_TOP_LOGPROBS_TEST_CASE: Final = replace(
|
|||
scenario="top_logprobs",
|
||||
litellm_request={**GEMINI_3_5_FLASH_TEST_CASE.litellm_request, "top_logprobs": 3},
|
||||
expected_provider_request=with_field(
|
||||
GEMINI_3_5_FLASH_TEST_CASE.expected_provider_request, ("generationConfig", "logprobs"), 3
|
||||
with_field(GEMINI_3_5_FLASH_TEST_CASE.expected_provider_request, ("generationConfig", "logprobs"), 3),
|
||||
("generationConfig", "responseLogprobs"),
|
||||
True,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -22,5 +24,7 @@ CASES: Final = (GEMINI_3_5_FLASH_TOP_LOGPROBS_TEST_CASE,)
|
|||
|
||||
|
||||
@pytest.mark.parametrize("case", CASES, ids=lambda case: case.id)
|
||||
def test_responses_params_gemini_logprobs(case: TranslationTestCase, gateway: Gateway, provider: SharedProvider) -> None:
|
||||
def test_responses_params_gemini_logprobs(
|
||||
case: TranslationTestCase, gateway: Gateway, provider: SharedProvider
|
||||
) -> None:
|
||||
assert_translation(case, gateway, provider)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
from typing import Final
|
||||
|
||||
from litellm.llms.gemini.chat.transformation import GoogleAIStudioGeminiConfig
|
||||
|
||||
|
||||
def test_top_logprobs_maps_to_generation_config_logprobs():
|
||||
config = GoogleAIStudioGeminiConfig()
|
||||
config: Final = GoogleAIStudioGeminiConfig()
|
||||
|
||||
assert "top_logprobs" in config.get_supported_openai_params("gemini-3.5-flash")
|
||||
|
||||
optional_params = config.map_openai_params(
|
||||
optional_params: Final = config.map_openai_params(
|
||||
non_default_params={"logprobs": True, "top_logprobs": 3},
|
||||
optional_params={},
|
||||
model="gemini-3.5-flash",
|
||||
|
|
@ -15,3 +17,15 @@ def test_top_logprobs_maps_to_generation_config_logprobs():
|
|||
|
||||
assert optional_params["responseLogprobs"] is True
|
||||
assert optional_params["logprobs"] == 3
|
||||
|
||||
|
||||
def test_top_logprobs_alone_enables_response_logprobs():
|
||||
optional_params: Final = GoogleAIStudioGeminiConfig().map_openai_params(
|
||||
non_default_params={"top_logprobs": 3},
|
||||
optional_params={},
|
||||
model="gemini-3.5-flash",
|
||||
drop_params=False,
|
||||
)
|
||||
|
||||
assert optional_params["responseLogprobs"] is True
|
||||
assert optional_params["logprobs"] == 3
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue