Skip to content

Commit

Permalink
fix: [vertexai] modify ResponseHandler.getFunctionCalls to not throw …
Browse files Browse the repository at this point in the history
…for finish reasons (#10909)

PiperOrigin-RevId: 639135803

Co-authored-by: Jaycee Li <jayceeli@google.com>
  • Loading branch information
copybara-service[bot] and jaycee-li authored Jun 3, 2024
1 parent 72a0c1a commit 13a724b
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.cloud.vertexai.generativeai;

import com.google.cloud.vertexai.api.Candidate;
import com.google.cloud.vertexai.api.Candidate.Builder;
import com.google.cloud.vertexai.api.Candidate.FinishReason;
import com.google.cloud.vertexai.api.Citation;
import com.google.cloud.vertexai.api.CitationMetadata;
Expand Down Expand Up @@ -59,14 +58,10 @@ public static String getText(GenerateContentResponse response) {
*
* @param response a {@link com.google.cloud.vertexai.api.GenerateContentResponse} instance
* @return a list of {@link com.google.cloud.vertexai.api.FunctionCall} in the response
* @throws IllegalArgumentException if the response has 0 or more than 1 candidates, or if the
* response is blocked by safety reason or unauthorized citations
* @throws IllegalArgumentException if the response has 0 or more than 1 candidates
*/
public static ImmutableList<FunctionCall> getFunctionCalls(GenerateContentResponse response) {
checkFinishReason(getFinishReason(response));
if (response.getCandidatesCount() == 0) {
return ImmutableList.of();
}
getFinishReason(response);
return response.getCandidates(0).getContent().getPartsList().stream()
.filter((part) -> part.hasFunctionCall())
.map((part) -> part.getFunctionCall())
Expand Down Expand Up @@ -162,7 +157,7 @@ static GenerateContentResponse aggregateStreamIntoResponse(
List<Candidate> aggregatedCandidates = new ArrayList<>();
candidates.forEach(
(index, candidate) -> {
Builder candidateBuilder = candidate.toBuilder();
Candidate.Builder candidateBuilder = candidate.toBuilder();
if (aggregatedContentParts.containsKey(index)) {
candidateBuilder.setContent(
Content.newBuilder()
Expand Down

0 comments on commit 13a724b

Please sign in to comment.