|
20 | 20 | import java.util.Collection;
|
21 | 21 | import java.util.List;
|
22 | 22 | import java.util.Map;
|
| 23 | +import java.util.stream.Collectors; |
23 | 24 |
|
24 | 25 | import com.fasterxml.jackson.annotation.JsonInclude;
|
25 | 26 | import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
@@ -587,35 +588,27 @@ protected List<Generation> responseCandidateToGeneration(Candidate candidate) {
|
587 | 588 | .finishReason(candidateFinishReason.name())
|
588 | 589 | .build();
|
589 | 590 |
|
590 |
| - boolean isFunctionCall = candidate.getContent().getPartsList().stream().allMatch(Part::hasFunctionCall); |
591 |
| - |
592 |
| - if (isFunctionCall) { |
593 |
| - List<AssistantMessage.ToolCall> assistantToolCalls = candidate.getContent() |
594 |
| - .getPartsList() |
595 |
| - .stream() |
596 |
| - .filter(part -> part.hasFunctionCall()) |
597 |
| - .map(part -> { |
598 |
| - FunctionCall functionCall = part.getFunctionCall(); |
599 |
| - var functionName = functionCall.getName(); |
600 |
| - String functionArguments = structToJson(functionCall.getArgs()); |
601 |
| - return new AssistantMessage.ToolCall("", "function", functionName, functionArguments); |
602 |
| - }) |
603 |
| - .toList(); |
| 591 | + var assistantToolCalls = candidate.getContent() |
| 592 | + .getPartsList() |
| 593 | + .stream() |
| 594 | + .filter(Part::hasFunctionCall) |
| 595 | + .map(part -> { |
| 596 | + FunctionCall functionCall = part.getFunctionCall(); |
| 597 | + var functionName = functionCall.getName(); |
| 598 | + String functionArguments = structToJson(functionCall.getArgs()); |
| 599 | + return new AssistantMessage.ToolCall("", "function", functionName, functionArguments); |
| 600 | + }) |
| 601 | + .toList(); |
604 | 602 |
|
605 |
| - AssistantMessage assistantMessage = new AssistantMessage("", messageMetadata, assistantToolCalls); |
| 603 | + var text = candidate.getContent() |
| 604 | + .getPartsList() |
| 605 | + .stream() |
| 606 | + .filter(Part::hasText) |
| 607 | + .map(Part::getText) |
| 608 | + .collect(Collectors.joining(System.lineSeparator())); |
606 | 609 |
|
607 |
| - return List.of(new Generation(assistantMessage, chatGenerationMetadata)); |
608 |
| - } |
609 |
| - else { |
610 |
| - List<Generation> generations = candidate.getContent() |
611 |
| - .getPartsList() |
612 |
| - .stream() |
613 |
| - .map(part -> new AssistantMessage(part.getText(), messageMetadata)) |
614 |
| - .map(assistantMessage -> new Generation(assistantMessage, chatGenerationMetadata)) |
615 |
| - .toList(); |
616 |
| - |
617 |
| - return generations; |
618 |
| - } |
| 610 | + return List.of(new Generation(new AssistantMessage(text, messageMetadata, assistantToolCalls), |
| 611 | + chatGenerationMetadata)); |
619 | 612 | }
|
620 | 613 |
|
621 | 614 | private ChatResponseMetadata toChatResponseMetadata(Usage usage) {
|
|
0 commit comments