Skip to content

Commit c466d52

Browse files
committed
OSS generation decoupled from new Orchestration Client
2 parents 7cdf2c8 + 9387838 commit c466d52

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

+413
-629
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# OpenAPI Generator Ignore
2+
3+
.github/
4+
gradle/
5+
.gitignore
6+
.travis.yml
7+
build.gradle
8+
build.sbt
9+
git_push.sh
10+
gradle.properties
11+
gradlew
12+
gradlew.bat
13+
pom.xml
14+
README.md
15+
settings.gradle
16+
src/main/AndroidManifest.xml
17+
api/
18+
.openapi-generator/
19+
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
22+
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
24+
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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,11 @@
165165
<configOptions>
166166
<generateBuilders>true</generateBuilders>
167167
<failOnUnknownProperties>false</failOnUnknownProperties>
168-
<hideGenerationTimestamp>true</hideGenerationTimestamp>
168+
<hideGenerationTimestamp>false</hideGenerationTimestamp>
169169
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
170170
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
171171
<useBeanValidation>false</useBeanValidation>
172172
<useOneOfInterfaces>true</useOneOfInterfaces>
173-
<!--<legacyDiscriminatorBehavior>false</legacyDiscriminatorBehavior>-->
174173
</configOptions>
175174
<generateModels>true</generateModels>
176175
<generateSupportingFiles>false</generateSupportingFiles>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.sap.ai.sdk.orchestration;
2+
3+
import com.fasterxml.jackson.annotation.JsonSubTypes;
4+
import com.fasterxml.jackson.core.JsonParser;
5+
import com.fasterxml.jackson.databind.*;
6+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
7+
import java.io.IOException;
8+
9+
public class GeneralizedFallbackDeserializer<T> extends StdDeserializer<T> {
10+
11+
private final Class<T> baseType;
12+
13+
public GeneralizedFallbackDeserializer(Class<T> baseClass) {
14+
super(baseClass);
15+
this.baseType = baseClass;
16+
}
17+
18+
@Override
19+
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
20+
ObjectMapper mapper = (ObjectMapper) p.getCodec();
21+
JsonNode rootNode = mapper.readTree(p);
22+
23+
// Get the possible subtypes from @JsonSubTypes
24+
JsonSubTypes subTypes = baseType.getAnnotation(JsonSubTypes.class);
25+
if (subTypes == null || subTypes.value().length == 0) {
26+
throw new JsonMappingException(p, "No subtypes found for " + baseType.getName());
27+
}
28+
29+
Exception lastException = null;
30+
for (JsonSubTypes.Type subType : subTypes.value()) {
31+
Class<? extends T> candidateClass = (Class<? extends T>) subType.value();
32+
33+
try {
34+
// Attempt to deserialize into the candidate class
35+
// If successful, return the result
36+
return mapper.treeToValue(rootNode, candidateClass);
37+
} catch (Exception e) {
38+
// Save the exception and try the next candidate
39+
lastException = e;
40+
}
41+
}
42+
43+
// If none succeeded, throw an exception with the last caught exception as the cause
44+
throw JsonMappingException.from(
45+
p, "Unable to deserialize " + baseType.getName(), lastException);
46+
}
47+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.sap.ai.sdk.orchestration;
2+
3+
import com.fasterxml.jackson.core.JsonParser;
4+
import com.fasterxml.jackson.databind.*;
5+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
6+
import com.sap.ai.sdk.orchestration.client.model.LLMModuleResult;
7+
import com.sap.ai.sdk.orchestration.client.model.LLMModuleResultStreaming;
8+
import com.sap.ai.sdk.orchestration.client.model.LLMModuleResultSynchronous;
9+
import java.io.IOException;
10+
11+
public class LLMModuleResultDeserializer extends StdDeserializer<LLMModuleResult> {
12+
13+
public LLMModuleResultDeserializer() {
14+
super(LLMModuleResult.class);
15+
}
16+
17+
@Override
18+
public LLMModuleResult deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
19+
20+
// Check if the target type is a concrete class
21+
JavaType targetType = ctxt.getContextualType();
22+
23+
if (targetType != null && !LLMModuleResult.class.equals(targetType.getRawClass())) {
24+
// If we're deserializing a concrete class, delegate to the default deserializer
25+
JsonDeserializer<Object> defaultDeserializer = ctxt.findRootValueDeserializer(targetType);
26+
return (LLMModuleResult) defaultDeserializer.deserialize(p, ctxt);
27+
}
28+
29+
// Custom deserialization logic for LLMModuleResult interface
30+
ObjectMapper mapper = (ObjectMapper) p.getCodec();
31+
JsonNode root = mapper.readTree(p);
32+
33+
// Inspect the "choices" field
34+
JsonNode choicesNode = root.get("choices");
35+
36+
if (choicesNode != null && choicesNode.isArray()) {
37+
JsonNode firstChoice = choicesNode.get(0);
38+
if (firstChoice != null) {
39+
Class<? extends LLMModuleResult> concreteClass = null;
40+
if (firstChoice.has("delta")) {
41+
concreteClass = LLMModuleResultStreaming.class;
42+
} else if (firstChoice.has("message")) {
43+
concreteClass = LLMModuleResultSynchronous.class;
44+
}
45+
46+
if (concreteClass != null) {
47+
// Deserialize into the determined concrete class
48+
// Create a new parser for the root node
49+
JsonParser rootParser = root.traverse(mapper);
50+
rootParser.nextToken(); // Advance to the first token
51+
52+
// Use the default deserializer for the concrete class
53+
JsonDeserializer<?> deserializer =
54+
ctxt.findRootValueDeserializer(ctxt.constructType(concreteClass));
55+
56+
return (LLMModuleResult) deserializer.deserialize(rootParser, ctxt);
57+
}
58+
}
59+
}
60+
61+
// If unable to determine, throw an exception or handle default case
62+
throw new JsonMappingException(
63+
p, "Unable to determine the concrete implementation of LLMModuleResult");
64+
}
65+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
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.LLMModuleResult;
1314
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor;
1415
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException;
1516
import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException;
@@ -38,6 +39,8 @@ public class OrchestrationClient {
3839
.visibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
3940
.visibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE)
4041
.serializationInclusion(JsonInclude.Include.NON_NULL)
42+
.deserializerByType(
43+
LLMModuleResult.class, new GeneralizedFallbackDeserializer<>(LLMModuleResult.class))
4144
.build();
4245
}
4346

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Internal Orchestration Service API
3-
* SAP AI Core - Orchestration Service API
2+
* Orchestration
3+
* Orchestration is an inference service which provides common additional capabilities for business AI scenarios, such as content filtering and data masking. At the core of the service is the LLM module which allows for an easy, harmonized access to the language models of gen AI hub. The service is designed to be modular and extensible, allowing for the addition of new modules in the future. Each module can be configured independently and at runtime, allowing for a high degree of flexibility in the orchestration of AI services.
44
*
5-
* The version of the OpenAPI document: 0.0.1
5+
* The version of the OpenAPI document: 0.29.3
66
*
77
*
88
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -26,6 +26,7 @@
2626
})
2727
@javax.annotation.Generated(
2828
value = "org.openapitools.codegen.languages.JavaClientCodegen",
29+
date = "2024-11-08T15:36:05.863594+01:00[Europe/Berlin]",
2930
comments = "Generator version: 7.9.0")
3031
public class AzureContentSafety {
3132
public static final String JSON_PROPERTY_HATE = "Hate";

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Internal Orchestration Service API
3-
* SAP AI Core - Orchestration Service API
2+
* Orchestration
3+
* Orchestration is an inference service which provides common additional capabilities for business AI scenarios, such as content filtering and data masking. At the core of the service is the LLM module which allows for an easy, harmonized access to the language models of gen AI hub. The service is designed to be modular and extensible, allowing for the addition of new modules in the future. Each module can be configured independently and at runtime, allowing for a high degree of flexibility in the orchestration of AI services.
44
*
5-
* The version of the OpenAPI document: 0.0.1
5+
* The version of the OpenAPI document: 0.29.3
66
*
77
*
88
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -26,6 +26,7 @@
2626
})
2727
@javax.annotation.Generated(
2828
value = "org.openapitools.codegen.languages.JavaClientCodegen",
29+
date = "2024-11-08T15:36:05.863594+01:00[Europe/Berlin]",
2930
comments = "Generator version: 7.9.0")
3031
public class AzureContentSafetyFilterConfig implements FilterConfig {
3132
/** String represents name of the filter provider */

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Internal Orchestration Service API
3-
* SAP AI Core - Orchestration Service API
2+
* Orchestration
3+
* Orchestration is an inference service which provides common additional capabilities for business AI scenarios, such as content filtering and data masking. At the core of the service is the LLM module which allows for an easy, harmonized access to the language models of gen AI hub. The service is designed to be modular and extensible, allowing for the addition of new modules in the future. Each module can be configured independently and at runtime, allowing for a high degree of flexibility in the orchestration of AI services.
44
*
5-
* The version of the OpenAPI document: 0.0.1
5+
* The version of the OpenAPI document: 0.29.3
66
*
77
*
88
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -21,6 +21,7 @@
2121
@JsonPropertyOrder({ChatDelta.JSON_PROPERTY_ROLE, ChatDelta.JSON_PROPERTY_CONTENT})
2222
@javax.annotation.Generated(
2323
value = "org.openapitools.codegen.languages.JavaClientCodegen",
24+
date = "2024-11-08T15:36:05.863594+01:00[Europe/Berlin]",
2425
comments = "Generator version: 7.9.0")
2526
public class ChatDelta {
2627
public static final String JSON_PROPERTY_ROLE = "role";

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Internal Orchestration Service API
3-
* SAP AI Core - Orchestration Service API
2+
* Orchestration
3+
* Orchestration is an inference service which provides common additional capabilities for business AI scenarios, such as content filtering and data masking. At the core of the service is the LLM module which allows for an easy, harmonized access to the language models of gen AI hub. The service is designed to be modular and extensible, allowing for the addition of new modules in the future. Each module can be configured independently and at runtime, allowing for a high degree of flexibility in the orchestration of AI services.
44
*
5-
* The version of the OpenAPI document: 0.0.1
5+
* The version of the OpenAPI document: 0.29.3
66
*
77
*
88
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -21,6 +21,7 @@
2121
@JsonPropertyOrder({ChatMessage.JSON_PROPERTY_ROLE, ChatMessage.JSON_PROPERTY_CONTENT})
2222
@javax.annotation.Generated(
2323
value = "org.openapitools.codegen.languages.JavaClientCodegen",
24+
date = "2024-11-08T15:36:05.863594+01:00[Europe/Berlin]",
2425
comments = "Generator version: 7.9.0")
2526
public class ChatMessage {
2627
public static final String JSON_PROPERTY_ROLE = "role";

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Internal Orchestration Service API
3-
* SAP AI Core - Orchestration Service API
2+
* Orchestration
3+
* Orchestration is an inference service which provides common additional capabilities for business AI scenarios, such as content filtering and data masking. At the core of the service is the LLM module which allows for an easy, harmonized access to the language models of gen AI hub. The service is designed to be modular and extensible, allowing for the addition of new modules in the future. Each module can be configured independently and at runtime, allowing for a high degree of flexibility in the orchestration of AI services.
44
*
5-
* The version of the OpenAPI document: 0.0.1
5+
* The version of the OpenAPI document: 0.29.3
66
*
77
*
88
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -29,6 +29,7 @@
2929
})
3030
@javax.annotation.Generated(
3131
value = "org.openapitools.codegen.languages.JavaClientCodegen",
32+
date = "2024-11-08T15:36:05.863594+01:00[Europe/Berlin]",
3233
comments = "Generator version: 7.9.0")
3334
public class CompletionPostRequest {
3435
public static final String JSON_PROPERTY_ORCHESTRATION_CONFIG = "orchestration_config";

0 commit comments

Comments
 (0)