Skip to content
Merged
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
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 the original author or authors.
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,12 +46,13 @@
*
* @author Grogdunn
* @author Christian Tzolov
* @author Soby Chacko
* @since 1.0.0
*/
public final class MergeUtils {

private static final Class<?>[] CHAT_COMPLETIONS_CONSTRUCTOR_ARG_TYPES = new Class<?>[] { String.class,
OffsetDateTime.class, List.class, CompletionsUsage.class };
OffsetDateTime.class, List.class };

private static final Class<?>[] chatChoiceConstructorArgumentTypes = new Class<?>[] {
ChatChoiceLogProbabilityInfo.class, int.class, CompletionsFinishReason.class };
Expand All @@ -75,8 +76,7 @@ private MergeUtils() {
*/
private static <T> T newInstance(Class<?>[] argumentTypes, Class<T> clazz, Object... args) {
try {
@SuppressWarnings("unchecked")
Constructor<T> constructor = (Constructor<T>) clazz.getDeclaredConstructor(argumentTypes);
Constructor<T> constructor = clazz.getDeclaredConstructor(argumentTypes);
constructor.setAccessible(true);
return constructor.newInstance(args);
}
Expand Down Expand Up @@ -108,10 +108,9 @@ private static void setField(Object classInstance, String fieldName, Object fiel
public static ChatCompletions emptyChatCompletions() {
String id = null;
List<ChatChoice> choices = new ArrayList<>();
CompletionsUsage usage = null;
OffsetDateTime createdAt = OffsetDateTime.now();
ChatCompletions chatCompletionsInstance = newInstance(CHAT_COMPLETIONS_CONSTRUCTOR_ARG_TYPES,
ChatCompletions.class, id, createdAt, choices, usage);
ChatCompletions.class, id, createdAt, choices);
List<ContentFilterResultsForPrompt> promptFilterResults = new ArrayList<>();
setField(chatCompletionsInstance, "promptFilterResults", promptFilterResults);
String systemFingerprint = null;
Expand Down Expand Up @@ -157,7 +156,7 @@ public static ChatCompletions mergeChatCompletions(ChatCompletions left, ChatCom
: right.getCreatedAt();

ChatCompletions instance = newInstance(CHAT_COMPLETIONS_CONSTRUCTOR_ARG_TYPES, ChatCompletions.class, id,
createdAt, choices, usage);
createdAt, choices);

List<ContentFilterResultsForPrompt> promptFilterResults = right.getPromptFilterResults() == null
? left.getPromptFilterResults() : right.getPromptFilterResults();
Expand All @@ -166,6 +165,9 @@ public static ChatCompletions mergeChatCompletions(ChatCompletions left, ChatCom
String systemFingerprint = right.getSystemFingerprint() == null ? left.getSystemFingerprint()
: right.getSystemFingerprint();
setField(instance, "systemFingerprint", systemFingerprint);

setField(instance, "usage", usage);

return instance;
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
<!-- production dependencies -->
<spring-boot.version>3.4.4</spring-boot.version>
<ST4.version>4.3.4</ST4.version>
<azure-open-ai-client.version>1.0.0-beta.14</azure-open-ai-client.version>
<azure-open-ai-client.version>1.0.0-beta.16</azure-open-ai-client.version>
<jtokkit.version>1.1.0</jtokkit.version>
<victools.version>4.37.0</victools.version>
<kotlin.version>1.9.25</kotlin.version>
Expand Down