Skip to content

Commit caf40c0

Browse files
committed
Clean up
- Remove Generic fallback deserializer - Beta Annotation on all concrete model classes. - Introduce Mixin to override model annotations - Improve variable naming
1 parent 1d65868 commit caf40c0

Some content is hidden

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

42 files changed

+614
-621
lines changed

orchestration/.openapi-generator-ignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ src/main/AndroidManifest.xml
1717
api/
1818
.openapi-generator/
1919

20-
src/main/java/com/sap/ai/sdk/orchestration/client/model/FilterConfig.java
21-
src/main/java/com/sap/ai/sdk/orchestration/client/model/GroundingModuleConfigConfigFiltersInner.java
20+
2221
src/main/java/com/sap/ai/sdk/orchestration/client/model/LLMModuleResult.java
23-
src/main/java/com/sap/ai/sdk/orchestration/client/model/MaskingProviderConfig.java
2422
src/main/java/com/sap/ai/sdk/orchestration/client/model/ModuleResultsOutputUnmaskingInner.java
25-
src/main/java/com/sap/ai/sdk/orchestration/client/model/TemplateRefTemplateRef.java
26-
src/main/java/com/sap/ai/sdk/orchestration/client/model/TemplatingModuleConfig.java

orchestration/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@
129129
<groupId>javax.annotation</groupId>
130130
<artifactId>javax.annotation-api</artifactId>
131131
</dependency>
132+
<dependency>
133+
<groupId>com.google.guava</groupId>
134+
<artifactId>guava</artifactId>
135+
</dependency>
132136
</dependencies>
133137

134138
<build>
@@ -166,11 +170,12 @@
166170
<configOptions>
167171
<generateBuilders>true</generateBuilders>
168172
<failOnUnknownProperties>false</failOnUnknownProperties>
169-
<hideGenerationTimestamp>false</hideGenerationTimestamp>
173+
<hideGenerationTimestamp>true</hideGenerationTimestamp>
170174
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
171175
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
172176
<useBeanValidation>false</useBeanValidation>
173177
<useOneOfInterfaces>true</useOneOfInterfaces>
178+
<additionalModelTypeAnnotations>@com.google.common.annotations.Beta</additionalModelTypeAnnotations>
174179
</configOptions>
175180
<generateModels>true</generateModels>
176181
<generateSupportingFiles>false</generateSupportingFiles>

orchestration/src/main/java/com/sap/ai/sdk/orchestration/GeneralizedFallbackDeserializer.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

orchestration/src/main/java/com/sap/ai/sdk/orchestration/LLMModuleResultDeserializer.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,30 @@ public LLMModuleResultDeserializer() {
2121
/**
2222
* Deserialize the JSON object into one of the subtypes of the base type.
2323
*
24-
* @param p The JSON parser.
25-
* @param ctxt The deserialization context.
24+
* @param parser The JSON parser.
25+
* @param context The deserialization context.
2626
* @return The deserialized object.
2727
* @throws IOException If an I/O error occurs.
2828
*/
2929
@Override
30-
public LLMModuleResult deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
30+
public LLMModuleResult deserialize(JsonParser parser, DeserializationContext context)
31+
throws IOException {
3132

3233
// Check if the target type is a concrete class
33-
JavaType targetType = ctxt.getContextualType();
34+
JavaType targetType = context.getContextualType();
3435

3536
if (targetType != null && !LLMModuleResult.class.equals(targetType.getRawClass())) {
3637
// If we're deserializing a concrete class, delegate to the default deserializer
37-
JsonDeserializer<Object> defaultDeserializer = ctxt.findRootValueDeserializer(targetType);
38-
return (LLMModuleResult) defaultDeserializer.deserialize(p, ctxt);
38+
JsonDeserializer<Object> defaultDeserializer = context.findRootValueDeserializer(targetType);
39+
return (LLMModuleResult) defaultDeserializer.deserialize(parser, context);
3940
}
4041

4142
// Custom deserialization logic for LLMModuleResult interface
42-
ObjectMapper mapper = (ObjectMapper) p.getCodec();
43-
JsonNode root = mapper.readTree(p);
43+
ObjectMapper mapper = (ObjectMapper) parser.getCodec();
44+
JsonNode rootNode = mapper.readTree(parser);
4445

4546
// Inspect the "choices" field
46-
JsonNode choicesNode = root.get("choices");
47+
JsonNode choicesNode = rootNode.get("choices");
4748

4849
if (choicesNode != null && choicesNode.isArray()) {
4950
JsonNode firstChoice = choicesNode.get(0);
@@ -58,20 +59,20 @@ public LLMModuleResult deserialize(JsonParser p, DeserializationContext ctxt) th
5859
if (concreteClass != null) {
5960
// Deserialize into the determined concrete class
6061
// Create a new parser for the root node
61-
JsonParser rootParser = root.traverse(mapper);
62+
JsonParser rootParser = rootNode.traverse(mapper);
6263
rootParser.nextToken(); // Advance to the first token
6364

6465
// Use the default deserializer for the concrete class
6566
JsonDeserializer<?> deserializer =
66-
ctxt.findRootValueDeserializer(ctxt.constructType(concreteClass));
67+
context.findRootValueDeserializer(context.constructType(concreteClass));
6768

68-
return (LLMModuleResult) deserializer.deserialize(rootParser, ctxt);
69+
return (LLMModuleResult) deserializer.deserialize(rootParser, context);
6970
}
7071
}
7172
}
7273

7374
// If unable to determine, throw an exception or handle default case
7475
throw new JsonMappingException(
75-
p, "Unable to determine the concrete implementation of LLMModuleResult");
76+
parser, "Unable to determine the concrete implementation of LLMModuleResult");
7677
}
7778
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.sap.ai.sdk.orchestration;
2+
3+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
4+
5+
/** Mixin to suppress @JsonTypeInfo for oneOf interfaces. */
6+
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
7+
public interface NoTypeInfoMixin {}

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClient.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@
1010
import com.sap.ai.sdk.core.AiCoreService;
1111
import com.sap.ai.sdk.orchestration.client.model.CompletionPostRequest;
1212
import com.sap.ai.sdk.orchestration.client.model.CompletionPostResponse;
13+
import com.sap.ai.sdk.orchestration.client.model.FilterConfig;
14+
import com.sap.ai.sdk.orchestration.client.model.GroundingModuleConfigConfigFiltersInner;
1315
import com.sap.ai.sdk.orchestration.client.model.LLMModuleResult;
16+
import com.sap.ai.sdk.orchestration.client.model.MaskingProviderConfig;
1417
import com.sap.ai.sdk.orchestration.client.model.ModuleConfigs;
1518
import com.sap.ai.sdk.orchestration.client.model.OrchestrationConfig;
19+
import com.sap.ai.sdk.orchestration.client.model.TemplateRefTemplateRef;
20+
import com.sap.ai.sdk.orchestration.client.model.TemplatingModuleConfig;
1621
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor;
1722
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
1823
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException;
@@ -41,8 +46,12 @@ public class OrchestrationClient {
4146
.visibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
4247
.visibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE)
4348
.serializationInclusion(JsonInclude.Include.NON_NULL)
44-
.deserializerByType(
45-
LLMModuleResult.class, new GeneralizedFallbackDeserializer<>(LLMModuleResult.class))
49+
.deserializerByType(LLMModuleResult.class, new LLMModuleResultDeserializer())
50+
.mixIn(FilterConfig.class, NoTypeInfoMixin.class)
51+
.mixIn(GroundingModuleConfigConfigFiltersInner.class, NoTypeInfoMixin.class)
52+
.mixIn(MaskingProviderConfig.class, NoTypeInfoMixin.class)
53+
.mixIn(TemplateRefTemplateRef.class, NoTypeInfoMixin.class)
54+
.mixIn(TemplatingModuleConfig.class, NoTypeInfoMixin.class)
4655
.build();
4756
}
4857

