This issue reports a discrepancy in the format of the SafetyRating protobuf field within the GenerateContentResponse object. When using the Vertex AI library (google-cloud-vertexai), the SafetyRating field lacks additional information like probabilityScore and severityScore present in the actual response by the GenerativeModel
The following sections detail the steps to reproduce the issue, provide environment information, and include code examples from the Vertex AI library, as well as an example of WebClient usage (with json-formatted request/response) for comparison. Additionally, references to relevant API documentation are provided.
Environment details
Using the google-cloud-vertexai imported with maven com.google.cloud libraries-bom 26.34.0 (see below)
OS type and version: Windows 11
Java version: 21
Steps to reproduce
Instantiate a GenerativeModel object
call the generateContent method
to make a comparison, create a similar request to a WebClient working with json data
Code example
Request made using the google-vertexai library
private static String jsonFilePath = ""; // the path to the authentication json
private static String apiUrl = ""; // see below for further information
@Test
public void example() throws IOException, Descriptors.DescriptorValidationException {
OAuth2Credentials credentials;
credentials = ServiceAccountCredentials
.fromStream(new FileInputStream(jsonFilePath))
.createScoped(Arrays.asList("https://www.googleapis.com/auth/cloud-platform"));
credentials.refreshIfExpired();
try (VertexAI vertexAi = new VertexAI("my-project", "europe-west9", credentials)) {
GenerationConfig generationConfig =
GenerationConfig.newBuilder()
.setMaxOutputTokens(2048)
.setTemperature(0.9F)
.setTopP(1F)
.build();
GenerativeModel model = new GenerativeModel("gemini-1.0-pro", generationConfig, vertexAi);
GenerateContentResponse response = model.generateContent("say Hi!");
System.out.println(response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
This issue reports a discrepancy in the format of the SafetyRating protobuf field within the GenerateContentResponse object. When using the Vertex AI library (google-cloud-vertexai), the SafetyRating field lacks additional information like probabilityScore and severityScore present in the actual response by the GenerativeModel
The following sections detail the steps to reproduce the issue, provide environment information, and include code examples from the Vertex AI library, as well as an example of WebClient usage (with json-formatted request/response) for comparison. Additionally, references to relevant API documentation are provided.
Environment details
Steps to reproduce
Code example
Request made using the google-vertexai library
Response received
Request made using the springboot WebClient
Response received
External references such as API reference guides
I got the apiUrl from this link: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini
Guide to the maven import: https://cloud.google.com/java/docs/reference/google-cloud-vertexai/latest/overview