diff --git a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/MergeUtils.java b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/MergeUtils.java index a832bd58826..969379833b0 100644 --- a/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/MergeUtils.java +++ b/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/MergeUtils.java @@ -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. @@ -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 }; @@ -75,8 +76,7 @@ private MergeUtils() { */ private static T newInstance(Class[] argumentTypes, Class clazz, Object... args) { try { - @SuppressWarnings("unchecked") - Constructor constructor = (Constructor) clazz.getDeclaredConstructor(argumentTypes); + Constructor constructor = clazz.getDeclaredConstructor(argumentTypes); constructor.setAccessible(true); return constructor.newInstance(args); } @@ -108,10 +108,9 @@ private static void setField(Object classInstance, String fieldName, Object fiel public static ChatCompletions emptyChatCompletions() { String id = null; List 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 promptFilterResults = new ArrayList<>(); setField(chatCompletionsInstance, "promptFilterResults", promptFilterResults); String systemFingerprint = null; @@ -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 promptFilterResults = right.getPromptFilterResults() == null ? left.getPromptFilterResults() : right.getPromptFilterResults(); @@ -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; } diff --git a/pom.xml b/pom.xml index ffc21c360df..e4927004b8d 100644 --- a/pom.xml +++ b/pom.xml @@ -256,7 +256,7 @@ 3.4.4 4.3.4 - 1.0.0-beta.14 + 1.0.0-beta.16 1.1.0 4.37.0 1.9.25