11/* 
2-  * Copyright 2023-2024  the original author or authors. 
2+  * Copyright 2023-2025  the original author or authors. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); 
55 * you may not use this file except in compliance with the License. 
4646 * 
4747 * @author Grogdunn 
4848 * @author Christian Tzolov 
49+  * @author Soby Chacko 
4950 * @since 1.0.0 
5051 */ 
5152public  final  class  MergeUtils  {
5253
5354	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  };
5556
5657	private  static  final  Class <?>[] chatChoiceConstructorArgumentTypes  = new  Class <?>[] {
5758			ChatChoiceLogProbabilityInfo .class , int .class , CompletionsFinishReason .class  };
@@ -75,8 +76,7 @@ private MergeUtils() {
7576	 */ 
7677	private  static  <T > T  newInstance (Class <?>[] argumentTypes , Class <T > clazz , Object ... args ) {
7778		try  {
78- 			@ SuppressWarnings ("unchecked" )
79- 			Constructor <T > constructor  = (Constructor <T >) clazz .getDeclaredConstructor (argumentTypes );
79+ 			Constructor <T > constructor  = clazz .getDeclaredConstructor (argumentTypes );
8080			constructor .setAccessible (true );
8181			return  constructor .newInstance (args );
8282		}
@@ -108,10 +108,9 @@ private static void setField(Object classInstance, String fieldName, Object fiel
108108	public  static  ChatCompletions  emptyChatCompletions () {
109109		String  id  = null ;
110110		List <ChatChoice > choices  = new  ArrayList <>();
111- 		CompletionsUsage  usage  = null ;
112111		OffsetDateTime  createdAt  = OffsetDateTime .now ();
113112		ChatCompletions  chatCompletionsInstance  = newInstance (CHAT_COMPLETIONS_CONSTRUCTOR_ARG_TYPES ,
114- 				ChatCompletions .class , id , createdAt , choices ,  usage );
113+ 				ChatCompletions .class , id , createdAt , choices );
115114		List <ContentFilterResultsForPrompt > promptFilterResults  = new  ArrayList <>();
116115		setField (chatCompletionsInstance , "promptFilterResults" , promptFilterResults );
117116		String  systemFingerprint  = null ;
@@ -157,7 +156,7 @@ public static ChatCompletions mergeChatCompletions(ChatCompletions left, ChatCom
157156				: right .getCreatedAt ();
158157
159158		ChatCompletions  instance  = newInstance (CHAT_COMPLETIONS_CONSTRUCTOR_ARG_TYPES , ChatCompletions .class , id ,
160- 				createdAt , choices ,  usage );
159+ 				createdAt , choices );
161160
162161		List <ContentFilterResultsForPrompt > promptFilterResults  = right .getPromptFilterResults () == null 
163162				? left .getPromptFilterResults () : right .getPromptFilterResults ();
@@ -166,6 +165,9 @@ public static ChatCompletions mergeChatCompletions(ChatCompletions left, ChatCom
166165		String  systemFingerprint  = right .getSystemFingerprint () == null  ? left .getSystemFingerprint ()
167166				: right .getSystemFingerprint ();
168167		setField (instance , "systemFingerprint" , systemFingerprint );
168+ 
169+ 		setField (instance , "usage" , usage );
170+ 
169171		return  instance ;
170172	}
171173
0 commit comments