Skip to content

Commit 4404dbe

Browse files
authored
Adding service_tier for request and response ChatCompletions (Azure#44719)
* Adding service_tier for request and response ChatCompletions * Alternative spelling * Removed generated annotation
1 parent 991ff43 commit 4404dbe

File tree

5 files changed

+160
-4
lines changed

5 files changed

+160
-4
lines changed

sdk/openai/azure-ai-openai/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- Added `ServiceTier` and `ServiceTierOptions` for `ChatCompletions` and `ChatCompletionsOptions` respectively. This is exclusively a non-Azure OpenAI issue and was requested in [this issue](https://github.com/Azure/azure-sdk-for-java/issues/41695#issuecomment-2736037879).
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatCompletions.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public final class ChatCompletions implements JsonSerializable<ChatCompletions>
4343
@Generated
4444
private final CompletionsUsage usage;
4545

46+
private ServiceTier serviceTier;
47+
4648
/**
4749
* Get the id property: A unique identifier associated with this chat completions response.
4850
*
@@ -95,6 +97,15 @@ public OffsetDateTime getCreatedAt() {
9597
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.createdAt), ZoneOffset.UTC);
9698
}
9799

100+
/**
101+
* This field is not available in Azure OpenAI. The service tier used for processing the request.
102+
*
103+
* @return the serviceTier value.
104+
*/
105+
public ServiceTier getServiceTier() {
106+
return serviceTier;
107+
}
108+
98109
/*
99110
* Content filtering results for zero or more prompts in the request. In a streaming request,
100111
* results for different prompts may arrive at different times or in different orders.
@@ -173,7 +184,6 @@ public String getModel() {
173184
/**
174185
* {@inheritDoc}
175186
*/
176-
@Generated
177187
@Override
178188
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
179189
jsonWriter.writeStartObject();
@@ -185,6 +195,9 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
185195
jsonWriter.writeArrayField("prompt_filter_results", this.promptFilterResults,
186196
(writer, element) -> writer.writeJson(element));
187197
jsonWriter.writeStringField("system_fingerprint", this.systemFingerprint);
198+
if (this.serviceTier != null) {
199+
jsonWriter.writeStringField("service_tier", this.serviceTier.toString());
200+
}
188201
return jsonWriter.writeEndObject();
189202
}
190203

@@ -197,7 +210,6 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
197210
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
198211
* @throws IOException If an error occurs while reading the ChatCompletions.
199212
*/
200-
@Generated
201213
public static ChatCompletions fromJson(JsonReader jsonReader) throws IOException {
202214
return jsonReader.readObject(reader -> {
203215
String id = null;
@@ -206,6 +218,7 @@ public static ChatCompletions fromJson(JsonReader jsonReader) throws IOException
206218
CompletionsUsage usage = null;
207219
String model = null;
208220
List<ContentFilterResultsForPrompt> promptFilterResults = null;
221+
ServiceTier serviceTier = null;
209222
String systemFingerprint = null;
210223
while (reader.nextToken() != JsonToken.END_OBJECT) {
211224
String fieldName = reader.getFieldName();
@@ -224,6 +237,8 @@ public static ChatCompletions fromJson(JsonReader jsonReader) throws IOException
224237
promptFilterResults = reader.readArray(reader1 -> ContentFilterResultsForPrompt.fromJson(reader1));
225238
} else if ("system_fingerprint".equals(fieldName)) {
226239
systemFingerprint = reader.getString();
240+
} else if ("service_tier".equals(fieldName)) {
241+
serviceTier = ServiceTier.fromString(reader.getString());
227242
} else {
228243
reader.skipChildren();
229244
}
@@ -232,6 +247,7 @@ public static ChatCompletions fromJson(JsonReader jsonReader) throws IOException
232247
deserializedChatCompletions.model = model;
233248
deserializedChatCompletions.promptFilterResults = promptFilterResults;
234249
deserializedChatCompletions.systemFingerprint = systemFingerprint;
250+
deserializedChatCompletions.serviceTier = serviceTier;
235251
return deserializedChatCompletions;
236252
});
237253
}

sdk/openai/azure-ai-openai/src/main/java/com/azure/ai/openai/models/ChatCompletionsOptions.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ public final class ChatCompletionsOptions implements JsonSerializable<ChatComple
221221
@Generated
222222
private Boolean parallelToolCalls;
223223

224+
/*
225+
* This field is not available in Azure OpenAI. Specifies the latency tier to use for processing the request.
226+
*/
227+
private ServiceTierOptions serviceTierOptions;
228+
224229
/**
225230
* Creates an instance of ChatCompletionsOptions class.
226231
*
@@ -903,10 +908,29 @@ public ChatCompletionsOptions setParallelToolCalls(Boolean parallelToolCalls) {
903908
return this;
904909
}
905910

911+
/**
912+
* Get the {@link ServiceTierOptions} for this request.
913+
*
914+
* @return the {@link ServiceTierOptions} value.
915+
*/
916+
public ServiceTierOptions getServiceTierOptions() {
917+
return this.serviceTierOptions;
918+
}
919+
920+
/**
921+
* Set the {@link ServiceTierOptions} for this request.
922+
*
923+
* @param serviceTierOptions the {@link ServiceTierOptions} value to set.
924+
* @return the ChatCompletionsOptions object itself.
925+
*/
926+
public ChatCompletionsOptions setServiceTierOptions(ServiceTierOptions serviceTierOptions) {
927+
this.serviceTierOptions = serviceTierOptions;
928+
return this;
929+
}
930+
906931
/**
907932
* {@inheritDoc}
908933
*/
909-
@Generated
910934
@Override
911935
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
912936
jsonWriter.writeStartObject();
@@ -950,6 +974,9 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
950974
(writer, element) -> writer.writeString(element == null ? null : element.toString()));
951975
jsonWriter.writeJsonField("prediction", this.prediction);
952976
jsonWriter.writeJsonField("audio", this.audio);
977+
if (this.serviceTierOptions != null) {
978+
jsonWriter.writeStringField("service_tier", this.serviceTierOptions.toString());
979+
}
953980
return jsonWriter.writeEndObject();
954981
}
955982

