Skip to content
Open
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
13 changes: 13 additions & 0 deletions src/google/adk/models/lite_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,19 @@ async def _get_completion_inputs(
mapped_key = param_mapping.get(key, key)
generation_params[mapped_key] = config_dict[key]

thinking_config = config_dict.get("thinking_config") or {}
thinking_level = thinking_config.get("thinking_level")
thinking_budget = thinking_config.get("thinking_budget")
if thinking_level and thinking_level != "THINKING_LEVEL_UNSPECIFIED":
generation_params["reasoning_effort"] = str(
getattr(thinking_level, "value", thinking_level)
).lower()
elif thinking_budget and thinking_budget > 0:
generation_params["thinking"] = {
"type": "enabled",
"budget_tokens": thinking_budget,
}

if not generation_params:
generation_params = None

Expand Down
38 changes: 38 additions & 0 deletions tests/unittests/models/test_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6407,6 +6407,44 @@ async def test_get_completion_inputs_generation_params():
assert "stop_sequences" not in generation_params


@pytest.mark.asyncio
async def test_get_completion_inputs_maps_thinking_level_to_reasoning_effort():
req = LlmRequest(
contents=[
types.Content(role="user", parts=[types.Part.from_text(text="hi")]),
],
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(
thinking_level=types.ThinkingLevel.LOW
),
),
)

_, _, _, generation_params, _ = await _get_completion_inputs(
req, model="gpt-4o-mini"
)
assert generation_params == {"reasoning_effort": "low"}


@pytest.mark.asyncio
async def test_get_completion_inputs_maps_thinking_budget():
req = LlmRequest(
contents=[
types.Content(role="user", parts=[types.Part.from_text(text="hi")]),
],
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_budget=2048),
),
)

_, _, _, generation_params, _ = await _get_completion_inputs(
req, model="gpt-4o-mini"
)
assert generation_params == {
"thinking": {"type": "enabled", "budget_tokens": 2048}
}


@pytest.mark.asyncio
async def test_get_completion_inputs_empty_generation_params():
# Test that generation_params is None when no generation parameters are set
Expand Down
Loading