litellm/tests/unit/llms/vertex_ai/context_caching
tavren27 77cf5c497f
fix(gemini): keep an empty trailing user turn so Gemini doesn't answer a model-turn 400 (#51311)
* fix(gemini): keep an empty trailing user turn so Gemini doesn't answer a model-turn 400

* fix(anthropic): keep an empty user message on the /v1/messages adapter so Gemini sees the user turn

* fix(gemini): add the blank user turn only for Gemini targets and fill an empty last user message with the continue message

The Responses bridge and the Anthropic Messages adapter now add back an empty
user message only when the target's chat config is Gemini's, the caller's last
message was an empty user message, and the converted request does not already
end on a user, tool or function message. With ensure_alternating_roles on, an
empty last user message is replaced by the continue message, and the continue
messages are copied so no request edits the shared default.

Ports 0a532277d8, f06c3b3893, 51c83ccd88 and fbc2df0e71 from the LTS branch.

* fix(gemini): send the blank user turn only for blank content and copy each inserted continue message

Drop the ensure_alternating_roles fill so alternating deployments of other providers keep the request they got before. Content of the wrong type keeps the base 400, and every inserted continue message is a fresh copy so a folded system prompt never reaches a later request

* fix(gemini): send the blank user turn only for the last user messages and catch every Gemini target in the bridges

* fix(responses): read a Vertex AI deployment's model_info.base_model when picking the Gemini route in the bridges

* fix(responses): keep an empty last user message for alternating Gemini deployments

The bridges dropped it when ensure_alternating_roles was set, so alternation sent the continue message on some shapes and the blank turn on others

* fix(gemini): send an alternating deployment's continue message for an empty last user message, and keep the user turn on adapter_completion

On an alternating Gemini deployment, completion() now drops an empty last user message so ensure_alternating_roles appends the configured user_continue_message, the same text /v1/messages already sent, on every route. adapter_completion, which proxy pass-through adapter targets use, now keeps the empty last user turn for Gemini like the /v1/messages handler

* test(gemini): flatten Gemini parts with chain.from_iterable in two tests

* fix(gemini): send a whitespace-only last Messages user turn to Gemini as a user turn

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-23 15:45:29 -08:00
..
__init__.py
conftest.py fix(vertex_ai): reuse known context caches instead of listing on every request (#46857) 2026-10-20 11:37:46 +00:00
test_context_caching_ttl.py fix(gemini): keep mid-conversation system messages in place so prompt caching survives (#53623) 2026-11-23 05:23:25 +00:00
test_known_cached_contents.py fix(vertex_ai): reuse known context caches instead of listing on every request (#46857) 2026-10-20 11:37:46 +00:00
test_vertex_ai_context_caching.py fix(gemini): keep an empty trailing user turn so Gemini doesn't answer a model-turn 400 (#51311) 2026-11-23 15:45:29 -08:00