Skip to content
Closed
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 @@ -1075,14 +1075,20 @@ private static Delta mergeDeltas(Delta left, Delta right) {
}
Assert.isTrue(tcs2.size() == 1, "no more than one tool call per message currently supported");
ToolCall toolCall = tcs2.get(0);
if (toolCall.id().isPresent()) {
if (toolCall.id().filter(id -> !id.isEmpty()).isPresent()) {
List<ToolCall> result = new ArrayList<>(tcs1);
result.add(toolCall);
return result;
}
else {
if (tcs1.isEmpty()) {
List<ToolCall> result = new ArrayList<>();
result.add(toolCall);
return result;
}
ToolCall lastFromTc1 = tcs1.get(tcs1.size() - 1);
Function lastFromTc1F = lastFromTc1.function().get();
Function lastFromTc1F = lastFromTc1.function()
.orElseGet(() -> Function.builder().build());

var concatenatedArgs = Stream
.of(lastFromTc1F.arguments(), toolCall.function().flatMap(Function::arguments))
Expand Down Expand Up @@ -1131,17 +1137,21 @@ static ChatCompletion chunkToChatCompletion(ChatCompletionChunk chunk) {

ChatCompletionMessage.Builder msgBuilder = ChatCompletionMessage.builder()
.content(cccc.delta().content())
.refusal(cccc.delta().refusal());
.refusal(cccc.delta().refusal())
.putAllAdditionalProperties(cccc.delta()._additionalProperties());
cccc.delta().toolCalls().ifPresent(ccctcs -> {
msgBuilder.toolCalls(ccctcs.stream().map(tc -> {
ChatCompletionMessageFunctionToolCall.Builder toolCallBuilder = ChatCompletionMessageFunctionToolCall
.builder();
toolCallBuilder.putAllAdditionalProperties(tc._additionalProperties());
toolCallBuilder.id(tc.id().get());
toolCallBuilder.function(ChatCompletionMessageFunctionToolCall.Function.builder()
.name(tc.function().get().name().get())
.arguments(tc.function().get().arguments().get())
.build());
toolCallBuilder.id(tc.id().orElse(""));
ChatCompletionMessageFunctionToolCall.Function.Builder funcBuilder = ChatCompletionMessageFunctionToolCall.Function
.builder();
tc.function().ifPresent(f -> {
funcBuilder.name(f.name().orElse(""));
funcBuilder.arguments(f.arguments().orElse(""));
});
toolCallBuilder.function(funcBuilder.build());
return ChatCompletionMessageToolCall.ofFunction(toolCallBuilder.build());
}).toList());
});
Expand Down