1
1
/*
2
- * Copyright 2023-2024 the original author or authors.
2
+ * Copyright 2023-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
46
46
*
47
47
* @author Grogdunn
48
48
* @author Christian Tzolov
49
+ * @author Soby Chacko
49
50
* @since 1.0.0
50
51
*/
51
52
public final class MergeUtils {
52
53
53
54
private static final Class <?>[] CHAT_COMPLETIONS_CONSTRUCTOR_ARG_TYPES = new Class <?>[] { String .class ,
54
- OffsetDateTime .class , List .class , CompletionsUsage . class };
55
+ OffsetDateTime .class , List .class };
55
56
56
57
private static final Class <?>[] chatChoiceConstructorArgumentTypes = new Class <?>[] {
57
58
ChatChoiceLogProbabilityInfo .class , int .class , CompletionsFinishReason .class };
@@ -75,8 +76,7 @@ private MergeUtils() {
75
76
*/
76
77
private static <T > T newInstance (Class <?>[] argumentTypes , Class <T > clazz , Object ... args ) {
77
78
try {
78
- @ SuppressWarnings ("unchecked" )
79
- Constructor <T > constructor = (Constructor <T >) clazz .getDeclaredConstructor (argumentTypes );
79
+ Constructor <T > constructor = clazz .getDeclaredConstructor (argumentTypes );
80
80
constructor .setAccessible (true );
81
81
return constructor .newInstance (args );
82
82
}
@@ -108,10 +108,9 @@ private static void setField(Object classInstance, String fieldName, Object fiel
108
108
public static ChatCompletions emptyChatCompletions () {
109
109
String id = null ;
110
110
List <ChatChoice > choices = new ArrayList <>();
111
- CompletionsUsage usage = null ;
112
111
OffsetDateTime createdAt = OffsetDateTime .now ();
113
112
ChatCompletions chatCompletionsInstance = newInstance (CHAT_COMPLETIONS_CONSTRUCTOR_ARG_TYPES ,
114
- ChatCompletions .class , id , createdAt , choices , usage );
113
+ ChatCompletions .class , id , createdAt , choices );
115
114
List <ContentFilterResultsForPrompt > promptFilterResults = new ArrayList <>();
116
115
setField (chatCompletionsInstance , "promptFilterResults" , promptFilterResults );
117
116
String systemFingerprint = null ;
@@ -157,7 +156,7 @@ public static ChatCompletions mergeChatCompletions(ChatCompletions left, ChatCom
157
156
: right .getCreatedAt ();
158
157
159
158
ChatCompletions instance = newInstance (CHAT_COMPLETIONS_CONSTRUCTOR_ARG_TYPES , ChatCompletions .class , id ,
160
- createdAt , choices , usage );
159
+ createdAt , choices );
161
160
162
161
List <ContentFilterResultsForPrompt > promptFilterResults = right .getPromptFilterResults () == null
163
162
? left .getPromptFilterResults () : right .getPromptFilterResults ();
@@ -166,6 +165,9 @@ public static ChatCompletions mergeChatCompletions(ChatCompletions left, ChatCom
166
165
String systemFingerprint = right .getSystemFingerprint () == null ? left .getSystemFingerprint ()
167
166
: right .getSystemFingerprint ();
168
167
setField (instance , "systemFingerprint" , systemFingerprint );
168
+
169
+ setField (instance , "usage" , usage );
170
+
169
171
return instance ;
170
172
}
171
173
0 commit comments