orchestration/src/main/java/com/sap/ai/sdk/orchestration/client/model/AzureContentSafety.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,25 @@
2424
AzureContentSafety.JSON_PROPERTY_SEXUAL,
2525
AzureContentSafety.JSON_PROPERTY_VIOLENCE
2626
})
27+
@com.google.common.annotations.Beta
2728
@javax.annotation.Generated(
2829
value = "org.openapitools.codegen.languages.JavaClientCodegen",
29-
date = "2024-11-08T18:02:22.585601+01:00[Europe/Berlin]",
3030
comments = "Generator version: 7.9.0")
3131
public class AzureContentSafety {
3232
public static final String JSON_PROPERTY_HATE = "Hate";
33-
public static final String JSON_PROPERTY_SELF_HARM = "SelfHarm";
34-
public static final String JSON_PROPERTY_SEXUAL = "Sexual";
35-
public static final String JSON_PROPERTY_VIOLENCE = "Violence";
3633
private AzureThreshold hate;
34+
35+
public static final String JSON_PROPERTY_SELF_HARM = "SelfHarm";
3736
private AzureThreshold selfHarm;
37+
38+
public static final String JSON_PROPERTY_SEXUAL = "Sexual";
3839
private AzureThreshold sexual;
40+
41+
public static final String JSON_PROPERTY_VIOLENCE = "Violence";
3942
private AzureThreshold violence;
4043

4144
public AzureContentSafety() {}
4245

43-
/** Create a builder with no initialized field. */
44-
public static AzureContentSafety.Builder builder() {
45-
return new AzureContentSafety.Builder();
46-
}
47-
4846
public AzureContentSafety hate(AzureThreshold hate) {
4947

5048
this.hate = hate;
@@ -183,15 +181,6 @@ private String toIndentedString(Object o) {
183181
return o.toString().replace("\n", "\n ");
184182
}
185183

186-
/** Create a builder with a shallow copy of this instance. */
187-
public AzureContentSafety.Builder toBuilder() {
188-
return new AzureContentSafety.Builder()
189-
.hate(getHate())
190-
.selfHarm(getSelfHarm())
191-
.sexual(getSexual())
192-
.violence(getViolence());
193-
}
194-
195184
public static class Builder {
196185

197186
private AzureContentSafety instance;
@@ -243,4 +232,18 @@ public String toString() {
243232
return getClass() + "=(" + instance + ")";
244233
}
245234
}
235+
236+
/** Create a builder with no initialized field. */
237+
public static AzureContentSafety.Builder builder() {
238+
return new AzureContentSafety.Builder();
239+
}
240+
241+
/** Create a builder with a shallow copy of this instance. */
242+
public AzureContentSafety.Builder toBuilder() {
243+
return new AzureContentSafety.Builder()
244+
.hate(getHate())
245+
.selfHarm(getSelfHarm())
246+
.sexual(getSexual())
247+
.violence(getViolence());
248+
}
246249
}

0 commit comments

Comments
 (0)