@@ -962,7 +989,6 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
962989
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
963990
* @throws IOException If an error occurs while reading the ChatCompletionsOptions.
964991
*/
965-
@Generated
966992
public static ChatCompletionsOptions fromJson(JsonReader jsonReader) throws IOException {
967993
return jsonReader.readObject(reader -> {
968994
List<ChatRequestMessage> messages = null;
@@ -997,6 +1023,7 @@ public static ChatCompletionsOptions fromJson(JsonReader jsonReader) throws IOEx
9971023
List<ChatCompletionModality> modalities = null;
9981024
PredictionContent prediction = null;
9991025
AudioOutputParameters audio = null;
1026+
ServiceTierOptions serviceTierOptions = null;
10001027
while (reader.nextToken() != JsonToken.END_OBJECT) {
10011028
String fieldName = reader.getFieldName();
10021029
reader.nextToken();
@@ -1066,6 +1093,8 @@ public static ChatCompletionsOptions fromJson(JsonReader jsonReader) throws IOEx
10661093
prediction = PredictionContent.fromJson(reader);
10671094
} else if ("audio".equals(fieldName)) {
10681095
audio = AudioOutputParameters.fromJson(reader);
1096+
} else if ("service_tier".equals(fieldName)) {
1097+
serviceTierOptions = ServiceTierOptions.fromString(reader.getString());
10691098
} else {
10701099
reader.skipChildren();
10711100
}
@@ -1102,6 +1131,7 @@ public static ChatCompletionsOptions fromJson(JsonReader jsonReader) throws IOEx
11021131
deserializedChatCompletionsOptions.modalities = modalities;
11031132
deserializedChatCompletionsOptions.prediction = prediction;
11041133
deserializedChatCompletionsOptions.audio = audio;
1134+
deserializedChatCompletionsOptions.serviceTierOptions = serviceTierOptions;
11051135
return deserializedChatCompletionsOptions;
11061136
});
11071137
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.ai.openai.models;
4+
5+
import com.azure.core.util.ExpandableStringEnum;
6+
7+
import java.util.Collection;
8+
9+
/**
10+
* The service tier used for processing the request.
11+
*/
12+
public final class ServiceTier extends ExpandableStringEnum<ServiceTier> {
13+
14+
/**
15+
* Service tier option for scale.
16+
*/
17+
public static final ServiceTier SCALE = fromString("scale");
18+
19+
/**
20+
* Service tier option for default.
21+
*/
22+
public static final ServiceTier DEFAULT = fromString("default");
23+
24+
/**
25+
* Creates a new instance of ServiceTier value.
26+
*
27+
* @deprecated Use the {@link #fromString(String)} factory method.
28+
*/
29+
@Deprecated
30+
public ServiceTier() {
31+
}
32+
33+
/**
34+
* Creates or finds a ServiceTier from its string representation.
35+
*
36+
* @param name a name to look for.
37+
* @return the corresponding ServiceTier.
38+
*/
39+
public static ServiceTier fromString(String name) {
40+
return fromString(name, ServiceTier.class);
41+
}
42+
43+
/**
44+
* Get known ServiceTier values.
45+
*
46+
* @return a collection of known ServiceTier values.
47+
*/
48+
public static Collection<ServiceTier> values() {
49+
return values(ServiceTier.class);
50+
}
51+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
package com.azure.ai.openai.models;
4+
5+
import com.azure.core.util.ExpandableStringEnum;
6+
7+
import java.util.Collection;
8+
9+
/**
10+
* Specifies the latency tier to use for processing the request.
11+
* This parameter is relevant for customers subscribed to the scale tier service:
12+
* - If set to 'auto', and the Project is Scale tier enabled, the system will utilize scale tier credits until they are exhausted.
13+
* - If set to 'auto', and the Project is not Scale tier enabled, the request will be processed using the default service tier with a lower uptime SLA and no latency guaranty.
14+
* - If set to 'default', the request will be processed using the default service tier with a lower uptime SLA and no latency guaranty.
15+
* - When not set, the default behavior is 'auto'.
16+
* When this parameter is set, the response body will include the `service_tier` utilized.
17+
*/
18+
public final class ServiceTierOptions extends ExpandableStringEnum<ServiceTierOptions> {
19+
20+
/**
21+
* Service tier option for auto.
22+
*/
23+
public static final ServiceTierOptions AUTO = fromString("auto");
24+
25+
/**
26+
* Service tier option for default.
27+
*/
28+
public static final ServiceTierOptions DEFAULT = fromString("default");
29+
30+
/**
31+
* Creates a new instance of ServiceTierOptions value.
32+
*
33+
* @deprecated Use the {@link #fromString(String)} factory method.
34+
*/
35+
@Deprecated
36+
public ServiceTierOptions() {
37+
}
38+
39+
/**
40+
* Creates or finds a ServiceTierOptions from its string representation.
41+
*
42+
* @param name a name to look for.
43+
* @return the corresponding ServiceTierOptions.
44+
*/
45+
public static ServiceTierOptions fromString(String name) {
46+
return fromString(name, ServiceTierOptions.class);
47+
}
48+
49+
/**
50+
* Get known ServiceTierOptions values.
51+
*
52+
* @return a collection of known ServiceTierOptions values.
53+
*/
54+
public static Collection<ServiceTierOptions> values() {
55+
return values(ServiceTierOptions.class);
56+
}
57+
}

0 commit comments

Comments
 (0)