Skip to content

Fixes #2185 googleSearchRetrieval(true) causes INVALID_ARGUMENT error with Gemini 2.0 (use google_search instead) #2755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.ai.vertexai.gemini;

import com.google.cloud.vertexai.api.Tool.GoogleSearch;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -713,10 +714,8 @@ GeminiRequest createGeminiRequest(Prompt prompt) {
}

if (prompt.getOptions() instanceof VertexAiGeminiChatOptions options && options.getGoogleSearchRetrieval()) {
final var googleSearchRetrieval = GoogleSearchRetrieval.newBuilder().getDefaultInstanceForType();
final var googleSearchRetrievalTool = Tool.newBuilder()
.setGoogleSearchRetrieval(googleSearchRetrieval)
.build();
var googleSearch = GoogleSearch.newBuilder().getDefaultInstanceForType();
final var googleSearchRetrievalTool = Tool.newBuilder().setGoogleSearch(googleSearch).build();
tools.add(googleSearchRetrievalTool);
}

Expand Down Expand Up @@ -969,7 +968,7 @@ public enum ChatModel implements ChatModelDescription {

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

GEMINI_2_5_PRO("gemini-2.5-pro-exp-03-28");
GEMINI_2_5_PRO("gemini-2.5-pro-exp-03-25");

public final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,28 @@ void testMessageHistory() {
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
}

// Test disabled until Gemini 2.5 PRO has an official release
@Disabled
@Test
void googleSearchTool() {
void googleSearchToolPro() {
Prompt prompt = createPrompt(VertexAiGeminiChatOptions.builder()
.model(ChatModel.GEMINI_1_5_PRO) // Only the pro model supports the google
// search tool
.model(ChatModel.GEMINI_2_5_PRO)
.googleSearchRetrieval(true)
.build());
ChatResponse response = this.chatModel.call(prompt);
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew");
}

@Test
void googleSearchToolFlash() {
Prompt prompt = createPrompt(VertexAiGeminiChatOptions.builder()
.model(ChatModel.GEMINI_2_0_FLASH)
.googleSearchRetrieval(true)
.build());
ChatResponse response = this.chatModel.call(prompt);
assertThat(response.getResult().getOutput().getText()).containsAnyOf("Blackbeard", "Bartholomew", "Bob");
}

@Test
@Disabled
void testSafetySettings() {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<djl.version>0.30.0</djl.version>
<onnxruntime.version>1.19.2</onnxruntime.version>
<oci-sdk-version>3.51.0</oci-sdk-version>
<com.google.cloud.version>26.48.0</com.google.cloud.version>
<com.google.cloud.version>26.59.0</com.google.cloud.version>
<ibm.sdk.version>9.20.0</ibm.sdk.version>
<jsonschema.version>4.37.0</jsonschema.version>
<swagger-annotations.version>2.2.25</swagger-annotations.version>
Expand Down