Skip to content

Commit 9268a21

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: Ignore case when determining if the last message comes from a user
PiperOrigin-RevId: 826144504
1 parent 2a86ae8 commit 9268a21

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

core/src/main/java/com/google/adk/models/GeminiUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static com.google.common.collect.ImmutableList.toImmutableList;
1919

20+
import com.google.common.base.Ascii;
2021
import com.google.common.collect.ImmutableList;
2122
import com.google.common.collect.ImmutableMap;
2223
import com.google.common.collect.Iterables;
@@ -128,7 +129,8 @@ public static LlmRequest sanitizeRequestForGeminiApi(LlmRequest llmRequest) {
128129
*/
129130
static List<Content> ensureModelResponse(List<Content> contents) {
130131
// Last content must be from the user, otherwise the model won't respond.
131-
if (contents.isEmpty() || !Iterables.getLast(contents).role().orElse("").equals("user")) {
132+
if (contents.isEmpty()
133+
|| !Ascii.equalsIgnoreCase(Iterables.getLast(contents).role().orElse(""), "user")) {
132134
Content userContent =
133135
Content.builder()
134136
.parts(ImmutableList.of(Part.fromText(CONTINUE_OUTPUT_MESSAGE)))

0 commit comments

Comments
 (0)