Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud SDK generator with oneOf fix #186

Merged
merged 16 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
<!-- TODO: remove this once Cloud SDK 5.15.0 is released -->
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<apiMaturity>released</apiMaturity>
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public BckndGenericSecretPatchBody data(@Nonnull final Map<String, String> data)
@Nonnull
public BckndGenericSecretPatchBody putdataItem(
@Nonnull final String key, @Nonnull final String dataItem) {
this.data = new HashMap<>();
this.data.put(key, dataItem);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public BckndGenericSecretPostBody data(@Nonnull final Map<String, String> data)
@Nonnull
public BckndGenericSecretPostBody putdataItem(
@Nonnull final String key, @Nonnull final String dataItem) {
this.data = new HashMap<>();
this.data.put(key, dataItem);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public BckndResourceGetResponse resourcePlans(
public BckndResourceGetResponse putresourcePlansItem(
@Nonnull final String key,
@Nonnull final BckndResourceGetResourcePlansValue resourcePlansItem) {
this.resourcePlans = new HashMap<>();
this.resourcePlans.put(key, resourcePlansItem);
return this;
}
Expand Down
18 changes: 0 additions & 18 deletions orchestration/.openapi-generator-ignore

This file was deleted.

72 changes: 18 additions & 54 deletions orchestration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -140,72 +136,40 @@
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
<!-- TODO: remove this once Cloud SDK 5.15.0 is released -->
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<apiMaturity>beta</apiMaturity>
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
<compileScope>COMPILE</compileScope>
<deleteOutputDirectory>true</deleteOutputDirectory>
</configuration>
<executions>
<execution>
<id>orchestration</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- Specify the input OpenAPI spec file -->
<inputSpec>${project.basedir}/src/main/resources/spec/orchestration.yaml</inputSpec>
<output>${project.basedir}</output>
<!-- Specify the generator to use, e.g., java, spring, kotlin, etc. -->
<generatorName>java</generatorName>
<!-- Specify the package names for models, APIs, and invokers -->
<apiPackage>com.sap.ai.sdk.orchestration.client</apiPackage>
<generateApis>false</generateApis>
<modelPackage>com.sap.ai.sdk.orchestration.client.model</modelPackage>
<apiPackage>com.sap.ai.sdk.orchestration.client.api</apiPackage>
<invokerPackage>com.sap.ai.sdk.orchestration.client.invoker</invokerPackage>

<!-- Global properties level; can be unpacked with 'generate' prefix-->
<globalProperties>
<apiDocs>false</apiDocs>
<modelDocs>false</modelDocs>
<modelTests>false</modelTests>
<apiTests>false</apiTests>
<minimalUpdate>true</minimalUpdate>
</globalProperties>

<!-- Generator Specific properties level; some can be unpacked-->
<configOptions>
<generateBuilders>true</generateBuilders>
<failOnUnknownProperties>false</failOnUnknownProperties>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
<additionalProperties>
<pojoBuilderMethodName>create</pojoBuilderMethodName>
<pojoBuildMethodName/>
<pojoConstructorVisibility>protected</pojoConstructorVisibility>
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
<useBeanValidation>false</useBeanValidation>
<useOneOfInterfaces>true</useOneOfInterfaces>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useOneOfInterfaces is the only addition compared to the old Cloud SDK generator

<additionalModelTypeAnnotations>@com.google.common.annotations.Beta</additionalModelTypeAnnotations>
</configOptions>
<generateModels>true</generateModels>
<generateSupportingFiles>false</generateSupportingFiles>
<generateApis>false</generateApis>
<library>resttemplate</library>
<!--<configHelp>true</configHelp>-->
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/java/com/sap/ai/sdk/orchestration/client</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<id>delete-orchestration-generated-client</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public AzureContentSafetyFilterConfig createConfig() {
throw new IllegalArgumentException("At least one filter category must be set");
}

return new AzureContentSafetyFilterConfig()
return AzureContentSafetyFilterConfig.create()
.type(AzureContentSafetyFilterConfig.TypeEnum.AZURE_CONTENT_SAFETY)
.config(
new AzureContentSafety()
AzureContentSafety.create()
.hate(hate != null ? hate.getAzureThreshold() : null)
.selfHarm(selfHarm != null ? selfHarm.getAzureThreshold() : null)
.sexual(sexual != null ? sexual.getAzureThreshold() : null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ static CompletionPostRequest toCompletionPostRequest(
// subsequent requests
val configCopy = config.withTemplateConfig(template);

return new CompletionPostRequest()
return CompletionPostRequest.create()
.orchestrationConfig(
new OrchestrationConfig().moduleConfigurations(toModuleConfigs(configCopy)))
OrchestrationConfig.create().moduleConfigurations(toModuleConfigs(configCopy)))
.inputParams(prompt.getTemplateParameters())
.messagesHistory(prompt.getMessagesHistory());
}
Expand All @@ -51,7 +51,7 @@ static TemplatingModuleConfig toTemplateModuleConfig(
throw new IllegalStateException(
"A prompt is required. Pass at least one message or configure a template with messages or a template reference.");
}
return new Template().template(messagesWithPrompt);
return Template.create().template(messagesWithPrompt);
}

@Nonnull
Expand All @@ -62,7 +62,7 @@ static ModuleConfigs toModuleConfigs(@Nonnull final OrchestrationModuleConfig co

//noinspection DataFlowIssue the template is always non-null here
val moduleConfig =
new ModuleConfigs()
ModuleConfigs.create()
.llmModuleConfig(llmConfig)
.templatingModuleConfig(config.getTemplateConfig());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public DpiMasking withEntities(
@Nonnull
@Override
public MaskingProviderConfig createConfig() {
val entitiesDTO = entities.stream().map(it -> new DPIEntityConfig().type(it)).toList();
return new DPIConfig()
val entitiesDTO = entities.stream().map(it -> DPIEntityConfig.create().type(it)).toList();
return DPIConfig.create()
.type(SAP_DATA_PRIVACY_INTEGRATION)
.method(maskingMethod)
.entities(entitiesDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ public class OrchestrationAiModel {

@Nonnull
LLMModuleConfig createConfig() {
return new LLMModuleConfig().modelName(name).modelParams(params).modelVersion(version);
return LLMModuleConfig.create().modelName(name).modelParams(params).modelVersion(version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,10 @@ public OrchestrationChatResponse executeRequestFromJsonModuleConfig(
"Prompt must not contain any messages when using a JSON module configuration, as the template is already defined in the JSON.");
}

final var request =
new CompletionPostRequest()
.messagesHistory(prompt.getMessagesHistory())
.inputParams(prompt.getTemplateParameters());
final ObjectNode requestJson = JACKSON.createObjectNode();
requestJson.set("messages_history", JACKSON.valueToTree(prompt.getMessagesHistory()));
requestJson.set("input_params", JACKSON.valueToTree(prompt.getTemplateParameters()));
Comment on lines +171 to +173
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Question/Minor)

Why not use CompletionPostRequest class as done before your change?

Your change requires the developer to know the keys are called "messages_history" and "input_params".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Matthias built an invalid object that our builder doesn't allow anymore. Plus the developer still has to know the key orchestration_config (line 184)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object itself isn't invalid, it's just not built all in one line of code 😉

We could still use CompletionPostRequest and just set the config to null explicitly, but then we have to suppress the warning, and overall it doesn't look much better. Alternatively, we could just make the constructors public, but I guess we don't want that for the few users who would use the low-level API and should be forced to supply all mandatory parameters..


final ObjectNode requestJson = JACKSON.valueToTree(request);
final JsonNode moduleConfigJson;
try {
moduleConfigJson = JACKSON.readTree(moduleConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public OrchestrationModuleConfig withMaskingConfig(
@Nonnull final MaskingProvider maskingProvider,
@Nonnull final MaskingProvider... maskingProviders) {
val newMaskingConfig =
new MaskingModuleConfig().addMaskingProvidersItem(maskingProvider.createConfig());
MaskingModuleConfig.create().maskingProviders(maskingProvider.createConfig());
Arrays.stream(maskingProviders)
.forEach(it -> newMaskingConfig.addMaskingProvidersItem(it.createConfig()));

Expand All @@ -109,10 +109,10 @@ public OrchestrationModuleConfig withInputFiltering(
final var filterConfigs =
allFilters.stream().filter(Objects::nonNull).map(ContentFilter::createConfig).toList();

final var inputFilter = new InputFilteringConfig().filters(filterConfigs);
final var inputFilter = InputFilteringConfig.create().filters(filterConfigs);

final var newFilteringConfig =
new FilteringModuleConfig()
FilteringModuleConfig.create()
.input(inputFilter)
.output(this.filteringConfig != null ? this.filteringConfig.getOutput() : null);

Expand Down Expand Up @@ -140,10 +140,10 @@ public OrchestrationModuleConfig withOutputFiltering(
final var filterConfigs =
allFilters.stream().filter(Objects::nonNull).map(ContentFilter::createConfig).toList();

final var outputFilter = new OutputFilteringConfig().filters(filterConfigs);
final var outputFilter = OutputFilteringConfig.create().filters(filterConfigs);

final var newFilteringConfig =
new FilteringModuleConfig()
FilteringModuleConfig.create()
.output(outputFilter)
.input(this.filteringConfig != null ? this.filteringConfig.getInput() : null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class OrchestrationPrompt {
* @param message A user message.
*/
public OrchestrationPrompt(@Nonnull final String message) {
messages.add(new ChatMessage().role("user").content(message));
messages.add(ChatMessage.create().role("user").content(message));
}

/**
Expand Down
Loading