Skip to content

Commit 53359fd

Browse files
ddobrinmarkpollack
authored andcommitted
Fixes #2185 - googleSearchRetrieval(true) causes INVALID_ARGUMENT error with Gemini 2.0 (use google_search instead)
1 parent 3ae67e7 commit 53359fd

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModel.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.ai.vertexai.gemini;
1818

19+
import com.google.cloud.vertexai.api.Tool.GoogleSearch;
1920
import java.util.ArrayList;
2021
import java.util.Collection;
2122
import java.util.List;
@@ -713,9 +714,10 @@ GeminiRequest createGeminiRequest(Prompt prompt) {
713714
}
714715

715716
if (prompt.getOptions() instanceof VertexAiGeminiChatOptions options && options.getGoogleSearchRetrieval()) {
716-
final var googleSearchRetrieval = GoogleSearchRetrieval.newBuilder().getDefaultInstanceForType();
717+
// final var googleSearchRetrieval = GoogleSearchRetrieval.newBuilder().getDefaultInstanceForType();
718+
var googleSearch = GoogleSearch.newBuilder().getDefaultInstanceForType();
717719
final var googleSearchRetrievalTool = Tool.newBuilder()
718-
.setGoogleSearchRetrieval(googleSearchRetrieval)
720+
.setGoogleSearch(googleSearch)
719721
.build();
720722
tools.add(googleSearchRetrievalTool);
721723
}
@@ -969,7 +971,7 @@ public enum ChatModel implements ChatModelDescription {
969971

970972
GEMINI_2_0_FLASH_LIGHT("gemini-2.0-flash-lite"),
971973

972-
GEMINI_2_5_PRO("gemini-2.5-pro-exp-03-28");
974+
GEMINI_2_5_PRO("gemini-2.5-pro-exp-03-25");
973975

974976
public final String value;
975977

models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatModelIT.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,28 @@ void testMessageHistory() {
8888
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
8989
}
9090

91+
// Disabled until Gemini 2.5 PRO has an official release
92+
@Disabled
9193
@Test
92-
void googleSearchTool() {
94+
void googleSearchToolPro() {
9395
Prompt prompt = createPrompt(VertexAiGeminiChatOptions.builder()
94-
.model(ChatModel.GEMINI_1_5_PRO) // Only the pro model supports the google
95-
// search tool
96+
.model(ChatModel.GEMINI_2_5_PRO)
9697
.googleSearchRetrieval(true)
9798
.build());
9899
ChatResponse response = this.chatModel.call(prompt);
99100
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
100101
}
101102

103+
@Test
104+
void googleSearchToolFlash() {
105+
Prompt prompt = createPrompt(VertexAiGeminiChatOptions.builder()
106+
.model(ChatModel.GEMINI_2_0_FLASH)
107+
.googleSearchRetrieval(true)
108+
.build());
109+
ChatResponse response = this.chatModel.call(prompt);
110+
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew", "Bob");
111+
}
112+
102113
@Test
103114
@Disabled
104115
void testSafetySettings() {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
<djl.version>0.30.0</djl.version>
269269
<onnxruntime.version>1.19.2</onnxruntime.version>
270270
<oci-sdk-version>3.51.0</oci-sdk-version>
271-
<com.google.cloud.version>26.48.0</com.google.cloud.version>
271+
<com.google.cloud.version>26.59.0</com.google.cloud.version>
272272
<ibm.sdk.version>9.20.0</ibm.sdk.version>
273273
<jsonschema.version>4.37.0</jsonschema.version>
274274
<swagger-annotations.version>2.2.25</swagger-annotations.version>

0 commit comments

Comments
 (0)