Skip to content

Commit dad524c

Browse files
newtorka-d
andauthored
chore: [OpenAI] use code generation (#370)
* Initial * Add fix * Format * Fix version * Disable plugin * Apply latest changes * update plugin ref * Update to SAP Cloud SDK 5.18.0 * Apply update to generated sources --------- Co-authored-by: Alexander Dümont <[email protected]>
1 parent 4af893f commit dad524c

File tree

81 files changed

+4070
-1621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+4070
-1621
lines changed

.pipeline/spotbugs-exclusions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<Package name="com.sap.ai.sdk.orchestration.model"/>
88
<Package name="com.sap.ai.sdk.grounding.client"/>
99
<Package name="com.sap.ai.sdk.grounding.model"/>
10+
<Package name="com.sap.ai.sdk.foundationmodels.openai.generated.model"/>
1011
<Package name="com.sap.ai.sdk.prompt.registry.model"/>
1112
<Package name="com.sap.ai.sdk.prompt.registry.client"/>
1213
</Or>

foundation-models/openai/pom.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,65 @@
132132
<scope>test</scope>
133133
</dependency>
134134
</dependencies>
135+
136+
<profiles>
137+
<profile>
138+
<id>generate</id>
139+
<activation>
140+
<activeByDefault>false</activeByDefault>
141+
<property>
142+
<name>generate</name>
143+
</property>
144+
</activation>
145+
<build>
146+
<plugins>
147+
<plugin>
148+
<groupId>com.sap.cloud.sdk.datamodel</groupId>
149+
<artifactId>openapi-generator-maven-plugin</artifactId>
150+
<configuration>
151+
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
152+
<apiMaturity>beta</apiMaturity>
153+
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
154+
<compileScope>COMPILE</compileScope>
155+
<deleteOutputDirectory>true</deleteOutputDirectory>
156+
</configuration>
157+
<executions>
158+
<execution>
159+
<id>openai</id>
160+
<goals>
161+
<goal>generate</goal>
162+
</goals>
163+
<phase>generate-sources</phase>
164+
<configuration>
165+
<inputSpec>${project.basedir}/src/main/resources/spec/openapi-2024-10-21.yaml</inputSpec>
166+
<apiPackage>com.sap.ai.sdk.foundationmodels.openai.generated.api</apiPackage>
167+
<modelPackage>com.sap.ai.sdk.foundationmodels.openai.generated.model</modelPackage>
168+
<generateApis>false</generateApis>
169+
<additionalProperties>
170+
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
171+
<useOneOfInterfaces>true</useOneOfInterfaces>
172+
<useOneOfCreators>true</useOneOfCreators>
173+
<useFloatArrays>true</useFloatArrays>
174+
175+
<!-- new exclude paths -->
176+
<excludePaths>/deployments/{deployment-id}/completions
177+
/deployments/{deployment-id}/audio/transcriptions
178+
/deployments/{deployment-id}/audio/translations
179+
/deployments/{deployment-id}/images/generations</excludePaths>
180+
181+
<!-- new exclude properties -->
182+
<excludeProperties>chatCompletionResponseMessage.context
183+
createChatCompletionRequest.data_sources</excludeProperties>
184+
185+
<!-- new: remove unassigned components -->
186+
<removeUnusedComponents>true</removeUnusedComponents>
187+
</additionalProperties>
188+
</configuration>
189+
</execution>
190+
</executions>
191+
</plugin>
192+
</plugins>
193+
</build>
194+
</profile>
195+
</profiles>
135196
</project>

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/generated/model/ChatCompletionFunctionCall.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
/*
2-
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3-
*/
4-
51
/*
62
* Azure OpenAI Service API
73
* Azure OpenAI APIs for completions and search
84
*
9-
* The version of the OpenAPI document: 2024-10-21
105
*
116
*
127
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -20,6 +15,7 @@
2015
import com.fasterxml.jackson.annotation.JsonAnySetter;
2116
import com.fasterxml.jackson.annotation.JsonIgnore;
2217
import com.fasterxml.jackson.annotation.JsonProperty;
18+
import com.google.common.annotations.Beta;
2319
import java.util.LinkedHashMap;
2420
import java.util.Map;
2521
import java.util.NoSuchElementException;
@@ -32,8 +28,7 @@
3228
* Deprecated and replaced by &#x60;tool_calls&#x60;. The name and arguments of a function that
3329
* should be called, as generated by the model.
3430
*/
35-
// CHECKSTYLE:OFF
36-
@com.google.common.annotations.Beta
31+
@Beta // CHECKSTYLE:OFF
3732
public class ChatCompletionFunctionCall
3833
// CHECKSTYLE:ON
3934
{
@@ -132,11 +127,13 @@ public Set<String> getCustomFieldNames() {
132127
* Get the value of an unrecognizable property of this {@link ChatCompletionFunctionCall}
133128
* instance.
134129
*
130+
* @deprecated Use {@link #toMap()} instead.
135131
* @param name The name of the property
136132
* @return The value of the property
137133
* @throws NoSuchElementException If no property with the given name could be found.
138134
*/
139135
@Nullable
136+
@Deprecated
140137
public Object getCustomField(@Nonnull final String name) throws NoSuchElementException {
141138
if (!cloudSdkCustomFields.containsKey(name)) {
142139
throw new NoSuchElementException(
@@ -145,6 +142,21 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc
145142
return cloudSdkCustomFields.get(name);
146143
}
147144

145+
/**
146+
* Get the value of all properties of this {@link ChatCompletionFunctionCall} instance including
147+
* unrecognized properties.
148+
*
149+
* @return The map of all properties
150+
*/
151+
@JsonIgnore
152+
@Nonnull
153+
public Map<String, Object> toMap() {
154+
final Map<String, Object> declaredFields = new LinkedHashMap<>(cloudSdkCustomFields);
155+
if (name != null) declaredFields.put("name", name);
156+
if (arguments != null) declaredFields.put("arguments", arguments);
157+
return declaredFields;
158+
}
159+
148160
/**
149161
* Set an unrecognizable property of this {@link ChatCompletionFunctionCall} instance. If the map
150162
* previously contained a mapping for the key, the old value is replaced by the specified value.
@@ -158,7 +170,7 @@ public void setCustomField(@Nonnull String customFieldName, @Nullable Object cus
158170
}
159171

160172
@Override
161-
public boolean equals(@Nullable final Object o) {
173+
public boolean equals(@Nullable final java.lang.Object o) {
162174
if (this == o) {
163175
return true;
164176
}
@@ -194,7 +206,7 @@ public String toString() {
194206
/**
195207
* Convert the given object to string with each line indented by 4 spaces (except the first line).
196208
*/
197-
private String toIndentedString(final Object o) {
209+
private String toIndentedString(final java.lang.Object o) {
198210
if (o == null) {
199211
return "null";
200212
}

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/generated/model/ChatCompletionFunctionCallOption.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
/*
2-
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3-
*/
4-
51
/*
62
* Azure OpenAI Service API
73
* Azure OpenAI APIs for completions and search
84
*
9-
* The version of the OpenAPI document: 2024-10-21
105
*
116
*
127
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -20,6 +15,7 @@
2015
import com.fasterxml.jackson.annotation.JsonAnySetter;
2116
import com.fasterxml.jackson.annotation.JsonIgnore;
2217
import com.fasterxml.jackson.annotation.JsonProperty;
18+
import com.google.common.annotations.Beta;
2319
import java.util.LinkedHashMap;
2420
import java.util.Map;
2521
import java.util.NoSuchElementException;
@@ -32,8 +28,7 @@
3228
* Specifying a particular function via &#x60;{\&quot;name\&quot;: \&quot;my_function\&quot;}&#x60;
3329
* forces the model to call that function.
3430
*/
35-
// CHECKSTYLE:OFF
36-
@com.google.common.annotations.Beta
31+
@Beta // CHECKSTYLE:OFF
3732
public class ChatCompletionFunctionCallOption
3833
// CHECKSTYLE:ON
3934
{
@@ -90,11 +85,13 @@ public Set<String> getCustomFieldNames() {
9085
* Get the value of an unrecognizable property of this {@link ChatCompletionFunctionCallOption}
9186
* instance.
9287
*
88+
* @deprecated Use {@link #toMap()} instead.
9389
* @param name The name of the property
9490
* @return The value of the property
9591
* @throws NoSuchElementException If no property with the given name could be found.
9692
*/
9793
@Nullable
94+
@Deprecated
9895
public Object getCustomField(@Nonnull final String name) throws NoSuchElementException {
9996
if (!cloudSdkCustomFields.containsKey(name)) {
10097
throw new NoSuchElementException(
@@ -103,6 +100,20 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc
103100
return cloudSdkCustomFields.get(name);
104101
}
105102

103+
/**
104+
* Get the value of all properties of this {@link ChatCompletionFunctionCallOption} instance
105+
* including unrecognized properties.
106+
*
107+
* @return The map of all properties
108+
*/
109+
@JsonIgnore
110+
@Nonnull
111+
public Map<String, Object> toMap() {
112+
final Map<String, Object> declaredFields = new LinkedHashMap<>(cloudSdkCustomFields);
113+
if (name != null) declaredFields.put("name", name);
114+
return declaredFields;
115+
}
116+
106117
/**
107118
* Set an unrecognizable property of this {@link ChatCompletionFunctionCallOption} instance. If
108119
* the map previously contained a mapping for the key, the old value is replaced by the specified
@@ -117,7 +128,7 @@ public void setCustomField(@Nonnull String customFieldName, @Nullable Object cus
117128
}
118129

119130
@Override
120-
public boolean equals(@Nullable final Object o) {
131+
public boolean equals(@Nullable final java.lang.Object o) {
121132
if (this == o) {
122133
return true;
123134
}
@@ -152,7 +163,7 @@ public String toString() {
152163
/**
153164
* Convert the given object to string with each line indented by 4 spaces (except the first line).
154165
*/
155-
private String toIndentedString(final Object o) {
166+
private String toIndentedString(final java.lang.Object o) {
156167
if (o == null) {
157168
return "null";
158169
}

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/generated/model/ChatCompletionFunctions.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
/*
2-
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3-
*/
4-
51
/*
62
* Azure OpenAI Service API
73
* Azure OpenAI APIs for completions and search
84
*
9-
* The version of the OpenAPI document: 2024-10-21
105
*
116
*
127
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -20,6 +15,7 @@
2015
import com.fasterxml.jackson.annotation.JsonAnySetter;
2116
import com.fasterxml.jackson.annotation.JsonIgnore;
2217
import com.fasterxml.jackson.annotation.JsonProperty;
18+
import com.google.common.annotations.Beta;
2319
import java.util.HashMap;
2420
import java.util.LinkedHashMap;
2521
import java.util.Map;
@@ -35,8 +31,7 @@
3531
* @deprecated
3632
*/
3733
@Deprecated
38-
// CHECKSTYLE:OFF
39-
@com.google.common.annotations.Beta
34+
@Beta // CHECKSTYLE:OFF
4035
public class ChatCompletionFunctions
4136
// CHECKSTYLE:ON
4237
{
@@ -198,11 +193,13 @@ public Set<String> getCustomFieldNames() {
198193
/**
199194
* Get the value of an unrecognizable property of this {@link ChatCompletionFunctions} instance.
200195
*
196+
* @deprecated Use {@link #toMap()} instead.
201197
* @param name The name of the property
202198
* @return The value of the property
203199
* @throws NoSuchElementException If no property with the given name could be found.
204200
*/
205201
@Nullable
202+
@Deprecated
206203
public Object getCustomField(@Nonnull final String name) throws NoSuchElementException {
207204
if (!cloudSdkCustomFields.containsKey(name)) {
208205
throw new NoSuchElementException(
@@ -211,6 +208,22 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc
211208
return cloudSdkCustomFields.get(name);
212209
}
213210

211+
/**
212+
* Get the value of all properties of this {@link ChatCompletionFunctions} instance including
213+
* unrecognized properties.
214+
*
215+
* @return The map of all properties
216+
*/
217+
@JsonIgnore
218+
@Nonnull
219+
public Map<String, Object> toMap() {
220+
final Map<String, Object> declaredFields = new LinkedHashMap<>(cloudSdkCustomFields);
221+
if (description != null) declaredFields.put("description", description);
222+
if (name != null) declaredFields.put("name", name);
223+
if (parameters != null) declaredFields.put("parameters", parameters);
224+
return declaredFields;
225+
}
226+
214227
/**
215228
* Set an unrecognizable property of this {@link ChatCompletionFunctions} instance. If the map
216229
* previously contained a mapping for the key, the old value is replaced by the specified value.
@@ -224,7 +237,7 @@ public void setCustomField(@Nonnull String customFieldName, @Nullable Object cus
224237
}
225238

226239
@Override
227-
public boolean equals(@Nullable final Object o) {
240+
public boolean equals(@Nullable final java.lang.Object o) {
228241
if (this == o) {
229242
return true;
230243
}
@@ -261,7 +274,7 @@ public String toString() {
261274
/**
262275
* Convert the given object to string with each line indented by 4 spaces (except the first line).
263276
*/
264-
private String toIndentedString(final Object o) {
277+
private String toIndentedString(final java.lang.Object o) {
265278
if (o == null) {
266279
return "null";
267280
}

0 commit comments

Comments
 (0)