Skip to content

Commit 3756e16

Browse files
sobychackomarkpollack
authored andcommitted
Upgrade azure-open-ai-client to 1.0.0-beta.16
Adjust MergeUtils to accommodate API changes: - Update ChatCompletions constructor parameter list to remove the usage argument - Move usage assignment to post-construction via reflection Signed-off-by: Soby Chacko <[email protected]>
1 parent 6e0c098 commit 3756e16

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/MergeUtils.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -46,12 +46,13 @@
4646
*
4747
* @author Grogdunn
4848
* @author Christian Tzolov
49+
* @author Soby Chacko
4950
* @since 1.0.0
5051
*/
5152
public 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

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
<!-- production dependencies -->
257257
<spring-boot.version>3.4.4</spring-boot.version>
258258
<ST4.version>4.3.4</ST4.version>
259-
<azure-open-ai-client.version>1.0.0-beta.14</azure-open-ai-client.version>
259+
<azure-open-ai-client.version>1.0.0-beta.16</azure-open-ai-client.version>
260260
<jtokkit.version>1.1.0</jtokkit.version>
261261
<victools.version>4.37.0</victools.version>
262262
<kotlin.version>1.9.25</kotlin.version>

0 commit comments

Comments
 (0)