diff --git a/core/src/main/java/com/sap/ai/sdk/core/common/ClientResponseHandler.java b/core/src/main/java/com/sap/ai/sdk/core/common/ClientResponseHandler.java index b28b6691f..902467b7b 100644 --- a/core/src/main/java/com/sap/ai/sdk/core/common/ClientResponseHandler.java +++ b/core/src/main/java/com/sap/ai/sdk/core/common/ClientResponseHandler.java @@ -36,7 +36,7 @@ public class ClientResponseHandler successType; /** The HTTP error response type */ - @Nonnull final Class errorType; + @Nonnull final Class errorType; /** The factory to create exceptions for Http 4xx/5xx responses. */ @Nonnull final ClientExceptionFactory exceptionFactory; diff --git a/core/src/main/java/com/sap/ai/sdk/core/common/ClientStreamingHandler.java b/core/src/main/java/com/sap/ai/sdk/core/common/ClientStreamingHandler.java index 1d27edb9d..280c51953 100644 --- a/core/src/main/java/com/sap/ai/sdk/core/common/ClientStreamingHandler.java +++ b/core/src/main/java/com/sap/ai/sdk/core/common/ClientStreamingHandler.java @@ -43,7 +43,7 @@ public ClientStreamingHandler objectMapper(@Nonnull final ObjectMapper */ public ClientStreamingHandler( @Nonnull final Class deltaType, - @Nonnull final Class errorType, + @Nonnull final Class errorType, @Nonnull final ClientExceptionFactory exceptionFactory) { super(deltaType, errorType, exceptionFactory); } diff --git a/docs/release_notes.md b/docs/release_notes.md index 383d64f75..118cbc75e 100644 --- a/docs/release_notes.md +++ b/docs/release_notes.md @@ -12,7 +12,10 @@ - The `OrchestrationChatOptions` have been, replacing all references to `FunctionCallback` with `ToolCallback`. - Please follow the [official Spring AI upgrade guide](https://docs.spring.io/spring-ai/reference/upgrade-notes.html#upgrading-to-1-0-0-RC1) for further details. - The `@Beta` annotations on all classes related to Spring AI have been removed. - +- [Orchestration] The `completion` api have been moved to the latest version `/v2/completions` + - `LLMModuleConfig` is replaced by `LLMModelDetails` in `withLLmConfig` method of `OrchestrationModuleConfig` class. + - `PromptTemplatingModuleConfigPrompt` replaces `TemplatingModuleConfig` in the `withTemplateConfig` method of `OrchestrationModuleConfig` class. + - The generated model classes will reflect payload updates including restructuring of the module configurations and renaming of several fields. ### ✨ New Functionality diff --git a/orchestration/pom.xml b/orchestration/pom.xml index 4ed8cdd69..a0aa26a9b 100644 --- a/orchestration/pom.xml +++ b/orchestration/pom.xml @@ -36,10 +36,10 @@ ${project.basedir}/../ - 82% + 80% 94% - 95% - 77% + 94% + 75% 93% 100% diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/ConfigToRequestTransformer.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/ConfigToRequestTransformer.java index 526bff598..ff77c3e5d 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/ConfigToRequestTransformer.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/ConfigToRequestTransformer.java @@ -4,9 +4,11 @@ import com.sap.ai.sdk.orchestration.model.CompletionPostRequest; import com.sap.ai.sdk.orchestration.model.ModuleConfigs; import com.sap.ai.sdk.orchestration.model.OrchestrationConfig; +import com.sap.ai.sdk.orchestration.model.PromptTemplatingModuleConfig; +import com.sap.ai.sdk.orchestration.model.PromptTemplatingModuleConfigPrompt; import com.sap.ai.sdk.orchestration.model.Template; import com.sap.ai.sdk.orchestration.model.TemplateRef; -import com.sap.ai.sdk.orchestration.model.TemplatingModuleConfig; +import com.sap.ai.sdk.orchestration.model.TranslationModuleConfig; import io.vavr.control.Option; import java.util.ArrayList; import javax.annotation.Nonnull; @@ -37,14 +39,15 @@ static CompletionPostRequest toCompletionPostRequest( val moduleConfigs = toModuleConfigs(configCopy); return CompletionPostRequest.create() - .orchestrationConfig(OrchestrationConfig.create().moduleConfigurations(moduleConfigs)) - .inputParams(prompt.getTemplateParameters()) + .config(OrchestrationConfig.create().modules(moduleConfigs)) + .placeholderValues(prompt.getTemplateParameters()) .messagesHistory(messageHistory); } @Nonnull - static TemplatingModuleConfig toTemplateModuleConfig( - @Nonnull final OrchestrationPrompt prompt, @Nullable final TemplatingModuleConfig config) { + static PromptTemplatingModuleConfigPrompt toTemplateModuleConfig( + @Nonnull final OrchestrationPrompt prompt, + @Nullable final PromptTemplatingModuleConfigPrompt config) { /* * Currently, we have to merge the prompt into the template configuration. * This works around the limitation that the template config is required. @@ -89,16 +92,23 @@ static ModuleConfigs toModuleConfigs(@Nonnull final OrchestrationModuleConfig co //noinspection DataFlowIssue the template is always non-null here val moduleConfig = ModuleConfigs.create() - .llmModuleConfig(llmConfig) - .templatingModuleConfig(config.getTemplateConfig()); - - Option.of(config.getFilteringConfig()).forEach(moduleConfig::filteringModuleConfig); - Option.of(config.getMaskingConfig()).forEach(moduleConfig::maskingModuleConfig); - Option.of(config.getGroundingConfig()).forEach(moduleConfig::groundingModuleConfig); - Option.of(config.getOutputTranslationConfig()) - .forEach(moduleConfig::outputTranslationModuleConfig); - Option.of(config.getInputTranslationConfig()) - .forEach(moduleConfig::inputTranslationModuleConfig); + .promptTemplating( + PromptTemplatingModuleConfig.create() + .prompt(config.getTemplateConfig()) + .model(llmConfig)); + + Option.of(config.getFilteringConfig()).forEach(moduleConfig::filtering); + Option.of(config.getMaskingConfig()).forEach(moduleConfig::masking); + Option.of(config.getGroundingConfig()).forEach(moduleConfig::grounding); + + val outputTranslation = Option.of(config.getOutputTranslationConfig()); + val inputTranslation = Option.of(config.getInputTranslationConfig()); + + if (inputTranslation.isDefined() || outputTranslation.isDefined()) { + moduleConfig.setTranslation(TranslationModuleConfig.create()); + inputTranslation.forEach(moduleConfig.getTranslation()::input); + outputTranslation.forEach(moduleConfig.getTranslation()::output); + } return moduleConfig; } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/Grounding.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/Grounding.java index 97a619cb1..8e78462f1 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/Grounding.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/Grounding.java @@ -7,6 +7,7 @@ import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig.TypeEnum; import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfig; import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfigFiltersInner; +import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfigPlaceholders; import java.util.List; import java.util.Map; import javax.annotation.Nonnull; @@ -81,8 +82,10 @@ public OrchestrationPrompt createGroundingPrompt(@Nonnull final String message) public GroundingModuleConfig createConfig() { val groundingConfigConfig = GroundingModuleConfigConfig.create() - .inputParams(List.of("userMessage")) - .outputParam("groundingContext") + .placeholders( + GroundingModuleConfigConfigPlaceholders.create() + .input(List.of("userMessage")) + .output("groundingContext")) .filters(filters); if (filters.contains( diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/JacksonMixins.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/JacksonMixins.java index bd3bade0f..d141f442e 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/JacksonMixins.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/JacksonMixins.java @@ -1,9 +1,12 @@ package com.sap.ai.sdk.orchestration; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo.As; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sap.ai.sdk.orchestration.model.AzureThreshold; import com.sap.ai.sdk.orchestration.model.LLMModuleResult; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -56,4 +59,26 @@ interface ResponseFormatSubTypesMixin {} name = "user") }) interface ChatMessageMixin {} + + /** + * Mixin used for parsing response "data" field of + * error.intermediate_results.input_filtering.data.azure_content_safety + */ + abstract static class AzureContentSafetyCaseAgnostic { + @JsonProperty("hate") + @JsonAlias("Hate") + private AzureThreshold hate; + + @JsonProperty("self_harm") + @JsonAlias("SelfHarm") + private AzureThreshold selfHarm; + + @JsonProperty("sexual") + @JsonAlias("Sexual") + private AzureThreshold sexual; + + @JsonProperty("violence") + @JsonAlias("Violence") + private AzureThreshold violence; + } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationAiModel.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationAiModel.java index 586e57d79..b78e4f607 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationAiModel.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationAiModel.java @@ -1,6 +1,6 @@ package com.sap.ai.sdk.orchestration; -import com.sap.ai.sdk.orchestration.model.LLMModuleConfig; +import com.sap.ai.sdk.orchestration.model.LLMModelDetails; import java.util.LinkedHashMap; import java.util.Map; import javax.annotation.Nonnull; @@ -276,8 +276,8 @@ public class OrchestrationAiModel { } @Nonnull - LLMModuleConfig createConfig() { - return LLMModuleConfig.create().modelName(name).modelParams(params).modelVersion(version); + LLMModelDetails createConfig() { + return LLMModelDetails.create().name(name).params(params).version(version); } /** diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatCompletionDelta.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatCompletionDelta.java index 10c2a0e93..5203b3f52 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatCompletionDelta.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatCompletionDelta.java @@ -13,7 +13,7 @@ public class OrchestrationChatCompletionDelta extends CompletionPostResponseStre @Nonnull @Override public String getDeltaContent() { - val choices = getOrchestrationResult().getChoices(); + val choices = getFinalResult().getChoices(); // Avoid the first delta: "choices":[] if (!choices.isEmpty() // Multiple choices are spread out on multiple deltas @@ -29,6 +29,6 @@ public String getDeltaContent() { @Nullable @Override public String getFinishReason() { - return getOrchestrationResult().getChoices().get(0).getFinishReason(); + return getFinalResult().getChoices().get(0).getFinishReason(); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatResponse.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatResponse.java index 52c178a35..ac8764856 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatResponse.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatResponse.java @@ -51,7 +51,7 @@ public String getContent() throws OrchestrationFilterException.Output { @SuppressWarnings("unchecked") private Map getOutputFilteringChoices() { - final var f = getOriginalResponse().getModuleResults().getOutputFiltering(); + final var f = getOriginalResponse().getIntermediateResults().getOutputFiltering(); return ((List>) ((Map) f.getData()).get("choices")).get(0); } @@ -62,7 +62,7 @@ private Map getOutputFilteringChoices() { */ @Nonnull public TokenUsage getTokenUsage() { - return originalResponse.getOrchestrationResult().getUsage(); + return originalResponse.getFinalResult().getUsage(); } /** @@ -74,7 +74,8 @@ public TokenUsage getTokenUsage() { @Nonnull public List getAllMessages() throws IllegalArgumentException { val messages = new ArrayList(); - for (final ChatMessage chatMessage : originalResponse.getModuleResults().getTemplating()) { + for (final ChatMessage chatMessage : + originalResponse.getIntermediateResults().getTemplating()) { if (chatMessage instanceof AssistantChatMessage assistantChatMessage) { val toolCalls = assistantChatMessage.getToolCalls(); if (!toolCalls.isEmpty()) { @@ -115,7 +116,7 @@ public List getAllMessages() throws IllegalArgumentException { @Nonnull public LLMChoice getChoice() { // We expect choices to be defined and never empty. - return originalResponse.getOrchestrationResult().getChoices().get(0); + return originalResponse.getFinalResult().getChoices().get(0); } /** @@ -133,12 +134,7 @@ public LLMChoice getChoice() { @Nonnull public T asEntity(@Nonnull final Class type) throws OrchestrationClientException { final String refusal = - getOriginalResponse() - .getOrchestrationResult() - .getChoices() - .get(0) - .getMessage() - .getRefusal(); + getOriginalResponse().getFinalResult().getChoices().get(0).getMessage().getRefusal(); if (refusal != null) { throw new OrchestrationClientException( "The model refused to answer the question: " + refusal); diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClient.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClient.java index a16101017..0606499a3 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClient.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClient.java @@ -12,6 +12,7 @@ import com.sap.ai.sdk.orchestration.model.CompletionPostResponse; import com.sap.ai.sdk.orchestration.model.EmbeddingsPostRequest; import com.sap.ai.sdk.orchestration.model.EmbeddingsPostResponse; +import com.sap.ai.sdk.orchestration.model.GlobalStreamOptions; import com.sap.ai.sdk.orchestration.model.ModuleConfigs; import com.sap.ai.sdk.orchestration.model.OrchestrationConfig; import com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination; @@ -28,6 +29,7 @@ @Slf4j public class OrchestrationClient { private static final String DEFAULT_SCENARIO = "orchestration"; + private static final String COMPLETION_ENDPOINT = "/v2/completion"; static final ObjectMapper JACKSON = getOrchestrationObjectMapper(); @@ -127,7 +129,7 @@ private static void throwOnContentFilter(@Nonnull final OrchestrationChatComplet @SuppressWarnings("unchecked") private static Map getOutputFilteringChoices( @Nonnull final OrchestrationChatCompletionDelta delta) { - final var f = delta.getModuleResults().getOutputFiltering(); + final var f = delta.getIntermediateResults().getOutputFiltering(); return ((List>) ((Map) f.getData()).get("choices")).get(0); } @@ -154,7 +156,7 @@ private static Map getOutputFilteringChoices( @Nonnull public CompletionPostResponse executeRequest(@Nonnull final CompletionPostRequest request) throws OrchestrationClientException { - return executor.execute("/completion", request, CompletionPostResponse.class); + return executor.execute(COMPLETION_ENDPOINT, request, CompletionPostResponse.class); } /** @@ -196,7 +198,7 @@ public OrchestrationChatResponse executeRequestFromJsonModuleConfig( requestJson.set("orchestration_config", moduleConfigJson); return new OrchestrationChatResponse( - executor.execute("/completion", requestJson, CompletionPostResponse.class)); + executor.execute(COMPLETION_ENDPOINT, requestJson, CompletionPostResponse.class)); } /** @@ -210,8 +212,9 @@ public OrchestrationChatResponse executeRequestFromJsonModuleConfig( @Nonnull public Stream streamChatCompletionDeltas( @Nonnull final CompletionPostRequest request) throws OrchestrationClientException { - request.getOrchestrationConfig().setStream(true); - return executor.stream(request); + request.getConfig().setStream(GlobalStreamOptions.create().enabled(true).delimiters(null)); + + return executor.stream(COMPLETION_ENDPOINT, request); } /** diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClientException.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClientException.java index 34493792f..cc8097e45 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClientException.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClientException.java @@ -2,7 +2,9 @@ import com.google.common.annotations.Beta; import com.sap.ai.sdk.core.common.ClientException; +import com.sap.ai.sdk.orchestration.model.Error; import com.sap.ai.sdk.orchestration.model.ErrorResponse; +import com.sap.ai.sdk.orchestration.model.ErrorResponseStreaming; import java.util.Optional; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -22,12 +24,29 @@ public class OrchestrationClientException extends ClientException { * Retrieves the {@link ErrorResponse} from the orchestration service, if available. * * @return The {@link ErrorResponse} object, or {@code null} if not available. + * @since 1.10.0 */ @Beta @Nullable public ErrorResponse getErrorResponse() { final var clientError = super.getClientError(); - if (clientError instanceof OrchestrationError orchestrationError) { + if (clientError instanceof OrchestrationError.Synchronous orchestrationError) { + return orchestrationError.getErrorResponse(); + } + return null; + } + + /** + * Retrieves the {@link ErrorResponseStreaming} from the orchestration service, if available. + * + * @return The {@link ErrorResponseStreaming} object, or {@code null} if not available. + * @since 1.10.0 + */ + @Beta + @Nullable + public ErrorResponseStreaming getErrorResponseStreaming() { + final var clientError = super.getClientError(); + if (clientError instanceof OrchestrationError.Streaming orchestrationError) { return orchestrationError.getErrorResponse(); } return null; @@ -37,10 +56,14 @@ public ErrorResponse getErrorResponse() { * Retrieves the HTTP status code from the original error response, if available. * * @return the HTTP status code, or {@code null} if not available + * @since 1.10.0 */ @Beta @Nullable public Integer getStatusCode() { - return Optional.ofNullable(getErrorResponse()).map(ErrorResponse::getCode).orElse(null); + return Optional.ofNullable(getErrorResponse()) + .map(ErrorResponse::getError) + .map(Error::getCode) + .orElse(null); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationError.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationError.java index 124535796..ad6b9256e 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationError.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationError.java @@ -3,7 +3,10 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.google.common.annotations.Beta; import com.sap.ai.sdk.core.common.ClientError; +import com.sap.ai.sdk.orchestration.model.Error; import com.sap.ai.sdk.orchestration.model.ErrorResponse; +import com.sap.ai.sdk.orchestration.model.ErrorResponseStreaming; +import com.sap.ai.sdk.orchestration.model.ErrorStreaming; import javax.annotation.Nonnull; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -14,21 +17,52 @@ * * @since 1.1.0 */ -@AllArgsConstructor(onConstructor = @__({@JsonCreator}), access = AccessLevel.PROTECTED) -@Value @Beta -public class OrchestrationError implements ClientError { - ErrorResponse errorResponse; +public interface OrchestrationError extends ClientError { /** - * Gets the error message from the contained original response. + * Orchestration error response for synchronous requests. * - * @return the error message + * @since 1.10.0 */ - @Nonnull - public String getMessage() { - return errorResponse.getCode() == 500 - ? errorResponse.getMessage() + " located in " + errorResponse.getLocation() - : errorResponse.getMessage(); + @AllArgsConstructor(onConstructor = @__({@JsonCreator}), access = AccessLevel.PROTECTED) + @Value + class Synchronous implements OrchestrationError { + ErrorResponse errorResponse; + + /** + * Gets the error message from the contained original response. + * + * @return the error message + */ + @Nonnull + public String getMessage() { + final Error e = errorResponse.getError(); + final String message = e.getMessage(); + return e.getCode() == 500 ? "%s located in %s".formatted(message, e.getLocation()) : message; + } + } + + /** + * Orchestration error response for streaming requests. + * + * @since 1.10.0 + */ + @AllArgsConstructor(onConstructor = @__({@JsonCreator}), access = AccessLevel.PROTECTED) + @Value + class Streaming implements OrchestrationError { + ErrorResponseStreaming errorResponse; + + /** + * Gets the error message from the contained original response. + * + * @return the error message + */ + @Nonnull + public String getMessage() { + final ErrorStreaming e = errorResponse.getError(); + final String message = e.getMessage(); + return e.getCode() == 500 ? "%s located in %s".formatted(message, e.getLocation()) : message; + } } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationExceptionFactory.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationExceptionFactory.java index 62a3a1635..756bd1451 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationExceptionFactory.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationExceptionFactory.java @@ -2,9 +2,13 @@ import com.google.common.annotations.Beta; import com.sap.ai.sdk.core.common.ClientExceptionFactory; +import com.sap.ai.sdk.orchestration.model.Error; import com.sap.ai.sdk.orchestration.model.ErrorResponse; +import com.sap.ai.sdk.orchestration.model.ErrorResponseStreaming; +import com.sap.ai.sdk.orchestration.model.ErrorStreaming; import com.sap.ai.sdk.orchestration.model.GenericModuleResult; import com.sap.ai.sdk.orchestration.model.ModuleResults; +import com.sap.ai.sdk.orchestration.model.ModuleResultsStreaming; import java.util.Collections; import java.util.Map; import java.util.Optional; @@ -38,12 +42,25 @@ public OrchestrationClientException buildFromClientError( @Nonnull private Map extractInputFilterDetails(@Nonnull final OrchestrationError error) { - return Optional.of(error.getErrorResponse()) - .map(ErrorResponse::getModuleResults) - .map(ModuleResults::getInputFiltering) - .map(GenericModuleResult::getData) - .filter(Map.class::isInstance) - .map(map -> (Map) map) - .orElseGet(Collections::emptyMap); + if (error instanceof OrchestrationError.Synchronous synchronousError) { + return Optional.of(synchronousError.getErrorResponse()) + .map(ErrorResponse::getError) + .map(Error::getIntermediateResults) + .map(ModuleResults::getInputFiltering) + .map(GenericModuleResult::getData) + .filter(Map.class::isInstance) + .map(map -> (Map) map) + .orElseGet(Collections::emptyMap); + } else if (error instanceof OrchestrationError.Streaming streamingError) { + return Optional.of(streamingError.getErrorResponse()) + .map(ErrorResponseStreaming::getError) + .map(ErrorStreaming::getIntermediateResults) + .map(ModuleResultsStreaming::getInputFiltering) + .map(GenericModuleResult::getData) + .filter(Map.class::isInstance) + .map(map -> (Map) map) + .orElseGet(Collections::emptyMap); + } + return Collections.emptyMap(); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationHttpExecutor.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationHttpExecutor.java index 6f4b061f1..80a9a43d2 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationHttpExecutor.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationHttpExecutor.java @@ -48,7 +48,9 @@ T execute( val handler = new ClientResponseHandler<>( - responseType, OrchestrationError.class, new OrchestrationExceptionFactory()) + responseType, + OrchestrationError.Synchronous.class, + new OrchestrationExceptionFactory()) .objectMapper(JACKSON); return client.execute(request, handler); @@ -65,17 +67,18 @@ responseType, OrchestrationError.class, new OrchestrationExceptionFactory()) } @Nonnull - Stream stream(@Nonnull final Object payload) { + Stream stream( + @Nonnull final String path, @Nonnull final Object payload) { try { val json = JACKSON.writeValueAsString(payload); - val request = new HttpPost("/completion"); + val request = new HttpPost(path); request.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); val client = getHttpClient(); return new ClientStreamingHandler<>( OrchestrationChatCompletionDelta.class, - OrchestrationError.class, + OrchestrationError.Streaming.class, new OrchestrationExceptionFactory()) .objectMapper(JACKSON) .handleStreamingResponse(client.executeOpen(null, request, null)); diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationJacksonConfiguration.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationJacksonConfiguration.java index 3cb017575..9ad86bfd7 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationJacksonConfiguration.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationJacksonConfiguration.java @@ -5,12 +5,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.google.common.annotations.Beta; +import com.sap.ai.sdk.orchestration.model.AzureContentSafetyInput; +import com.sap.ai.sdk.orchestration.model.AzureContentSafetyOutput; import com.sap.ai.sdk.orchestration.model.ChatMessage; import com.sap.ai.sdk.orchestration.model.TemplateResponseFormat; import javax.annotation.Nonnull; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import lombok.val; /** * Internal utility class for getting a default object mapper with preset configuration. @@ -33,18 +34,22 @@ public class OrchestrationJacksonConfiguration { @Beta public static ObjectMapper getOrchestrationObjectMapper() { - val jackson = getDefaultObjectMapper(); - - jackson.addMixIn(ChatMessage.class, JacksonMixins.ChatMessageMixin.class); - final var module = new SimpleModule() .addDeserializer( TemplateResponseFormat.class, PolymorphicFallbackDeserializer.fromJsonSubTypes(TemplateResponseFormat.class)) .setMixInAnnotation( - TemplateResponseFormat.class, JacksonMixins.ResponseFormatSubTypesMixin.class); - jackson.registerModule(module); - return jackson; + TemplateResponseFormat.class, JacksonMixins.ResponseFormatSubTypesMixin.class) + .setMixInAnnotation( + AzureContentSafetyOutput.class, JacksonMixins.AzureContentSafetyCaseAgnostic.class) + .setMixInAnnotation( + AzureContentSafetyInput.class, JacksonMixins.AzureContentSafetyCaseAgnostic.class); + + return getDefaultObjectMapper() + .rebuild() + .addModule(module) + .addMixIn(ChatMessage.class, JacksonMixins.ChatMessageMixin.class) + .build(); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfig.java index 1b8b7ca19..0fca60664 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfig.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfig.java @@ -4,11 +4,11 @@ import com.sap.ai.sdk.orchestration.model.FilteringModuleConfig; import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig; import com.sap.ai.sdk.orchestration.model.InputFilteringConfig; -import com.sap.ai.sdk.orchestration.model.LLMModuleConfig; +import com.sap.ai.sdk.orchestration.model.LLMModelDetails; import com.sap.ai.sdk.orchestration.model.MaskingModuleConfig; import com.sap.ai.sdk.orchestration.model.OutputFilteringConfig; +import com.sap.ai.sdk.orchestration.model.PromptTemplatingModuleConfigPrompt; import com.sap.ai.sdk.orchestration.model.SAPDocumentTranslation; -import com.sap.ai.sdk.orchestration.model.TemplatingModuleConfig; import java.util.ArrayList; import java.util.Arrays; import java.util.Objects; @@ -54,7 +54,7 @@ public class OrchestrationModuleConfig { * href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/model-configuration"> * SAP AI Core: Orchestration - Model Configuration */ - @Nullable LLMModuleConfig llmConfig; + @Nullable LLMModelDetails llmConfig; /** * A template to be populated with input parameters. Upon request execution, this template will be @@ -63,7 +63,7 @@ public class OrchestrationModuleConfig { * @link SAP * AI Core: Orchestration - Templating */ - @Nullable TemplatingModuleConfig templateConfig; + @Nullable PromptTemplatingModuleConfigPrompt templateConfig; /** * A masking configuration to pseudonymous or anonymize sensitive data in the input. diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationTemplate.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationTemplate.java index 2a56ee619..e5fb76861 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationTemplate.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationTemplate.java @@ -8,12 +8,12 @@ import com.google.common.annotations.Beta; import com.sap.ai.sdk.orchestration.model.ChatCompletionTool; import com.sap.ai.sdk.orchestration.model.ChatMessage; +import com.sap.ai.sdk.orchestration.model.PromptTemplatingModuleConfigPrompt; import com.sap.ai.sdk.orchestration.model.ResponseFormatJsonObject; import com.sap.ai.sdk.orchestration.model.ResponseFormatJsonSchema; import com.sap.ai.sdk.orchestration.model.ResponseFormatJsonSchemaJsonSchema; import com.sap.ai.sdk.orchestration.model.Template; import com.sap.ai.sdk.orchestration.model.TemplateResponseFormat; -import com.sap.ai.sdk.orchestration.model.TemplatingModuleConfig; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -80,7 +80,7 @@ public OrchestrationTemplate withMessages(@Nonnull final Message... messages) { */ @Override @Nonnull - protected TemplatingModuleConfig toLowLevel() { + protected PromptTemplatingModuleConfigPrompt toLowLevel() { final List template = this.template != null ? this.template : List.of(); final Map defaults = this.defaults != null ? this.defaults : new HashMap<>(); final List tools = this.tools != null ? this.tools : new ArrayList<>(); diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationTemplateReference.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationTemplateReference.java index abb22eeed..e88ac06a3 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationTemplateReference.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationTemplateReference.java @@ -1,9 +1,9 @@ package com.sap.ai.sdk.orchestration; import com.google.common.annotations.Beta; +import com.sap.ai.sdk.orchestration.model.PromptTemplatingModuleConfigPrompt; import com.sap.ai.sdk.orchestration.model.TemplateRef; import com.sap.ai.sdk.orchestration.model.TemplateRefTemplateRef; -import com.sap.ai.sdk.orchestration.model.TemplatingModuleConfig; import javax.annotation.Nonnull; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -29,7 +29,7 @@ public class OrchestrationTemplateReference extends TemplateConfig { */ @Nonnull @Override - protected TemplatingModuleConfig toLowLevel() { + protected PromptTemplatingModuleConfigPrompt toLowLevel() { return TemplateRef.create().templateRef(reference); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/TemplateConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/TemplateConfig.java index be6a52f0e..15bab9c85 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/TemplateConfig.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/TemplateConfig.java @@ -1,9 +1,9 @@ package com.sap.ai.sdk.orchestration; import com.google.common.annotations.Beta; +import com.sap.ai.sdk.orchestration.model.PromptTemplatingModuleConfigPrompt; import com.sap.ai.sdk.orchestration.model.TemplateRefByID; import com.sap.ai.sdk.orchestration.model.TemplateRefByScenarioNameVersion; -import com.sap.ai.sdk.orchestration.model.TemplatingModuleConfig; import javax.annotation.Nonnull; import lombok.EqualsAndHashCode; @@ -22,7 +22,7 @@ public abstract class TemplateConfig { * @return The low-level representation of the template. */ @Nonnull - protected abstract TemplatingModuleConfig toLowLevel(); + protected abstract PromptTemplatingModuleConfigPrompt toLowLevel(); /** * Build a template. diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/AzureContentSafetyInput.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/AzureContentSafetyInput.java index 4c4ccd4af..209d91377 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/AzureContentSafetyInput.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/AzureContentSafetyInput.java @@ -28,19 +28,19 @@ public class AzureContentSafetyInput // CHECKSTYLE:ON { - @JsonProperty("Hate") + @JsonProperty("hate") private AzureThreshold hate; - @JsonProperty("SelfHarm") + @JsonProperty("self_harm") private AzureThreshold selfHarm; - @JsonProperty("Sexual") + @JsonProperty("sexual") private AzureThreshold sexual; - @JsonProperty("Violence") + @JsonProperty("violence") private AzureThreshold violence; - @JsonProperty("PromptShield") + @JsonProperty("prompt_shield") private Boolean promptShield = false; @JsonAnySetter @JsonAnyGetter diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/AzureContentSafetyOutput.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/AzureContentSafetyOutput.java index f428f183a..b8d9db163 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/AzureContentSafetyOutput.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/AzureContentSafetyOutput.java @@ -28,16 +28,16 @@ public class AzureContentSafetyOutput // CHECKSTYLE:ON { - @JsonProperty("Hate") + @JsonProperty("hate") private AzureThreshold hate; - @JsonProperty("SelfHarm") + @JsonProperty("self_harm") private AzureThreshold selfHarm; - @JsonProperty("Sexual") + @JsonProperty("sexual") private AzureThreshold sexual; - @JsonProperty("Violence") + @JsonProperty("violence") private AzureThreshold violence; @JsonAnySetter @JsonAnyGetter diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostRequest.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostRequest.java index bb81b40ab..08290ff96 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostRequest.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostRequest.java @@ -31,11 +31,11 @@ public class CompletionPostRequest // CHECKSTYLE:ON { - @JsonProperty("orchestration_config") - private OrchestrationConfig orchestrationConfig; + @JsonProperty("config") + private OrchestrationConfig config; - @JsonProperty("input_params") - private Map inputParams = new HashMap<>(); + @JsonProperty("placeholder_values") + private Map placeholderValues = new HashMap<>(); @JsonProperty("messages_history") private List messagesHistory; @@ -47,86 +47,84 @@ public class CompletionPostRequest protected CompletionPostRequest() {} /** - * Set the orchestrationConfig of this {@link CompletionPostRequest} instance and return the same - * instance. + * Set the config of this {@link CompletionPostRequest} instance and return the same instance. * - * @param orchestrationConfig The orchestrationConfig of this {@link CompletionPostRequest} + * @param config The config of this {@link CompletionPostRequest} * @return The same instance of this {@link CompletionPostRequest} class */ @Nonnull - public CompletionPostRequest orchestrationConfig( - @Nonnull final OrchestrationConfig orchestrationConfig) { - this.orchestrationConfig = orchestrationConfig; + public CompletionPostRequest config(@Nonnull final OrchestrationConfig config) { + this.config = config; return this; } /** - * Get orchestrationConfig + * Get config * - * @return orchestrationConfig The orchestrationConfig of this {@link CompletionPostRequest} - * instance. + * @return config The config of this {@link CompletionPostRequest} instance. */ @Nonnull - public OrchestrationConfig getOrchestrationConfig() { - return orchestrationConfig; + public OrchestrationConfig getConfig() { + return config; } /** - * Set the orchestrationConfig of this {@link CompletionPostRequest} instance. + * Set the config of this {@link CompletionPostRequest} instance. * - * @param orchestrationConfig The orchestrationConfig of this {@link CompletionPostRequest} + * @param config The config of this {@link CompletionPostRequest} */ - public void setOrchestrationConfig(@Nonnull final OrchestrationConfig orchestrationConfig) { - this.orchestrationConfig = orchestrationConfig; + public void setConfig(@Nonnull final OrchestrationConfig config) { + this.config = config; } /** - * Set the inputParams of this {@link CompletionPostRequest} instance and return the same + * Set the placeholderValues of this {@link CompletionPostRequest} instance and return the same * instance. * - * @param inputParams The inputParams of this {@link CompletionPostRequest} + * @param placeholderValues The placeholderValues of this {@link CompletionPostRequest} * @return The same instance of this {@link CompletionPostRequest} class */ @Nonnull - public CompletionPostRequest inputParams(@Nullable final Map inputParams) { - this.inputParams = inputParams; + public CompletionPostRequest placeholderValues( + @Nullable final Map placeholderValues) { + this.placeholderValues = placeholderValues; return this; } /** - * Put one inputParams instance to this {@link CompletionPostRequest} instance. + * Put one placeholderValues instance to this {@link CompletionPostRequest} instance. * - * @param key The String key of this inputParams instance - * @param inputParamsItem The inputParams that should be added under the given key + * @param key The String key of this placeholderValues instance + * @param placeholderValuesItem The placeholderValues that should be added under the given key * @return The same instance of type {@link CompletionPostRequest} */ @Nonnull - public CompletionPostRequest putinputParamsItem( - @Nonnull final String key, @Nonnull final String inputParamsItem) { - if (this.inputParams == null) { - this.inputParams = new HashMap<>(); + public CompletionPostRequest putplaceholderValuesItem( + @Nonnull final String key, @Nonnull final String placeholderValuesItem) { + if (this.placeholderValues == null) { + this.placeholderValues = new HashMap<>(); } - this.inputParams.put(key, inputParamsItem); + this.placeholderValues.put(key, placeholderValuesItem); return this; } /** - * Get inputParams + * Get placeholderValues * - * @return inputParams The inputParams of this {@link CompletionPostRequest} instance. + * @return placeholderValues The placeholderValues of this {@link CompletionPostRequest} instance. */ @Nonnull - public Map getInputParams() { - return inputParams; + public Map getPlaceholderValues() { + return placeholderValues; } /** - * Set the inputParams of this {@link CompletionPostRequest} instance. + * Set the placeholderValues of this {@link CompletionPostRequest} instance. * - * @param inputParams The inputParams of this {@link CompletionPostRequest} + * @param placeholderValues The placeholderValues of this {@link CompletionPostRequest} */ - public void setInputParams(@Nullable final Map inputParams) { - this.inputParams = inputParams; + public void setPlaceholderValues(@Nullable final Map placeholderValues) { + this.placeholderValues = placeholderValues; } /** @@ -219,8 +217,8 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc @Nonnull public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); - if (orchestrationConfig != null) declaredFields.put("orchestrationConfig", orchestrationConfig); - if (inputParams != null) declaredFields.put("inputParams", inputParams); + if (config != null) declaredFields.put("config", config); + if (placeholderValues != null) declaredFields.put("placeholderValues", placeholderValues); if (messagesHistory != null) declaredFields.put("messagesHistory", messagesHistory); return declaredFields; } @@ -247,14 +245,14 @@ public boolean equals(@Nullable final java.lang.Object o) { } final CompletionPostRequest completionPostRequest = (CompletionPostRequest) o; return Objects.equals(this.cloudSdkCustomFields, completionPostRequest.cloudSdkCustomFields) - && Objects.equals(this.orchestrationConfig, completionPostRequest.orchestrationConfig) - && Objects.equals(this.inputParams, completionPostRequest.inputParams) + && Objects.equals(this.config, completionPostRequest.config) + && Objects.equals(this.placeholderValues, completionPostRequest.placeholderValues) && Objects.equals(this.messagesHistory, completionPostRequest.messagesHistory); } @Override public int hashCode() { - return Objects.hash(orchestrationConfig, inputParams, messagesHistory, cloudSdkCustomFields); + return Objects.hash(config, placeholderValues, messagesHistory, cloudSdkCustomFields); } @Override @@ -262,10 +260,8 @@ public int hashCode() { public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class CompletionPostRequest {\n"); - sb.append(" orchestrationConfig: ") - .append(toIndentedString(orchestrationConfig)) - .append("\n"); - sb.append(" inputParams: ").append(toIndentedString(inputParams)).append("\n"); + sb.append(" config: ").append(toIndentedString(config)).append("\n"); + sb.append(" placeholderValues: ").append(toIndentedString(placeholderValues)).append("\n"); sb.append(" messagesHistory: ").append(toIndentedString(messagesHistory)).append("\n"); cloudSdkCustomFields.forEach( (k, v) -> @@ -289,19 +285,17 @@ private String toIndentedString(final java.lang.Object o) { * instance with all required arguments. */ public static Builder create() { - return (orchestrationConfig) -> - new CompletionPostRequest().orchestrationConfig(orchestrationConfig); + return (config) -> new CompletionPostRequest().config(config); } /** Builder helper class. */ public interface Builder { /** - * Set the orchestrationConfig of this {@link CompletionPostRequest} instance. + * Set the config of this {@link CompletionPostRequest} instance. * - * @param orchestrationConfig The orchestrationConfig of this {@link CompletionPostRequest} + * @param config The config of this {@link CompletionPostRequest} * @return The CompletionPostRequest instance. */ - CompletionPostRequest orchestrationConfig( - @Nonnull final OrchestrationConfig orchestrationConfig); + CompletionPostRequest config(@Nonnull final OrchestrationConfig config); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostResponse.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostResponse.java index 245223966..c5b0f0908 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostResponse.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostResponse.java @@ -31,11 +31,11 @@ public class CompletionPostResponse @JsonProperty("request_id") private String requestId; - @JsonProperty("module_results") - private ModuleResults moduleResults; + @JsonProperty("intermediate_results") + private ModuleResults intermediateResults; - @JsonProperty("orchestration_result") - private LLMModuleResult orchestrationResult; + @JsonProperty("final_result") + private LLMModuleResult finalResult; @JsonAnySetter @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); @@ -75,69 +75,69 @@ public void setRequestId(@Nonnull final String requestId) { } /** - * Set the moduleResults of this {@link CompletionPostResponse} instance and return the same + * Set the intermediateResults of this {@link CompletionPostResponse} instance and return the same * instance. * - * @param moduleResults The moduleResults of this {@link CompletionPostResponse} + * @param intermediateResults The intermediateResults of this {@link CompletionPostResponse} * @return The same instance of this {@link CompletionPostResponse} class */ @Nonnull - public CompletionPostResponse moduleResults(@Nonnull final ModuleResults moduleResults) { - this.moduleResults = moduleResults; + public CompletionPostResponse intermediateResults( + @Nonnull final ModuleResults intermediateResults) { + this.intermediateResults = intermediateResults; return this; } /** - * Get moduleResults + * Get intermediateResults * - * @return moduleResults The moduleResults of this {@link CompletionPostResponse} instance. + * @return intermediateResults The intermediateResults of this {@link CompletionPostResponse} + * instance. */ @Nonnull - public ModuleResults getModuleResults() { - return moduleResults; + public ModuleResults getIntermediateResults() { + return intermediateResults; } /** - * Set the moduleResults of this {@link CompletionPostResponse} instance. + * Set the intermediateResults of this {@link CompletionPostResponse} instance. * - * @param moduleResults The moduleResults of this {@link CompletionPostResponse} + * @param intermediateResults The intermediateResults of this {@link CompletionPostResponse} */ - public void setModuleResults(@Nonnull final ModuleResults moduleResults) { - this.moduleResults = moduleResults; + public void setIntermediateResults(@Nonnull final ModuleResults intermediateResults) { + this.intermediateResults = intermediateResults; } /** - * Set the orchestrationResult of this {@link CompletionPostResponse} instance and return the same + * Set the finalResult of this {@link CompletionPostResponse} instance and return the same * instance. * - * @param orchestrationResult The orchestrationResult of this {@link CompletionPostResponse} + * @param finalResult The finalResult of this {@link CompletionPostResponse} * @return The same instance of this {@link CompletionPostResponse} class */ @Nonnull - public CompletionPostResponse orchestrationResult( - @Nonnull final LLMModuleResult orchestrationResult) { - this.orchestrationResult = orchestrationResult; + public CompletionPostResponse finalResult(@Nonnull final LLMModuleResult finalResult) { + this.finalResult = finalResult; return this; } /** - * Get orchestrationResult + * Get finalResult * - * @return orchestrationResult The orchestrationResult of this {@link CompletionPostResponse} - * instance. + * @return finalResult The finalResult of this {@link CompletionPostResponse} instance. */ @Nonnull - public LLMModuleResult getOrchestrationResult() { - return orchestrationResult; + public LLMModuleResult getFinalResult() { + return finalResult; } /** - * Set the orchestrationResult of this {@link CompletionPostResponse} instance. + * Set the finalResult of this {@link CompletionPostResponse} instance. * - * @param orchestrationResult The orchestrationResult of this {@link CompletionPostResponse} + * @param finalResult The finalResult of this {@link CompletionPostResponse} */ - public void setOrchestrationResult(@Nonnull final LLMModuleResult orchestrationResult) { - this.orchestrationResult = orchestrationResult; + public void setFinalResult(@Nonnull final LLMModuleResult finalResult) { + this.finalResult = finalResult; } /** @@ -180,8 +180,8 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); if (requestId != null) declaredFields.put("requestId", requestId); - if (moduleResults != null) declaredFields.put("moduleResults", moduleResults); - if (orchestrationResult != null) declaredFields.put("orchestrationResult", orchestrationResult); + if (intermediateResults != null) declaredFields.put("intermediateResults", intermediateResults); + if (finalResult != null) declaredFields.put("finalResult", finalResult); return declaredFields; } @@ -208,13 +208,13 @@ public boolean equals(@Nullable final java.lang.Object o) { final CompletionPostResponse completionPostResponse = (CompletionPostResponse) o; return Objects.equals(this.cloudSdkCustomFields, completionPostResponse.cloudSdkCustomFields) && Objects.equals(this.requestId, completionPostResponse.requestId) - && Objects.equals(this.moduleResults, completionPostResponse.moduleResults) - && Objects.equals(this.orchestrationResult, completionPostResponse.orchestrationResult); + && Objects.equals(this.intermediateResults, completionPostResponse.intermediateResults) + && Objects.equals(this.finalResult, completionPostResponse.finalResult); } @Override public int hashCode() { - return Objects.hash(requestId, moduleResults, orchestrationResult, cloudSdkCustomFields); + return Objects.hash(requestId, intermediateResults, finalResult, cloudSdkCustomFields); } @Override @@ -223,10 +223,10 @@ public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class CompletionPostResponse {\n"); sb.append(" requestId: ").append(toIndentedString(requestId)).append("\n"); - sb.append(" moduleResults: ").append(toIndentedString(moduleResults)).append("\n"); - sb.append(" orchestrationResult: ") - .append(toIndentedString(orchestrationResult)) + sb.append(" intermediateResults: ") + .append(toIndentedString(intermediateResults)) .append("\n"); + sb.append(" finalResult: ").append(toIndentedString(finalResult)).append("\n"); cloudSdkCustomFields.forEach( (k, v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); @@ -250,12 +250,12 @@ private String toIndentedString(final java.lang.Object o) { */ public static Builder create() { return (requestId) -> - (moduleResults) -> - (orchestrationResult) -> + (intermediateResults) -> + (finalResult) -> new CompletionPostResponse() .requestId(requestId) - .moduleResults(moduleResults) - .orchestrationResult(orchestrationResult); + .intermediateResults(intermediateResults) + .finalResult(finalResult); } /** Builder helper class. */ @@ -272,22 +272,22 @@ public interface Builder { /** Builder helper class. */ public interface Builder1 { /** - * Set the moduleResults of this {@link CompletionPostResponse} instance. + * Set the intermediateResults of this {@link CompletionPostResponse} instance. * - * @param moduleResults The moduleResults of this {@link CompletionPostResponse} + * @param intermediateResults The intermediateResults of this {@link CompletionPostResponse} * @return The CompletionPostResponse builder. */ - Builder2 moduleResults(@Nonnull final ModuleResults moduleResults); + Builder2 intermediateResults(@Nonnull final ModuleResults intermediateResults); } /** Builder helper class. */ public interface Builder2 { /** - * Set the orchestrationResult of this {@link CompletionPostResponse} instance. + * Set the finalResult of this {@link CompletionPostResponse} instance. * - * @param orchestrationResult The orchestrationResult of this {@link CompletionPostResponse} + * @param finalResult The finalResult of this {@link CompletionPostResponse} * @return The CompletionPostResponse instance. */ - CompletionPostResponse orchestrationResult(@Nonnull final LLMModuleResult orchestrationResult); + CompletionPostResponse finalResult(@Nonnull final LLMModuleResult finalResult); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostResponseStreaming.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostResponseStreaming.java index f68c93146..7f4f759ff 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostResponseStreaming.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostResponseStreaming.java @@ -31,11 +31,11 @@ public class CompletionPostResponseStreaming @JsonProperty("request_id") private String requestId; - @JsonProperty("module_results") - private ModuleResultsStreaming moduleResults; + @JsonProperty("intermediate_results") + private ModuleResultsStreaming intermediateResults; - @JsonProperty("orchestration_result") - private LLMModuleResultStreaming orchestrationResult; + @JsonProperty("final_result") + private LLMModuleResultStreaming finalResult; @JsonAnySetter @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); @@ -76,73 +76,72 @@ public void setRequestId(@Nonnull final String requestId) { } /** - * Set the moduleResults of this {@link CompletionPostResponseStreaming} instance and return the - * same instance. + * Set the intermediateResults of this {@link CompletionPostResponseStreaming} instance and return + * the same instance. * - * @param moduleResults The moduleResults of this {@link CompletionPostResponseStreaming} + * @param intermediateResults The intermediateResults of this {@link + * CompletionPostResponseStreaming} * @return The same instance of this {@link CompletionPostResponseStreaming} class */ @Nonnull - public CompletionPostResponseStreaming moduleResults( - @Nullable final ModuleResultsStreaming moduleResults) { - this.moduleResults = moduleResults; + public CompletionPostResponseStreaming intermediateResults( + @Nullable final ModuleResultsStreaming intermediateResults) { + this.intermediateResults = intermediateResults; return this; } /** - * Get moduleResults + * Get intermediateResults * - * @return moduleResults The moduleResults of this {@link CompletionPostResponseStreaming} - * instance. + * @return intermediateResults The intermediateResults of this {@link + * CompletionPostResponseStreaming} instance. */ @Nonnull - public ModuleResultsStreaming getModuleResults() { - return moduleResults; + public ModuleResultsStreaming getIntermediateResults() { + return intermediateResults; } /** - * Set the moduleResults of this {@link CompletionPostResponseStreaming} instance. + * Set the intermediateResults of this {@link CompletionPostResponseStreaming} instance. * - * @param moduleResults The moduleResults of this {@link CompletionPostResponseStreaming} + * @param intermediateResults The intermediateResults of this {@link + * CompletionPostResponseStreaming} */ - public void setModuleResults(@Nullable final ModuleResultsStreaming moduleResults) { - this.moduleResults = moduleResults; + public void setIntermediateResults(@Nullable final ModuleResultsStreaming intermediateResults) { + this.intermediateResults = intermediateResults; } /** - * Set the orchestrationResult of this {@link CompletionPostResponseStreaming} instance and return - * the same instance. + * Set the finalResult of this {@link CompletionPostResponseStreaming} instance and return the + * same instance. * - * @param orchestrationResult The orchestrationResult of this {@link - * CompletionPostResponseStreaming} + * @param finalResult The finalResult of this {@link CompletionPostResponseStreaming} * @return The same instance of this {@link CompletionPostResponseStreaming} class */ @Nonnull - public CompletionPostResponseStreaming orchestrationResult( - @Nullable final LLMModuleResultStreaming orchestrationResult) { - this.orchestrationResult = orchestrationResult; + public CompletionPostResponseStreaming finalResult( + @Nullable final LLMModuleResultStreaming finalResult) { + this.finalResult = finalResult; return this; } /** - * Get orchestrationResult + * Get finalResult * - * @return orchestrationResult The orchestrationResult of this {@link - * CompletionPostResponseStreaming} instance. + * @return finalResult The finalResult of this {@link CompletionPostResponseStreaming} instance. */ @Nonnull - public LLMModuleResultStreaming getOrchestrationResult() { - return orchestrationResult; + public LLMModuleResultStreaming getFinalResult() { + return finalResult; } /** - * Set the orchestrationResult of this {@link CompletionPostResponseStreaming} instance. + * Set the finalResult of this {@link CompletionPostResponseStreaming} instance. * - * @param orchestrationResult The orchestrationResult of this {@link - * CompletionPostResponseStreaming} + * @param finalResult The finalResult of this {@link CompletionPostResponseStreaming} */ - public void setOrchestrationResult(@Nullable final LLMModuleResultStreaming orchestrationResult) { - this.orchestrationResult = orchestrationResult; + public void setFinalResult(@Nullable final LLMModuleResultStreaming finalResult) { + this.finalResult = finalResult; } /** @@ -186,8 +185,8 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); if (requestId != null) declaredFields.put("requestId", requestId); - if (moduleResults != null) declaredFields.put("moduleResults", moduleResults); - if (orchestrationResult != null) declaredFields.put("orchestrationResult", orchestrationResult); + if (intermediateResults != null) declaredFields.put("intermediateResults", intermediateResults); + if (finalResult != null) declaredFields.put("finalResult", finalResult); return declaredFields; } @@ -217,14 +216,14 @@ public boolean equals(@Nullable final java.lang.Object o) { return Objects.equals( this.cloudSdkCustomFields, completionPostResponseStreaming.cloudSdkCustomFields) && Objects.equals(this.requestId, completionPostResponseStreaming.requestId) - && Objects.equals(this.moduleResults, completionPostResponseStreaming.moduleResults) && Objects.equals( - this.orchestrationResult, completionPostResponseStreaming.orchestrationResult); + this.intermediateResults, completionPostResponseStreaming.intermediateResults) + && Objects.equals(this.finalResult, completionPostResponseStreaming.finalResult); } @Override public int hashCode() { - return Objects.hash(requestId, moduleResults, orchestrationResult, cloudSdkCustomFields); + return Objects.hash(requestId, intermediateResults, finalResult, cloudSdkCustomFields); } @Override @@ -233,10 +232,10 @@ public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class CompletionPostResponseStreaming {\n"); sb.append(" requestId: ").append(toIndentedString(requestId)).append("\n"); - sb.append(" moduleResults: ").append(toIndentedString(moduleResults)).append("\n"); - sb.append(" orchestrationResult: ") - .append(toIndentedString(orchestrationResult)) + sb.append(" intermediateResults: ") + .append(toIndentedString(intermediateResults)) .append("\n"); + sb.append(" finalResult: ").append(toIndentedString(finalResult)).append("\n"); cloudSdkCustomFields.forEach( (k, v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Error.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Error.java new file mode 100644 index 000000000..a34b16ba4 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Error.java @@ -0,0 +1,372 @@ +/* + * Internal Orchestration Service API + * 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. + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.orchestration.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Error */ +// CHECKSTYLE:OFF +public class Error +// CHECKSTYLE:ON +{ + @JsonProperty("request_id") + private String requestId; + + @JsonProperty("code") + private Integer code; + + @JsonProperty("message") + private String message; + + @JsonProperty("location") + private String location; + + @JsonProperty("intermediate_results") + private ModuleResults intermediateResults; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for Error. */ + protected Error() {} + + /** + * Set the requestId of this {@link Error} instance and return the same instance. + * + * @param requestId The requestId of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error requestId(@Nonnull final String requestId) { + this.requestId = requestId; + return this; + } + + /** + * Get requestId + * + * @return requestId The requestId of this {@link Error} instance. + */ + @Nonnull + public String getRequestId() { + return requestId; + } + + /** + * Set the requestId of this {@link Error} instance. + * + * @param requestId The requestId of this {@link Error} + */ + public void setRequestId(@Nonnull final String requestId) { + this.requestId = requestId; + } + + /** + * Set the code of this {@link Error} instance and return the same instance. + * + * @param code The code of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error code(@Nonnull final Integer code) { + this.code = code; + return this; + } + + /** + * Get code + * + * @return code The code of this {@link Error} instance. + */ + @Nonnull + public Integer getCode() { + return code; + } + + /** + * Set the code of this {@link Error} instance. + * + * @param code The code of this {@link Error} + */ + public void setCode(@Nonnull final Integer code) { + this.code = code; + } + + /** + * Set the message of this {@link Error} instance and return the same instance. + * + * @param message The message of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error message(@Nonnull final String message) { + this.message = message; + return this; + } + + /** + * Get message + * + * @return message The message of this {@link Error} instance. + */ + @Nonnull + public String getMessage() { + return message; + } + + /** + * Set the message of this {@link Error} instance. + * + * @param message The message of this {@link Error} + */ + public void setMessage(@Nonnull final String message) { + this.message = message; + } + + /** + * Set the location of this {@link Error} instance and return the same instance. + * + * @param location Where the error occurred + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error location(@Nonnull final String location) { + this.location = location; + return this; + } + + /** + * Where the error occurred + * + * @return location The location of this {@link Error} instance. + */ + @Nonnull + public String getLocation() { + return location; + } + + /** + * Set the location of this {@link Error} instance. + * + * @param location Where the error occurred + */ + public void setLocation(@Nonnull final String location) { + this.location = location; + } + + /** + * Set the intermediateResults of this {@link Error} instance and return the same instance. + * + * @param intermediateResults The intermediateResults of this {@link Error} + * @return The same instance of this {@link Error} class + */ + @Nonnull + public Error intermediateResults(@Nullable final ModuleResults intermediateResults) { + this.intermediateResults = intermediateResults; + return this; + } + + /** + * Get intermediateResults + * + * @return intermediateResults The intermediateResults of this {@link Error} instance. + */ + @Nonnull + public ModuleResults getIntermediateResults() { + return intermediateResults; + } + + /** + * Set the intermediateResults of this {@link Error} instance. + * + * @param intermediateResults The intermediateResults of this {@link Error} + */ + public void setIntermediateResults(@Nullable final ModuleResults intermediateResults) { + this.intermediateResults = intermediateResults; + } + + /** + * Get the names of the unrecognizable properties of the {@link Error}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link Error} instance. + * + * @deprecated Use {@link #toMap()} instead. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + @Deprecated + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("Error has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link Error} instance including unrecognized + * properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (requestId != null) declaredFields.put("requestId", requestId); + if (code != null) declaredFields.put("code", code); + if (message != null) declaredFields.put("message", message); + if (location != null) declaredFields.put("location", location); + if (intermediateResults != null) declaredFields.put("intermediateResults", intermediateResults); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link Error} instance. If the map previously contained + * a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Error error = (Error) o; + return Objects.equals(this.cloudSdkCustomFields, error.cloudSdkCustomFields) + && Objects.equals(this.requestId, error.requestId) + && Objects.equals(this.code, error.code) + && Objects.equals(this.message, error.message) + && Objects.equals(this.location, error.location) + && Objects.equals(this.intermediateResults, error.intermediateResults); + } + + @Override + public int hashCode() { + return Objects.hash( + requestId, code, message, location, intermediateResults, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class Error {\n"); + sb.append(" requestId: ").append(toIndentedString(requestId)).append("\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append(" location: ").append(toIndentedString(location)).append("\n"); + sb.append(" intermediateResults: ") + .append(toIndentedString(intermediateResults)) + .append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link Error} instance with + * all required arguments. + */ + public static Builder create() { + return (requestId) -> + (code) -> + (message) -> + (location) -> + new Error().requestId(requestId).code(code).message(message).location(location); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the requestId of this {@link Error} instance. + * + * @param requestId The requestId of this {@link Error} + * @return The Error builder. + */ + Builder1 requestId(@Nonnull final String requestId); + } + + /** Builder helper class. */ + public interface Builder1 { + /** + * Set the code of this {@link Error} instance. + * + * @param code The code of this {@link Error} + * @return The Error builder. + */ + Builder2 code(@Nonnull final Integer code); + } + + /** Builder helper class. */ + public interface Builder2 { + /** + * Set the message of this {@link Error} instance. + * + * @param message The message of this {@link Error} + * @return The Error builder. + */ + Builder3 message(@Nonnull final String message); + } + + /** Builder helper class. */ + public interface Builder3 { + /** + * Set the location of this {@link Error} instance. + * + * @param location Where the error occurred + * @return The Error instance. + */ + Error location(@Nonnull final String location); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorResponse.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorResponse.java index 76fc798e1..45612f31a 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorResponse.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorResponse.java @@ -28,20 +28,8 @@ public class ErrorResponse // CHECKSTYLE:ON { - @JsonProperty("request_id") - private String requestId; - - @JsonProperty("code") - private Integer code; - - @JsonProperty("message") - private String message; - - @JsonProperty("location") - private String location; - - @JsonProperty("module_results") - private ModuleResults moduleResults; + @JsonProperty("error") + private Error error; @JsonAnySetter @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); @@ -50,158 +38,34 @@ public class ErrorResponse protected ErrorResponse() {} /** - * Set the requestId of this {@link ErrorResponse} instance and return the same instance. - * - * @param requestId The requestId of this {@link ErrorResponse} - * @return The same instance of this {@link ErrorResponse} class - */ - @Nonnull - public ErrorResponse requestId(@Nonnull final String requestId) { - this.requestId = requestId; - return this; - } - - /** - * Get requestId - * - * @return requestId The requestId of this {@link ErrorResponse} instance. - */ - @Nonnull - public String getRequestId() { - return requestId; - } - - /** - * Set the requestId of this {@link ErrorResponse} instance. - * - * @param requestId The requestId of this {@link ErrorResponse} - */ - public void setRequestId(@Nonnull final String requestId) { - this.requestId = requestId; - } - - /** - * Set the code of this {@link ErrorResponse} instance and return the same instance. - * - * @param code The code of this {@link ErrorResponse} - * @return The same instance of this {@link ErrorResponse} class - */ - @Nonnull - public ErrorResponse code(@Nonnull final Integer code) { - this.code = code; - return this; - } - - /** - * Get code - * - * @return code The code of this {@link ErrorResponse} instance. - */ - @Nonnull - public Integer getCode() { - return code; - } - - /** - * Set the code of this {@link ErrorResponse} instance. - * - * @param code The code of this {@link ErrorResponse} - */ - public void setCode(@Nonnull final Integer code) { - this.code = code; - } - - /** - * Set the message of this {@link ErrorResponse} instance and return the same instance. - * - * @param message The message of this {@link ErrorResponse} - * @return The same instance of this {@link ErrorResponse} class - */ - @Nonnull - public ErrorResponse message(@Nonnull final String message) { - this.message = message; - return this; - } - - /** - * Get message - * - * @return message The message of this {@link ErrorResponse} instance. - */ - @Nonnull - public String getMessage() { - return message; - } - - /** - * Set the message of this {@link ErrorResponse} instance. + * Set the error of this {@link ErrorResponse} instance and return the same instance. * - * @param message The message of this {@link ErrorResponse} - */ - public void setMessage(@Nonnull final String message) { - this.message = message; - } - - /** - * Set the location of this {@link ErrorResponse} instance and return the same instance. - * - * @param location Where the error occurred + * @param error The error of this {@link ErrorResponse} * @return The same instance of this {@link ErrorResponse} class */ @Nonnull - public ErrorResponse location(@Nonnull final String location) { - this.location = location; + public ErrorResponse error(@Nonnull final Error error) { + this.error = error; return this; } /** - * Where the error occurred + * Get error * - * @return location The location of this {@link ErrorResponse} instance. + * @return error The error of this {@link ErrorResponse} instance. */ @Nonnull - public String getLocation() { - return location; + public Error getError() { + return error; } /** - * Set the location of this {@link ErrorResponse} instance. + * Set the error of this {@link ErrorResponse} instance. * - * @param location Where the error occurred + * @param error The error of this {@link ErrorResponse} */ - public void setLocation(@Nonnull final String location) { - this.location = location; - } - - /** - * Set the moduleResults of this {@link ErrorResponse} instance and return the same instance. - * - * @param moduleResults The moduleResults of this {@link ErrorResponse} - * @return The same instance of this {@link ErrorResponse} class - */ - @Nonnull - public ErrorResponse moduleResults(@Nullable final ModuleResults moduleResults) { - this.moduleResults = moduleResults; - return this; - } - - /** - * Get moduleResults - * - * @return moduleResults The moduleResults of this {@link ErrorResponse} instance. - */ - @Nonnull - public ModuleResults getModuleResults() { - return moduleResults; - } - - /** - * Set the moduleResults of this {@link ErrorResponse} instance. - * - * @param moduleResults The moduleResults of this {@link ErrorResponse} - */ - public void setModuleResults(@Nullable final ModuleResults moduleResults) { - this.moduleResults = moduleResults; + public void setError(@Nonnull final Error error) { + this.error = error; } /** @@ -242,11 +106,7 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc @Nonnull public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); - if (requestId != null) declaredFields.put("requestId", requestId); - if (code != null) declaredFields.put("code", code); - if (message != null) declaredFields.put("message", message); - if (location != null) declaredFields.put("location", location); - if (moduleResults != null) declaredFields.put("moduleResults", moduleResults); + if (error != null) declaredFields.put("error", error); return declaredFields; } @@ -272,16 +132,12 @@ public boolean equals(@Nullable final java.lang.Object o) { } final ErrorResponse errorResponse = (ErrorResponse) o; return Objects.equals(this.cloudSdkCustomFields, errorResponse.cloudSdkCustomFields) - && Objects.equals(this.requestId, errorResponse.requestId) - && Objects.equals(this.code, errorResponse.code) - && Objects.equals(this.message, errorResponse.message) - && Objects.equals(this.location, errorResponse.location) - && Objects.equals(this.moduleResults, errorResponse.moduleResults); + && Objects.equals(this.error, errorResponse.error); } @Override public int hashCode() { - return Objects.hash(requestId, code, message, location, moduleResults, cloudSdkCustomFields); + return Objects.hash(error, cloudSdkCustomFields); } @Override @@ -289,11 +145,7 @@ public int hashCode() { public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class ErrorResponse {\n"); - sb.append(" requestId: ").append(toIndentedString(requestId)).append("\n"); - sb.append(" code: ").append(toIndentedString(code)).append("\n"); - sb.append(" message: ").append(toIndentedString(message)).append("\n"); - sb.append(" location: ").append(toIndentedString(location)).append("\n"); - sb.append(" moduleResults: ").append(toIndentedString(moduleResults)).append("\n"); + sb.append(" error: ").append(toIndentedString(error)).append("\n"); cloudSdkCustomFields.forEach( (k, v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); @@ -316,58 +168,17 @@ private String toIndentedString(final java.lang.Object o) { * with all required arguments. */ public static Builder create() { - return (requestId) -> - (code) -> - (message) -> - (location) -> - new ErrorResponse() - .requestId(requestId) - .code(code) - .message(message) - .location(location); + return (error) -> new ErrorResponse().error(error); } /** Builder helper class. */ public interface Builder { /** - * Set the requestId of this {@link ErrorResponse} instance. - * - * @param requestId The requestId of this {@link ErrorResponse} - * @return The ErrorResponse builder. - */ - Builder1 requestId(@Nonnull final String requestId); - } - - /** Builder helper class. */ - public interface Builder1 { - /** - * Set the code of this {@link ErrorResponse} instance. - * - * @param code The code of this {@link ErrorResponse} - * @return The ErrorResponse builder. - */ - Builder2 code(@Nonnull final Integer code); - } - - /** Builder helper class. */ - public interface Builder2 { - /** - * Set the message of this {@link ErrorResponse} instance. - * - * @param message The message of this {@link ErrorResponse} - * @return The ErrorResponse builder. - */ - Builder3 message(@Nonnull final String message); - } - - /** Builder helper class. */ - public interface Builder3 { - /** - * Set the location of this {@link ErrorResponse} instance. + * Set the error of this {@link ErrorResponse} instance. * - * @param location Where the error occurred + * @param error The error of this {@link ErrorResponse} * @return The ErrorResponse instance. */ - ErrorResponse location(@Nonnull final String location); + ErrorResponse error(@Nonnull final Error error); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorResponseStreaming.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorResponseStreaming.java index 496390e32..1b2b947e8 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorResponseStreaming.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorResponseStreaming.java @@ -28,20 +28,8 @@ public class ErrorResponseStreaming // CHECKSTYLE:ON { - @JsonProperty("request_id") - private String requestId; - - @JsonProperty("code") - private Integer code; - - @JsonProperty("message") - private String message; - - @JsonProperty("location") - private String location; - - @JsonProperty("module_results") - private ModuleResultsStreaming moduleResults; + @JsonProperty("error") + private ErrorStreaming error; @JsonAnySetter @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); @@ -50,160 +38,34 @@ public class ErrorResponseStreaming protected ErrorResponseStreaming() {} /** - * Set the requestId of this {@link ErrorResponseStreaming} instance and return the same instance. - * - * @param requestId The requestId of this {@link ErrorResponseStreaming} - * @return The same instance of this {@link ErrorResponseStreaming} class - */ - @Nonnull - public ErrorResponseStreaming requestId(@Nonnull final String requestId) { - this.requestId = requestId; - return this; - } - - /** - * Get requestId - * - * @return requestId The requestId of this {@link ErrorResponseStreaming} instance. - */ - @Nonnull - public String getRequestId() { - return requestId; - } - - /** - * Set the requestId of this {@link ErrorResponseStreaming} instance. - * - * @param requestId The requestId of this {@link ErrorResponseStreaming} - */ - public void setRequestId(@Nonnull final String requestId) { - this.requestId = requestId; - } - - /** - * Set the code of this {@link ErrorResponseStreaming} instance and return the same instance. - * - * @param code The code of this {@link ErrorResponseStreaming} - * @return The same instance of this {@link ErrorResponseStreaming} class - */ - @Nonnull - public ErrorResponseStreaming code(@Nonnull final Integer code) { - this.code = code; - return this; - } - - /** - * Get code - * - * @return code The code of this {@link ErrorResponseStreaming} instance. - */ - @Nonnull - public Integer getCode() { - return code; - } - - /** - * Set the code of this {@link ErrorResponseStreaming} instance. - * - * @param code The code of this {@link ErrorResponseStreaming} - */ - public void setCode(@Nonnull final Integer code) { - this.code = code; - } - - /** - * Set the message of this {@link ErrorResponseStreaming} instance and return the same instance. - * - * @param message The message of this {@link ErrorResponseStreaming} - * @return The same instance of this {@link ErrorResponseStreaming} class - */ - @Nonnull - public ErrorResponseStreaming message(@Nonnull final String message) { - this.message = message; - return this; - } - - /** - * Get message - * - * @return message The message of this {@link ErrorResponseStreaming} instance. - */ - @Nonnull - public String getMessage() { - return message; - } - - /** - * Set the message of this {@link ErrorResponseStreaming} instance. + * Set the error of this {@link ErrorResponseStreaming} instance and return the same instance. * - * @param message The message of this {@link ErrorResponseStreaming} - */ - public void setMessage(@Nonnull final String message) { - this.message = message; - } - - /** - * Set the location of this {@link ErrorResponseStreaming} instance and return the same instance. - * - * @param location Where the error occurred + * @param error The error of this {@link ErrorResponseStreaming} * @return The same instance of this {@link ErrorResponseStreaming} class */ @Nonnull - public ErrorResponseStreaming location(@Nonnull final String location) { - this.location = location; + public ErrorResponseStreaming error(@Nonnull final ErrorStreaming error) { + this.error = error; return this; } /** - * Where the error occurred + * Get error * - * @return location The location of this {@link ErrorResponseStreaming} instance. + * @return error The error of this {@link ErrorResponseStreaming} instance. */ @Nonnull - public String getLocation() { - return location; + public ErrorStreaming getError() { + return error; } /** - * Set the location of this {@link ErrorResponseStreaming} instance. + * Set the error of this {@link ErrorResponseStreaming} instance. * - * @param location Where the error occurred + * @param error The error of this {@link ErrorResponseStreaming} */ - public void setLocation(@Nonnull final String location) { - this.location = location; - } - - /** - * Set the moduleResults of this {@link ErrorResponseStreaming} instance and return the same - * instance. - * - * @param moduleResults The moduleResults of this {@link ErrorResponseStreaming} - * @return The same instance of this {@link ErrorResponseStreaming} class - */ - @Nonnull - public ErrorResponseStreaming moduleResults( - @Nullable final ModuleResultsStreaming moduleResults) { - this.moduleResults = moduleResults; - return this; - } - - /** - * Get moduleResults - * - * @return moduleResults The moduleResults of this {@link ErrorResponseStreaming} instance. - */ - @Nonnull - public ModuleResultsStreaming getModuleResults() { - return moduleResults; - } - - /** - * Set the moduleResults of this {@link ErrorResponseStreaming} instance. - * - * @param moduleResults The moduleResults of this {@link ErrorResponseStreaming} - */ - public void setModuleResults(@Nullable final ModuleResultsStreaming moduleResults) { - this.moduleResults = moduleResults; + public void setError(@Nonnull final ErrorStreaming error) { + this.error = error; } /** @@ -245,11 +107,7 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc @Nonnull public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); - if (requestId != null) declaredFields.put("requestId", requestId); - if (code != null) declaredFields.put("code", code); - if (message != null) declaredFields.put("message", message); - if (location != null) declaredFields.put("location", location); - if (moduleResults != null) declaredFields.put("moduleResults", moduleResults); + if (error != null) declaredFields.put("error", error); return declaredFields; } @@ -275,16 +133,12 @@ public boolean equals(@Nullable final java.lang.Object o) { } final ErrorResponseStreaming errorResponseStreaming = (ErrorResponseStreaming) o; return Objects.equals(this.cloudSdkCustomFields, errorResponseStreaming.cloudSdkCustomFields) - && Objects.equals(this.requestId, errorResponseStreaming.requestId) - && Objects.equals(this.code, errorResponseStreaming.code) - && Objects.equals(this.message, errorResponseStreaming.message) - && Objects.equals(this.location, errorResponseStreaming.location) - && Objects.equals(this.moduleResults, errorResponseStreaming.moduleResults); + && Objects.equals(this.error, errorResponseStreaming.error); } @Override public int hashCode() { - return Objects.hash(requestId, code, message, location, moduleResults, cloudSdkCustomFields); + return Objects.hash(error, cloudSdkCustomFields); } @Override @@ -292,11 +146,7 @@ public int hashCode() { public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class ErrorResponseStreaming {\n"); - sb.append(" requestId: ").append(toIndentedString(requestId)).append("\n"); - sb.append(" code: ").append(toIndentedString(code)).append("\n"); - sb.append(" message: ").append(toIndentedString(message)).append("\n"); - sb.append(" location: ").append(toIndentedString(location)).append("\n"); - sb.append(" moduleResults: ").append(toIndentedString(moduleResults)).append("\n"); + sb.append(" error: ").append(toIndentedString(error)).append("\n"); cloudSdkCustomFields.forEach( (k, v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); @@ -319,58 +169,17 @@ private String toIndentedString(final java.lang.Object o) { * instance with all required arguments. */ public static Builder create() { - return (requestId) -> - (code) -> - (message) -> - (location) -> - new ErrorResponseStreaming() - .requestId(requestId) - .code(code) - .message(message) - .location(location); + return (error) -> new ErrorResponseStreaming().error(error); } /** Builder helper class. */ public interface Builder { /** - * Set the requestId of this {@link ErrorResponseStreaming} instance. - * - * @param requestId The requestId of this {@link ErrorResponseStreaming} - * @return The ErrorResponseStreaming builder. - */ - Builder1 requestId(@Nonnull final String requestId); - } - - /** Builder helper class. */ - public interface Builder1 { - /** - * Set the code of this {@link ErrorResponseStreaming} instance. - * - * @param code The code of this {@link ErrorResponseStreaming} - * @return The ErrorResponseStreaming builder. - */ - Builder2 code(@Nonnull final Integer code); - } - - /** Builder helper class. */ - public interface Builder2 { - /** - * Set the message of this {@link ErrorResponseStreaming} instance. - * - * @param message The message of this {@link ErrorResponseStreaming} - * @return The ErrorResponseStreaming builder. - */ - Builder3 message(@Nonnull final String message); - } - - /** Builder helper class. */ - public interface Builder3 { - /** - * Set the location of this {@link ErrorResponseStreaming} instance. + * Set the error of this {@link ErrorResponseStreaming} instance. * - * @param location Where the error occurred + * @param error The error of this {@link ErrorResponseStreaming} * @return The ErrorResponseStreaming instance. */ - ErrorResponseStreaming location(@Nonnull final String location); + ErrorResponseStreaming error(@Nonnull final ErrorStreaming error); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorStreaming.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorStreaming.java new file mode 100644 index 000000000..db99b3f58 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ErrorStreaming.java @@ -0,0 +1,378 @@ +/* + * Internal Orchestration Service API + * 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. + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.orchestration.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** ErrorStreaming */ +// CHECKSTYLE:OFF +public class ErrorStreaming +// CHECKSTYLE:ON +{ + @JsonProperty("request_id") + private String requestId; + + @JsonProperty("code") + private Integer code; + + @JsonProperty("message") + private String message; + + @JsonProperty("location") + private String location; + + @JsonProperty("intermediate_results") + private ModuleResultsStreaming intermediateResults; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for ErrorStreaming. */ + protected ErrorStreaming() {} + + /** + * Set the requestId of this {@link ErrorStreaming} instance and return the same instance. + * + * @param requestId The requestId of this {@link ErrorStreaming} + * @return The same instance of this {@link ErrorStreaming} class + */ + @Nonnull + public ErrorStreaming requestId(@Nonnull final String requestId) { + this.requestId = requestId; + return this; + } + + /** + * Get requestId + * + * @return requestId The requestId of this {@link ErrorStreaming} instance. + */ + @Nonnull + public String getRequestId() { + return requestId; + } + + /** + * Set the requestId of this {@link ErrorStreaming} instance. + * + * @param requestId The requestId of this {@link ErrorStreaming} + */ + public void setRequestId(@Nonnull final String requestId) { + this.requestId = requestId; + } + + /** + * Set the code of this {@link ErrorStreaming} instance and return the same instance. + * + * @param code The code of this {@link ErrorStreaming} + * @return The same instance of this {@link ErrorStreaming} class + */ + @Nonnull + public ErrorStreaming code(@Nonnull final Integer code) { + this.code = code; + return this; + } + + /** + * Get code + * + * @return code The code of this {@link ErrorStreaming} instance. + */ + @Nonnull + public Integer getCode() { + return code; + } + + /** + * Set the code of this {@link ErrorStreaming} instance. + * + * @param code The code of this {@link ErrorStreaming} + */ + public void setCode(@Nonnull final Integer code) { + this.code = code; + } + + /** + * Set the message of this {@link ErrorStreaming} instance and return the same instance. + * + * @param message The message of this {@link ErrorStreaming} + * @return The same instance of this {@link ErrorStreaming} class + */ + @Nonnull + public ErrorStreaming message(@Nonnull final String message) { + this.message = message; + return this; + } + + /** + * Get message + * + * @return message The message of this {@link ErrorStreaming} instance. + */ + @Nonnull + public String getMessage() { + return message; + } + + /** + * Set the message of this {@link ErrorStreaming} instance. + * + * @param message The message of this {@link ErrorStreaming} + */ + public void setMessage(@Nonnull final String message) { + this.message = message; + } + + /** + * Set the location of this {@link ErrorStreaming} instance and return the same instance. + * + * @param location Where the error occurred + * @return The same instance of this {@link ErrorStreaming} class + */ + @Nonnull + public ErrorStreaming location(@Nonnull final String location) { + this.location = location; + return this; + } + + /** + * Where the error occurred + * + * @return location The location of this {@link ErrorStreaming} instance. + */ + @Nonnull + public String getLocation() { + return location; + } + + /** + * Set the location of this {@link ErrorStreaming} instance. + * + * @param location Where the error occurred + */ + public void setLocation(@Nonnull final String location) { + this.location = location; + } + + /** + * Set the intermediateResults of this {@link ErrorStreaming} instance and return the same + * instance. + * + * @param intermediateResults The intermediateResults of this {@link ErrorStreaming} + * @return The same instance of this {@link ErrorStreaming} class + */ + @Nonnull + public ErrorStreaming intermediateResults( + @Nullable final ModuleResultsStreaming intermediateResults) { + this.intermediateResults = intermediateResults; + return this; + } + + /** + * Get intermediateResults + * + * @return intermediateResults The intermediateResults of this {@link ErrorStreaming} instance. + */ + @Nonnull + public ModuleResultsStreaming getIntermediateResults() { + return intermediateResults; + } + + /** + * Set the intermediateResults of this {@link ErrorStreaming} instance. + * + * @param intermediateResults The intermediateResults of this {@link ErrorStreaming} + */ + public void setIntermediateResults(@Nullable final ModuleResultsStreaming intermediateResults) { + this.intermediateResults = intermediateResults; + } + + /** + * Get the names of the unrecognizable properties of the {@link ErrorStreaming}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link ErrorStreaming} instance. + * + * @deprecated Use {@link #toMap()} instead. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + @Deprecated + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("ErrorStreaming has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link ErrorStreaming} instance including unrecognized + * properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (requestId != null) declaredFields.put("requestId", requestId); + if (code != null) declaredFields.put("code", code); + if (message != null) declaredFields.put("message", message); + if (location != null) declaredFields.put("location", location); + if (intermediateResults != null) declaredFields.put("intermediateResults", intermediateResults); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link ErrorStreaming} instance. If the map previously + * contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ErrorStreaming errorStreaming = (ErrorStreaming) o; + return Objects.equals(this.cloudSdkCustomFields, errorStreaming.cloudSdkCustomFields) + && Objects.equals(this.requestId, errorStreaming.requestId) + && Objects.equals(this.code, errorStreaming.code) + && Objects.equals(this.message, errorStreaming.message) + && Objects.equals(this.location, errorStreaming.location) + && Objects.equals(this.intermediateResults, errorStreaming.intermediateResults); + } + + @Override + public int hashCode() { + return Objects.hash( + requestId, code, message, location, intermediateResults, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ErrorStreaming {\n"); + sb.append(" requestId: ").append(toIndentedString(requestId)).append("\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append(" location: ").append(toIndentedString(location)).append("\n"); + sb.append(" intermediateResults: ") + .append(toIndentedString(intermediateResults)) + .append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link ErrorStreaming} + * instance with all required arguments. + */ + public static Builder create() { + return (requestId) -> + (code) -> + (message) -> + (location) -> + new ErrorStreaming() + .requestId(requestId) + .code(code) + .message(message) + .location(location); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the requestId of this {@link ErrorStreaming} instance. + * + * @param requestId The requestId of this {@link ErrorStreaming} + * @return The ErrorStreaming builder. + */ + Builder1 requestId(@Nonnull final String requestId); + } + + /** Builder helper class. */ + public interface Builder1 { + /** + * Set the code of this {@link ErrorStreaming} instance. + * + * @param code The code of this {@link ErrorStreaming} + * @return The ErrorStreaming builder. + */ + Builder2 code(@Nonnull final Integer code); + } + + /** Builder helper class. */ + public interface Builder2 { + /** + * Set the message of this {@link ErrorStreaming} instance. + * + * @param message The message of this {@link ErrorStreaming} + * @return The ErrorStreaming builder. + */ + Builder3 message(@Nonnull final String message); + } + + /** Builder helper class. */ + public interface Builder3 { + /** + * Set the location of this {@link ErrorStreaming} instance. + * + * @param location Where the error occurred + * @return The ErrorStreaming instance. + */ + ErrorStreaming location(@Nonnull final String location); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GlobalStreamOptions.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GlobalStreamOptions.java index 84768b995..12b89da94 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GlobalStreamOptions.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GlobalStreamOptions.java @@ -25,11 +25,14 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -/** Options for streaming. Will be ignored if stream is false. */ +/** Options for streaming. Will be ignored if enabled is false. */ // CHECKSTYLE:OFF public class GlobalStreamOptions // CHECKSTYLE:ON { + @JsonProperty("enabled") + private Boolean enabled = false; + @JsonProperty("chunk_size") private Integer chunkSize = 100; @@ -42,6 +45,37 @@ public class GlobalStreamOptions /** Default constructor for GlobalStreamOptions. */ protected GlobalStreamOptions() {} + /** + * Set the enabled of this {@link GlobalStreamOptions} instance and return the same instance. + * + * @param enabled If true, the response will be streamed back to the client + * @return The same instance of this {@link GlobalStreamOptions} class + */ + @Nonnull + public GlobalStreamOptions enabled(@Nullable final Boolean enabled) { + this.enabled = enabled; + return this; + } + + /** + * If true, the response will be streamed back to the client + * + * @return enabled The enabled of this {@link GlobalStreamOptions} instance. + */ + @Nonnull + public Boolean isEnabled() { + return enabled; + } + + /** + * Set the enabled of this {@link GlobalStreamOptions} instance. + * + * @param enabled If true, the response will be streamed back to the client + */ + public void setEnabled(@Nullable final Boolean enabled) { + this.enabled = enabled; + } + /** * Set the chunkSize of this {@link GlobalStreamOptions} instance and return the same instance. * @@ -167,6 +201,7 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc @Nonnull public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (enabled != null) declaredFields.put("enabled", enabled); if (chunkSize != null) declaredFields.put("chunkSize", chunkSize); if (delimiters != null) declaredFields.put("delimiters", delimiters); return declaredFields; @@ -194,13 +229,14 @@ public boolean equals(@Nullable final java.lang.Object o) { } final GlobalStreamOptions globalStreamOptions = (GlobalStreamOptions) o; return Objects.equals(this.cloudSdkCustomFields, globalStreamOptions.cloudSdkCustomFields) + && Objects.equals(this.enabled, globalStreamOptions.enabled) && Objects.equals(this.chunkSize, globalStreamOptions.chunkSize) && Objects.equals(this.delimiters, globalStreamOptions.delimiters); } @Override public int hashCode() { - return Objects.hash(chunkSize, delimiters, cloudSdkCustomFields); + return Objects.hash(enabled, chunkSize, delimiters, cloudSdkCustomFields); } @Override @@ -208,6 +244,7 @@ public int hashCode() { public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class GlobalStreamOptions {\n"); + sb.append(" enabled: ").append(toIndentedString(enabled)).append("\n"); sb.append(" chunkSize: ").append(toIndentedString(chunkSize)).append("\n"); sb.append(" delimiters: ").append(toIndentedString(delimiters)).append("\n"); cloudSdkCustomFields.forEach( diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GroundingModuleConfigConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GroundingModuleConfigConfig.java index d17add2c8..11ee24b43 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GroundingModuleConfigConfig.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GroundingModuleConfigConfig.java @@ -16,7 +16,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; -import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -34,11 +33,8 @@ public class GroundingModuleConfigConfig @JsonProperty("filters") private List filters = new ArrayList<>(); - @JsonProperty("input_params") - private List inputParams = new ArrayList<>(); - - @JsonProperty("output_param") - private String outputParam; + @JsonProperty("placeholders") + private GroundingModuleConfigConfigPlaceholders placeholders; @JsonProperty("metadata_params") private List metadataParams = new ArrayList<>(); @@ -99,82 +95,36 @@ public void setFilters(@Nullable final List inputParams) { - this.inputParams = inputParams; + public GroundingModuleConfigConfig placeholders( + @Nonnull final GroundingModuleConfigConfigPlaceholders placeholders) { + this.placeholders = placeholders; return this; } /** - * Add one inputParams instance to this {@link GroundingModuleConfigConfig}. + * Get placeholders * - * @param inputParamsItem The inputParams that should be added - * @return The same instance of type {@link GroundingModuleConfigConfig} + * @return placeholders The placeholders of this {@link GroundingModuleConfigConfig} instance. */ @Nonnull - public GroundingModuleConfigConfig addInputParamsItem(@Nonnull final String inputParamsItem) { - if (this.inputParams == null) { - this.inputParams = new ArrayList<>(); - } - this.inputParams.add(inputParamsItem); - return this; + public GroundingModuleConfigConfigPlaceholders getPlaceholders() { + return placeholders; } /** - * Contains the input parameters used for grounding input questions + * Set the placeholders of this {@link GroundingModuleConfigConfig} instance. * - * @return inputParams The inputParams of this {@link GroundingModuleConfigConfig} instance. + * @param placeholders The placeholders of this {@link GroundingModuleConfigConfig} */ - @Nonnull - public List getInputParams() { - return inputParams; - } - - /** - * Set the inputParams of this {@link GroundingModuleConfigConfig} instance. - * - * @param inputParams Contains the input parameters used for grounding input questions - */ - public void setInputParams(@Nonnull final List inputParams) { - this.inputParams = inputParams; - } - - /** - * Set the outputParam of this {@link GroundingModuleConfigConfig} instance and return the same - * instance. - * - * @param outputParam Parameter name used for grounding output - * @return The same instance of this {@link GroundingModuleConfigConfig} class - */ - @Nonnull - public GroundingModuleConfigConfig outputParam(@Nonnull final String outputParam) { - this.outputParam = outputParam; - return this; - } - - /** - * Parameter name used for grounding output - * - * @return outputParam The outputParam of this {@link GroundingModuleConfigConfig} instance. - */ - @Nonnull - public String getOutputParam() { - return outputParam; - } - - /** - * Set the outputParam of this {@link GroundingModuleConfigConfig} instance. - * - * @param outputParam Parameter name used for grounding output - */ - public void setOutputParam(@Nonnull final String outputParam) { - this.outputParam = outputParam; + public void setPlaceholders(@Nonnull final GroundingModuleConfigConfigPlaceholders placeholders) { + this.placeholders = placeholders; } /** @@ -266,8 +216,7 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); if (filters != null) declaredFields.put("filters", filters); - if (inputParams != null) declaredFields.put("inputParams", inputParams); - if (outputParam != null) declaredFields.put("outputParam", outputParam); + if (placeholders != null) declaredFields.put("placeholders", placeholders); if (metadataParams != null) declaredFields.put("metadataParams", metadataParams); return declaredFields; } @@ -296,14 +245,13 @@ public boolean equals(@Nullable final java.lang.Object o) { return Objects.equals( this.cloudSdkCustomFields, groundingModuleConfigConfig.cloudSdkCustomFields) && Objects.equals(this.filters, groundingModuleConfigConfig.filters) - && Objects.equals(this.inputParams, groundingModuleConfigConfig.inputParams) - && Objects.equals(this.outputParam, groundingModuleConfigConfig.outputParam) + && Objects.equals(this.placeholders, groundingModuleConfigConfig.placeholders) && Objects.equals(this.metadataParams, groundingModuleConfigConfig.metadataParams); } @Override public int hashCode() { - return Objects.hash(filters, inputParams, outputParam, metadataParams, cloudSdkCustomFields); + return Objects.hash(filters, placeholders, metadataParams, cloudSdkCustomFields); } @Override @@ -312,8 +260,7 @@ public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class GroundingModuleConfigConfig {\n"); sb.append(" filters: ").append(toIndentedString(filters)).append("\n"); - sb.append(" inputParams: ").append(toIndentedString(inputParams)).append("\n"); - sb.append(" outputParam: ").append(toIndentedString(outputParam)).append("\n"); + sb.append(" placeholders: ").append(toIndentedString(placeholders)).append("\n"); sb.append(" metadataParams: ").append(toIndentedString(metadataParams)).append("\n"); cloudSdkCustomFields.forEach( (k, v) -> @@ -337,40 +284,18 @@ private String toIndentedString(final java.lang.Object o) { * GroundingModuleConfigConfig} instance with all required arguments. */ public static Builder create() { - return (inputParams) -> - (outputParam) -> - new GroundingModuleConfigConfig().inputParams(inputParams).outputParam(outputParam); + return (placeholders) -> new GroundingModuleConfigConfig().placeholders(placeholders); } /** Builder helper class. */ public interface Builder { /** - * Set the inputParams of this {@link GroundingModuleConfigConfig} instance. - * - * @param inputParams Contains the input parameters used for grounding input questions - * @return The GroundingModuleConfigConfig builder. - */ - Builder1 inputParams(@Nonnull final List inputParams); - - /** - * Set the inputParams of this {@link GroundingModuleConfigConfig} instance. - * - * @param inputParams Contains the input parameters used for grounding input questions - * @return The GroundingModuleConfigConfig builder. - */ - default Builder1 inputParams(@Nonnull final String... inputParams) { - return inputParams(Arrays.asList(inputParams)); - } - } - - /** Builder helper class. */ - public interface Builder1 { - /** - * Set the outputParam of this {@link GroundingModuleConfigConfig} instance. + * Set the placeholders of this {@link GroundingModuleConfigConfig} instance. * - * @param outputParam Parameter name used for grounding output + * @param placeholders The placeholders of this {@link GroundingModuleConfigConfig} * @return The GroundingModuleConfigConfig instance. */ - GroundingModuleConfigConfig outputParam(@Nonnull final String outputParam); + GroundingModuleConfigConfig placeholders( + @Nonnull final GroundingModuleConfigConfigPlaceholders placeholders); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GroundingModuleConfigConfigPlaceholders.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GroundingModuleConfigConfigPlaceholders.java new file mode 100644 index 000000000..9947284fe --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/GroundingModuleConfigConfigPlaceholders.java @@ -0,0 +1,269 @@ +/* + * Internal Orchestration Service API + * 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. + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.orchestration.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Placeholders to be used for grounding input questions and output */ +// CHECKSTYLE:OFF +public class GroundingModuleConfigConfigPlaceholders +// CHECKSTYLE:ON +{ + @JsonProperty("input") + private List input = new ArrayList<>(); + + @JsonProperty("output") + private String output; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for GroundingModuleConfigConfigPlaceholders. */ + protected GroundingModuleConfigConfigPlaceholders() {} + + /** + * Set the input of this {@link GroundingModuleConfigConfigPlaceholders} instance and return the + * same instance. + * + * @param input Contains the input parameters used for grounding input questions + * @return The same instance of this {@link GroundingModuleConfigConfigPlaceholders} class + */ + @Nonnull + public GroundingModuleConfigConfigPlaceholders input(@Nonnull final List input) { + this.input = input; + return this; + } + + /** + * Add one input instance to this {@link GroundingModuleConfigConfigPlaceholders}. + * + * @param inputItem The input that should be added + * @return The same instance of type {@link GroundingModuleConfigConfigPlaceholders} + */ + @Nonnull + public GroundingModuleConfigConfigPlaceholders addInputItem(@Nonnull final String inputItem) { + if (this.input == null) { + this.input = new ArrayList<>(); + } + this.input.add(inputItem); + return this; + } + + /** + * Contains the input parameters used for grounding input questions + * + * @return input The input of this {@link GroundingModuleConfigConfigPlaceholders} instance. + */ + @Nonnull + public List getInput() { + return input; + } + + /** + * Set the input of this {@link GroundingModuleConfigConfigPlaceholders} instance. + * + * @param input Contains the input parameters used for grounding input questions + */ + public void setInput(@Nonnull final List input) { + this.input = input; + } + + /** + * Set the output of this {@link GroundingModuleConfigConfigPlaceholders} instance and return the + * same instance. + * + * @param output Placeholder name for grounding output + * @return The same instance of this {@link GroundingModuleConfigConfigPlaceholders} class + */ + @Nonnull + public GroundingModuleConfigConfigPlaceholders output(@Nonnull final String output) { + this.output = output; + return this; + } + + /** + * Placeholder name for grounding output + * + * @return output The output of this {@link GroundingModuleConfigConfigPlaceholders} instance. + */ + @Nonnull + public String getOutput() { + return output; + } + + /** + * Set the output of this {@link GroundingModuleConfigConfigPlaceholders} instance. + * + * @param output Placeholder name for grounding output + */ + public void setOutput(@Nonnull final String output) { + this.output = output; + } + + /** + * Get the names of the unrecognizable properties of the {@link + * GroundingModuleConfigConfigPlaceholders}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link + * GroundingModuleConfigConfigPlaceholders} instance. + * + * @deprecated Use {@link #toMap()} instead. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + @Deprecated + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "GroundingModuleConfigConfigPlaceholders has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link GroundingModuleConfigConfigPlaceholders} + * instance including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (input != null) declaredFields.put("input", input); + if (output != null) declaredFields.put("output", output); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link GroundingModuleConfigConfigPlaceholders} + * instance. If the map previously contained a mapping for the key, the old value is replaced by + * the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final GroundingModuleConfigConfigPlaceholders groundingModuleConfigConfigPlaceholders = + (GroundingModuleConfigConfigPlaceholders) o; + return Objects.equals( + this.cloudSdkCustomFields, groundingModuleConfigConfigPlaceholders.cloudSdkCustomFields) + && Objects.equals(this.input, groundingModuleConfigConfigPlaceholders.input) + && Objects.equals(this.output, groundingModuleConfigConfigPlaceholders.output); + } + + @Override + public int hashCode() { + return Objects.hash(input, output, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class GroundingModuleConfigConfigPlaceholders {\n"); + sb.append(" input: ").append(toIndentedString(input)).append("\n"); + sb.append(" output: ").append(toIndentedString(output)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link + * GroundingModuleConfigConfigPlaceholders} instance with all required arguments. + */ + public static Builder create() { + return (input) -> + (output) -> new GroundingModuleConfigConfigPlaceholders().input(input).output(output); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the input of this {@link GroundingModuleConfigConfigPlaceholders} instance. + * + * @param input Contains the input parameters used for grounding input questions + * @return The GroundingModuleConfigConfigPlaceholders builder. + */ + Builder1 input(@Nonnull final List input); + + /** + * Set the input of this {@link GroundingModuleConfigConfigPlaceholders} instance. + * + * @param input Contains the input parameters used for grounding input questions + * @return The GroundingModuleConfigConfigPlaceholders builder. + */ + default Builder1 input(@Nonnull final String... input) { + return input(Arrays.asList(input)); + } + } + + /** Builder helper class. */ + public interface Builder1 { + /** + * Set the output of this {@link GroundingModuleConfigConfigPlaceholders} instance. + * + * @param output Placeholder name for grounding output + * @return The GroundingModuleConfigConfigPlaceholders instance. + */ + GroundingModuleConfigConfigPlaceholders output(@Nonnull final String output); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModelDetails.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModelDetails.java new file mode 100644 index 000000000..7a932eef0 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModelDetails.java @@ -0,0 +1,278 @@ +/* + * Internal Orchestration Service API + * 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. + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.orchestration.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** LLMModelDetails */ +// CHECKSTYLE:OFF +public class LLMModelDetails +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("version") + private String version = "latest"; + + @JsonProperty("params") + private Map params = new HashMap<>(); + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for LLMModelDetails. */ + protected LLMModelDetails() {} + + /** + * Set the name of this {@link LLMModelDetails} instance and return the same instance. + * + * @param name Name of the model as in LLM Access configuration + * @return The same instance of this {@link LLMModelDetails} class + */ + @Nonnull + public LLMModelDetails name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * Name of the model as in LLM Access configuration + * + * @return name The name of this {@link LLMModelDetails} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link LLMModelDetails} instance. + * + * @param name Name of the model as in LLM Access configuration + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the version of this {@link LLMModelDetails} instance and return the same instance. + * + * @param version Version of the model to be used + * @return The same instance of this {@link LLMModelDetails} class + */ + @Nonnull + public LLMModelDetails version(@Nullable final String version) { + this.version = version; + return this; + } + + /** + * Version of the model to be used + * + * @return version The version of this {@link LLMModelDetails} instance. + */ + @Nonnull + public String getVersion() { + return version; + } + + /** + * Set the version of this {@link LLMModelDetails} instance. + * + * @param version Version of the model to be used + */ + public void setVersion(@Nullable final String version) { + this.version = version; + } + + /** + * Set the params of this {@link LLMModelDetails} instance and return the same instance. + * + * @param params Additional parameters for the model. Default values are used for mandatory + * parameters. + * @return The same instance of this {@link LLMModelDetails} class + */ + @Nonnull + public LLMModelDetails params(@Nullable final Map params) { + this.params = params; + return this; + } + + /** + * Put one params instance to this {@link LLMModelDetails} instance. + * + * @param key The String key of this params instance + * @param paramsItem The params that should be added under the given key + * @return The same instance of type {@link LLMModelDetails} + */ + @Nonnull + public LLMModelDetails putparamsItem( + @Nonnull final String key, @Nullable final Object paramsItem) { + if (this.params == null) { + this.params = new HashMap<>(); + } + this.params.put(key, paramsItem); + return this; + } + + /** + * Additional parameters for the model. Default values are used for mandatory parameters. + * + * @return params The params of this {@link LLMModelDetails} instance. + */ + @Nonnull + public Map getParams() { + return params; + } + + /** + * Set the params of this {@link LLMModelDetails} instance. + * + * @param params Additional parameters for the model. Default values are used for mandatory + * parameters. + */ + public void setParams(@Nullable final Map params) { + this.params = params; + } + + /** + * Get the names of the unrecognizable properties of the {@link LLMModelDetails}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link LLMModelDetails} instance. + * + * @deprecated Use {@link #toMap()} instead. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + @Deprecated + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException("LLMModelDetails has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link LLMModelDetails} instance including unrecognized + * properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (name != null) declaredFields.put("name", name); + if (version != null) declaredFields.put("version", version); + if (params != null) declaredFields.put("params", params); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link LLMModelDetails} instance. If the map previously + * contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final LLMModelDetails llMModelDetails = (LLMModelDetails) o; + return Objects.equals(this.cloudSdkCustomFields, llMModelDetails.cloudSdkCustomFields) + && Objects.equals(this.name, llMModelDetails.name) + && Objects.equals(this.version, llMModelDetails.version) + && Objects.equals(this.params, llMModelDetails.params); + } + + @Override + public int hashCode() { + return Objects.hash(name, version, params, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class LLMModelDetails {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" version: ").append(toIndentedString(version)).append("\n"); + sb.append(" params: ").append(toIndentedString(params)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link LLMModelDetails} + * instance with all required arguments. + */ + public static Builder create() { + return (name) -> new LLMModelDetails().name(name); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the name of this {@link LLMModelDetails} instance. + * + * @param name Name of the model as in LLM Access configuration + * @return The LLMModelDetails instance. + */ + LLMModelDetails name(@Nonnull final String name); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModuleConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModuleConfig.java deleted file mode 100644 index 5a2cd63d6..000000000 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModuleConfig.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Internal Orchestration Service API - * 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. - * - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -package com.sap.ai.sdk.orchestration.model; - -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Objects; -import java.util.Set; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -/** LLMModuleConfig */ -// CHECKSTYLE:OFF -public class LLMModuleConfig -// CHECKSTYLE:ON -{ - @JsonProperty("model_name") - private String modelName; - - @JsonProperty("model_params") - private Map modelParams = new HashMap<>(); - - @JsonProperty("model_version") - private String modelVersion = "latest"; - - @JsonAnySetter @JsonAnyGetter - private final Map cloudSdkCustomFields = new LinkedHashMap<>(); - - /** Default constructor for LLMModuleConfig. */ - protected LLMModuleConfig() {} - - /** - * Set the modelName of this {@link LLMModuleConfig} instance and return the same instance. - * - * @param modelName Model name as in LLM Access configuration - * @return The same instance of this {@link LLMModuleConfig} class - */ - @Nonnull - public LLMModuleConfig modelName(@Nonnull final String modelName) { - this.modelName = modelName; - return this; - } - - /** - * Model name as in LLM Access configuration - * - * @return modelName The modelName of this {@link LLMModuleConfig} instance. - */ - @Nonnull - public String getModelName() { - return modelName; - } - - /** - * Set the modelName of this {@link LLMModuleConfig} instance. - * - * @param modelName Model name as in LLM Access configuration - */ - public void setModelName(@Nonnull final String modelName) { - this.modelName = modelName; - } - - /** - * Set the modelParams of this {@link LLMModuleConfig} instance and return the same instance. - * - * @param modelParams Model parameters - * @return The same instance of this {@link LLMModuleConfig} class - */ - @Nonnull - public LLMModuleConfig modelParams(@Nullable final Map modelParams) { - this.modelParams = modelParams; - return this; - } - - /** - * Put one modelParams instance to this {@link LLMModuleConfig} instance. - * - * @param key The String key of this modelParams instance - * @param modelParamsItem The modelParams that should be added under the given key - * @return The same instance of type {@link LLMModuleConfig} - */ - @Nonnull - public LLMModuleConfig putmodelParamsItem( - @Nonnull final String key, @Nullable final Object modelParamsItem) { - if (this.modelParams == null) { - this.modelParams = new HashMap<>(); - } - this.modelParams.put(key, modelParamsItem); - return this; - } - - /** - * Model parameters - * - * @return modelParams The modelParams of this {@link LLMModuleConfig} instance. - */ - @Nonnull - public Map getModelParams() { - return modelParams; - } - - /** - * Set the modelParams of this {@link LLMModuleConfig} instance. - * - * @param modelParams Model parameters - */ - public void setModelParams(@Nullable final Map modelParams) { - this.modelParams = modelParams; - } - - /** - * Set the modelVersion of this {@link LLMModuleConfig} instance and return the same instance. - * - * @param modelVersion Version of the model to use - * @return The same instance of this {@link LLMModuleConfig} class - */ - @Nonnull - public LLMModuleConfig modelVersion(@Nullable final String modelVersion) { - this.modelVersion = modelVersion; - return this; - } - - /** - * Version of the model to use - * - * @return modelVersion The modelVersion of this {@link LLMModuleConfig} instance. - */ - @Nonnull - public String getModelVersion() { - return modelVersion; - } - - /** - * Set the modelVersion of this {@link LLMModuleConfig} instance. - * - * @param modelVersion Version of the model to use - */ - public void setModelVersion(@Nullable final String modelVersion) { - this.modelVersion = modelVersion; - } - - /** - * Get the names of the unrecognizable properties of the {@link LLMModuleConfig}. - * - * @return The set of properties names - */ - @JsonIgnore - @Nonnull - public Set getCustomFieldNames() { - return cloudSdkCustomFields.keySet(); - } - - /** - * Get the value of an unrecognizable property of this {@link LLMModuleConfig} instance. - * - * @deprecated Use {@link #toMap()} instead. - * @param name The name of the property - * @return The value of the property - * @throws NoSuchElementException If no property with the given name could be found. - */ - @Nullable - @Deprecated - public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { - if (!cloudSdkCustomFields.containsKey(name)) { - throw new NoSuchElementException("LLMModuleConfig has no field with name '" + name + "'."); - } - return cloudSdkCustomFields.get(name); - } - - /** - * Get the value of all properties of this {@link LLMModuleConfig} instance including unrecognized - * properties. - * - * @return The map of all properties - */ - @JsonIgnore - @Nonnull - public Map toMap() { - final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); - if (modelName != null) declaredFields.put("modelName", modelName); - if (modelParams != null) declaredFields.put("modelParams", modelParams); - if (modelVersion != null) declaredFields.put("modelVersion", modelVersion); - return declaredFields; - } - - /** - * Set an unrecognizable property of this {@link LLMModuleConfig} instance. If the map previously - * contained a mapping for the key, the old value is replaced by the specified value. - * - * @param customFieldName The name of the property - * @param customFieldValue The value of the property - */ - @JsonIgnore - public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { - cloudSdkCustomFields.put(customFieldName, customFieldValue); - } - - @Override - public boolean equals(@Nullable final java.lang.Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final LLMModuleConfig llMModuleConfig = (LLMModuleConfig) o; - return Objects.equals(this.cloudSdkCustomFields, llMModuleConfig.cloudSdkCustomFields) - && Objects.equals(this.modelName, llMModuleConfig.modelName) - && Objects.equals(this.modelParams, llMModuleConfig.modelParams) - && Objects.equals(this.modelVersion, llMModuleConfig.modelVersion); - } - - @Override - public int hashCode() { - return Objects.hash(modelName, modelParams, modelVersion, cloudSdkCustomFields); - } - - @Override - @Nonnull - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("class LLMModuleConfig {\n"); - sb.append(" modelName: ").append(toIndentedString(modelName)).append("\n"); - sb.append(" modelParams: ").append(toIndentedString(modelParams)).append("\n"); - sb.append(" modelVersion: ").append(toIndentedString(modelVersion)).append("\n"); - cloudSdkCustomFields.forEach( - (k, v) -> - sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); - sb.append("}"); - return sb.toString(); - } - - /** - * Convert the given object to string with each line indented by 4 spaces (except the first line). - */ - private String toIndentedString(final java.lang.Object o) { - if (o == null) { - return "null"; - } - return o.toString().replace("\n", "\n "); - } - - /** - * Create a type-safe, fluent-api builder object to construct a new {@link LLMModuleConfig} - * instance with all required arguments. - */ - public static Builder create() { - return (modelName) -> new LLMModuleConfig().modelName(modelName); - } - - /** Builder helper class. */ - public interface Builder { - /** - * Set the modelName of this {@link LLMModuleConfig} instance. - * - * @param modelName Model name as in LLM Access configuration - * @return The LLMModuleConfig instance. - */ - LLMModuleConfig modelName(@Nonnull final String modelName); - } -} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModuleResult.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModuleResult.java index 10063bb70..957aae9ad 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModuleResult.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/LLMModuleResult.java @@ -26,7 +26,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -/** Output of LLM module. Follows the OpenAI spec. */ +/** Output from LLM. Follows the OpenAI spec. */ // CHECKSTYLE:OFF public class LLMModuleResult // CHECKSTYLE:ON diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ModuleConfigs.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ModuleConfigs.java index 743f70e9c..3ab43534c 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ModuleConfigs.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/ModuleConfigs.java @@ -28,26 +28,20 @@ public class ModuleConfigs // CHECKSTYLE:ON { - @JsonProperty("llm_module_config") - private LLMModuleConfig llmModuleConfig; + @JsonProperty("prompt_templating") + private PromptTemplatingModuleConfig promptTemplating; - @JsonProperty("templating_module_config") - private TemplatingModuleConfig templatingModuleConfig; + @JsonProperty("filtering") + private FilteringModuleConfig filtering; - @JsonProperty("filtering_module_config") - private FilteringModuleConfig filteringModuleConfig; + @JsonProperty("masking") + private MaskingModuleConfig masking; - @JsonProperty("masking_module_config") - private MaskingModuleConfig maskingModuleConfig; + @JsonProperty("grounding") + private GroundingModuleConfig grounding; - @JsonProperty("grounding_module_config") - private GroundingModuleConfig groundingModuleConfig; - - @JsonProperty("input_translation_module_config") - private SAPDocumentTranslation inputTranslationModuleConfig; - - @JsonProperty("output_translation_module_config") - private SAPDocumentTranslation outputTranslationModuleConfig; + @JsonProperty("translation") + private TranslationModuleConfig translation; @JsonAnySetter @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); @@ -56,244 +50,159 @@ public class ModuleConfigs protected ModuleConfigs() {} /** - * Set the llmModuleConfig of this {@link ModuleConfigs} instance and return the same instance. - * - * @param llmModuleConfig The llmModuleConfig of this {@link ModuleConfigs} - * @return The same instance of this {@link ModuleConfigs} class - */ - @Nonnull - public ModuleConfigs llmModuleConfig(@Nonnull final LLMModuleConfig llmModuleConfig) { - this.llmModuleConfig = llmModuleConfig; - return this; - } - - /** - * Get llmModuleConfig - * - * @return llmModuleConfig The llmModuleConfig of this {@link ModuleConfigs} instance. - */ - @Nonnull - public LLMModuleConfig getLlmModuleConfig() { - return llmModuleConfig; - } - - /** - * Set the llmModuleConfig of this {@link ModuleConfigs} instance. - * - * @param llmModuleConfig The llmModuleConfig of this {@link ModuleConfigs} - */ - public void setLlmModuleConfig(@Nonnull final LLMModuleConfig llmModuleConfig) { - this.llmModuleConfig = llmModuleConfig; - } - - /** - * Set the templatingModuleConfig of this {@link ModuleConfigs} instance and return the same - * instance. - * - * @param templatingModuleConfig The templatingModuleConfig of this {@link ModuleConfigs} - * @return The same instance of this {@link ModuleConfigs} class - */ - @Nonnull - public ModuleConfigs templatingModuleConfig( - @Nonnull final TemplatingModuleConfig templatingModuleConfig) { - this.templatingModuleConfig = templatingModuleConfig; - return this; - } - - /** - * Get templatingModuleConfig - * - * @return templatingModuleConfig The templatingModuleConfig of this {@link ModuleConfigs} - * instance. - */ - @Nonnull - public TemplatingModuleConfig getTemplatingModuleConfig() { - return templatingModuleConfig; - } - - /** - * Set the templatingModuleConfig of this {@link ModuleConfigs} instance. + * Set the promptTemplating of this {@link ModuleConfigs} instance and return the same instance. * - * @param templatingModuleConfig The templatingModuleConfig of this {@link ModuleConfigs} - */ - public void setTemplatingModuleConfig( - @Nonnull final TemplatingModuleConfig templatingModuleConfig) { - this.templatingModuleConfig = templatingModuleConfig; - } - - /** - * Set the filteringModuleConfig of this {@link ModuleConfigs} instance and return the same - * instance. - * - * @param filteringModuleConfig The filteringModuleConfig of this {@link ModuleConfigs} + * @param promptTemplating The promptTemplating of this {@link ModuleConfigs} * @return The same instance of this {@link ModuleConfigs} class */ @Nonnull - public ModuleConfigs filteringModuleConfig( - @Nullable final FilteringModuleConfig filteringModuleConfig) { - this.filteringModuleConfig = filteringModuleConfig; + public ModuleConfigs promptTemplating( + @Nonnull final PromptTemplatingModuleConfig promptTemplating) { + this.promptTemplating = promptTemplating; return this; } /** - * Get filteringModuleConfig + * Get promptTemplating * - * @return filteringModuleConfig The filteringModuleConfig of this {@link ModuleConfigs} instance. + * @return promptTemplating The promptTemplating of this {@link ModuleConfigs} instance. */ @Nonnull - public FilteringModuleConfig getFilteringModuleConfig() { - return filteringModuleConfig; + public PromptTemplatingModuleConfig getPromptTemplating() { + return promptTemplating; } /** - * Set the filteringModuleConfig of this {@link ModuleConfigs} instance. + * Set the promptTemplating of this {@link ModuleConfigs} instance. * - * @param filteringModuleConfig The filteringModuleConfig of this {@link ModuleConfigs} + * @param promptTemplating The promptTemplating of this {@link ModuleConfigs} */ - public void setFilteringModuleConfig( - @Nullable final FilteringModuleConfig filteringModuleConfig) { - this.filteringModuleConfig = filteringModuleConfig; + public void setPromptTemplating(@Nonnull final PromptTemplatingModuleConfig promptTemplating) { + this.promptTemplating = promptTemplating; } /** - * Set the maskingModuleConfig of this {@link ModuleConfigs} instance and return the same - * instance. + * Set the filtering of this {@link ModuleConfigs} instance and return the same instance. * - * @param maskingModuleConfig The maskingModuleConfig of this {@link ModuleConfigs} + * @param filtering The filtering of this {@link ModuleConfigs} * @return The same instance of this {@link ModuleConfigs} class */ @Nonnull - public ModuleConfigs maskingModuleConfig( - @Nullable final MaskingModuleConfig maskingModuleConfig) { - this.maskingModuleConfig = maskingModuleConfig; + public ModuleConfigs filtering(@Nullable final FilteringModuleConfig filtering) { + this.filtering = filtering; return this; } /** - * Get maskingModuleConfig + * Get filtering * - * @return maskingModuleConfig The maskingModuleConfig of this {@link ModuleConfigs} instance. + * @return filtering The filtering of this {@link ModuleConfigs} instance. */ @Nonnull - public MaskingModuleConfig getMaskingModuleConfig() { - return maskingModuleConfig; + public FilteringModuleConfig getFiltering() { + return filtering; } /** - * Set the maskingModuleConfig of this {@link ModuleConfigs} instance. + * Set the filtering of this {@link ModuleConfigs} instance. * - * @param maskingModuleConfig The maskingModuleConfig of this {@link ModuleConfigs} + * @param filtering The filtering of this {@link ModuleConfigs} */ - public void setMaskingModuleConfig(@Nullable final MaskingModuleConfig maskingModuleConfig) { - this.maskingModuleConfig = maskingModuleConfig; + public void setFiltering(@Nullable final FilteringModuleConfig filtering) { + this.filtering = filtering; } /** - * Set the groundingModuleConfig of this {@link ModuleConfigs} instance and return the same - * instance. + * Set the masking of this {@link ModuleConfigs} instance and return the same instance. * - * @param groundingModuleConfig The groundingModuleConfig of this {@link ModuleConfigs} + * @param masking The masking of this {@link ModuleConfigs} * @return The same instance of this {@link ModuleConfigs} class */ @Nonnull - public ModuleConfigs groundingModuleConfig( - @Nullable final GroundingModuleConfig groundingModuleConfig) { - this.groundingModuleConfig = groundingModuleConfig; + public ModuleConfigs masking(@Nullable final MaskingModuleConfig masking) { + this.masking = masking; return this; } /** - * Get groundingModuleConfig + * Get masking * - * @return groundingModuleConfig The groundingModuleConfig of this {@link ModuleConfigs} instance. + * @return masking The masking of this {@link ModuleConfigs} instance. */ @Nonnull - public GroundingModuleConfig getGroundingModuleConfig() { - return groundingModuleConfig; + public MaskingModuleConfig getMasking() { + return masking; } /** - * Set the groundingModuleConfig of this {@link ModuleConfigs} instance. + * Set the masking of this {@link ModuleConfigs} instance. * - * @param groundingModuleConfig The groundingModuleConfig of this {@link ModuleConfigs} + * @param masking The masking of this {@link ModuleConfigs} */ - public void setGroundingModuleConfig( - @Nullable final GroundingModuleConfig groundingModuleConfig) { - this.groundingModuleConfig = groundingModuleConfig; + public void setMasking(@Nullable final MaskingModuleConfig masking) { + this.masking = masking; } /** - * Set the inputTranslationModuleConfig of this {@link ModuleConfigs} instance and return the same - * instance. + * Set the grounding of this {@link ModuleConfigs} instance and return the same instance. * - * @param inputTranslationModuleConfig The inputTranslationModuleConfig of this {@link - * ModuleConfigs} + * @param grounding The grounding of this {@link ModuleConfigs} * @return The same instance of this {@link ModuleConfigs} class */ @Nonnull - public ModuleConfigs inputTranslationModuleConfig( - @Nullable final SAPDocumentTranslation inputTranslationModuleConfig) { - this.inputTranslationModuleConfig = inputTranslationModuleConfig; + public ModuleConfigs grounding(@Nullable final GroundingModuleConfig grounding) { + this.grounding = grounding; return this; } /** - * Get inputTranslationModuleConfig + * Get grounding * - * @return inputTranslationModuleConfig The inputTranslationModuleConfig of this {@link - * ModuleConfigs} instance. + * @return grounding The grounding of this {@link ModuleConfigs} instance. */ @Nonnull - public SAPDocumentTranslation getInputTranslationModuleConfig() { - return inputTranslationModuleConfig; + public GroundingModuleConfig getGrounding() { + return grounding; } /** - * Set the inputTranslationModuleConfig of this {@link ModuleConfigs} instance. + * Set the grounding of this {@link ModuleConfigs} instance. * - * @param inputTranslationModuleConfig The inputTranslationModuleConfig of this {@link - * ModuleConfigs} + * @param grounding The grounding of this {@link ModuleConfigs} */ - public void setInputTranslationModuleConfig( - @Nullable final SAPDocumentTranslation inputTranslationModuleConfig) { - this.inputTranslationModuleConfig = inputTranslationModuleConfig; + public void setGrounding(@Nullable final GroundingModuleConfig grounding) { + this.grounding = grounding; } /** - * Set the outputTranslationModuleConfig of this {@link ModuleConfigs} instance and return the - * same instance. + * Set the translation of this {@link ModuleConfigs} instance and return the same instance. * - * @param outputTranslationModuleConfig The outputTranslationModuleConfig of this {@link - * ModuleConfigs} + * @param translation The translation of this {@link ModuleConfigs} * @return The same instance of this {@link ModuleConfigs} class */ @Nonnull - public ModuleConfigs outputTranslationModuleConfig( - @Nullable final SAPDocumentTranslation outputTranslationModuleConfig) { - this.outputTranslationModuleConfig = outputTranslationModuleConfig; + public ModuleConfigs translation(@Nullable final TranslationModuleConfig translation) { + this.translation = translation; return this; } /** - * Get outputTranslationModuleConfig + * Get translation * - * @return outputTranslationModuleConfig The outputTranslationModuleConfig of this {@link - * ModuleConfigs} instance. + * @return translation The translation of this {@link ModuleConfigs} instance. */ @Nonnull - public SAPDocumentTranslation getOutputTranslationModuleConfig() { - return outputTranslationModuleConfig; + public TranslationModuleConfig getTranslation() { + return translation; } /** - * Set the outputTranslationModuleConfig of this {@link ModuleConfigs} instance. + * Set the translation of this {@link ModuleConfigs} instance. * - * @param outputTranslationModuleConfig The outputTranslationModuleConfig of this {@link - * ModuleConfigs} + * @param translation The translation of this {@link ModuleConfigs} */ - public void setOutputTranslationModuleConfig( - @Nullable final SAPDocumentTranslation outputTranslationModuleConfig) { - this.outputTranslationModuleConfig = outputTranslationModuleConfig; + public void setTranslation(@Nullable final TranslationModuleConfig translation) { + this.translation = translation; } /** @@ -334,18 +243,11 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc @Nonnull public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); - if (llmModuleConfig != null) declaredFields.put("llmModuleConfig", llmModuleConfig); - if (templatingModuleConfig != null) - declaredFields.put("templatingModuleConfig", templatingModuleConfig); - if (filteringModuleConfig != null) - declaredFields.put("filteringModuleConfig", filteringModuleConfig); - if (maskingModuleConfig != null) declaredFields.put("maskingModuleConfig", maskingModuleConfig); - if (groundingModuleConfig != null) - declaredFields.put("groundingModuleConfig", groundingModuleConfig); - if (inputTranslationModuleConfig != null) - declaredFields.put("inputTranslationModuleConfig", inputTranslationModuleConfig); - if (outputTranslationModuleConfig != null) - declaredFields.put("outputTranslationModuleConfig", outputTranslationModuleConfig); + if (promptTemplating != null) declaredFields.put("promptTemplating", promptTemplating); + if (filtering != null) declaredFields.put("filtering", filtering); + if (masking != null) declaredFields.put("masking", masking); + if (grounding != null) declaredFields.put("grounding", grounding); + if (translation != null) declaredFields.put("translation", translation); return declaredFields; } @@ -371,28 +273,17 @@ public boolean equals(@Nullable final java.lang.Object o) { } final ModuleConfigs moduleConfigs = (ModuleConfigs) o; return Objects.equals(this.cloudSdkCustomFields, moduleConfigs.cloudSdkCustomFields) - && Objects.equals(this.llmModuleConfig, moduleConfigs.llmModuleConfig) - && Objects.equals(this.templatingModuleConfig, moduleConfigs.templatingModuleConfig) - && Objects.equals(this.filteringModuleConfig, moduleConfigs.filteringModuleConfig) - && Objects.equals(this.maskingModuleConfig, moduleConfigs.maskingModuleConfig) - && Objects.equals(this.groundingModuleConfig, moduleConfigs.groundingModuleConfig) - && Objects.equals( - this.inputTranslationModuleConfig, moduleConfigs.inputTranslationModuleConfig) - && Objects.equals( - this.outputTranslationModuleConfig, moduleConfigs.outputTranslationModuleConfig); + && Objects.equals(this.promptTemplating, moduleConfigs.promptTemplating) + && Objects.equals(this.filtering, moduleConfigs.filtering) + && Objects.equals(this.masking, moduleConfigs.masking) + && Objects.equals(this.grounding, moduleConfigs.grounding) + && Objects.equals(this.translation, moduleConfigs.translation); } @Override public int hashCode() { return Objects.hash( - llmModuleConfig, - templatingModuleConfig, - filteringModuleConfig, - maskingModuleConfig, - groundingModuleConfig, - inputTranslationModuleConfig, - outputTranslationModuleConfig, - cloudSdkCustomFields); + promptTemplating, filtering, masking, grounding, translation, cloudSdkCustomFields); } @Override @@ -400,25 +291,11 @@ public int hashCode() { public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class ModuleConfigs {\n"); - sb.append(" llmModuleConfig: ").append(toIndentedString(llmModuleConfig)).append("\n"); - sb.append(" templatingModuleConfig: ") - .append(toIndentedString(templatingModuleConfig)) - .append("\n"); - sb.append(" filteringModuleConfig: ") - .append(toIndentedString(filteringModuleConfig)) - .append("\n"); - sb.append(" maskingModuleConfig: ") - .append(toIndentedString(maskingModuleConfig)) - .append("\n"); - sb.append(" groundingModuleConfig: ") - .append(toIndentedString(groundingModuleConfig)) - .append("\n"); - sb.append(" inputTranslationModuleConfig: ") - .append(toIndentedString(inputTranslationModuleConfig)) - .append("\n"); - sb.append(" outputTranslationModuleConfig: ") - .append(toIndentedString(outputTranslationModuleConfig)) - .append("\n"); + sb.append(" promptTemplating: ").append(toIndentedString(promptTemplating)).append("\n"); + sb.append(" filtering: ").append(toIndentedString(filtering)).append("\n"); + sb.append(" masking: ").append(toIndentedString(masking)).append("\n"); + sb.append(" grounding: ").append(toIndentedString(grounding)).append("\n"); + sb.append(" translation: ").append(toIndentedString(translation)).append("\n"); cloudSdkCustomFields.forEach( (k, v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); @@ -441,33 +318,17 @@ private String toIndentedString(final java.lang.Object o) { * with all required arguments. */ public static Builder create() { - return (llmModuleConfig) -> - (templatingModuleConfig) -> - new ModuleConfigs() - .llmModuleConfig(llmModuleConfig) - .templatingModuleConfig(templatingModuleConfig); + return (promptTemplating) -> new ModuleConfigs().promptTemplating(promptTemplating); } /** Builder helper class. */ public interface Builder { /** - * Set the llmModuleConfig of this {@link ModuleConfigs} instance. - * - * @param llmModuleConfig The llmModuleConfig of this {@link ModuleConfigs} - * @return The ModuleConfigs builder. - */ - Builder1 llmModuleConfig(@Nonnull final LLMModuleConfig llmModuleConfig); - } - - /** Builder helper class. */ - public interface Builder1 { - /** - * Set the templatingModuleConfig of this {@link ModuleConfigs} instance. + * Set the promptTemplating of this {@link ModuleConfigs} instance. * - * @param templatingModuleConfig The templatingModuleConfig of this {@link ModuleConfigs} + * @param promptTemplating The promptTemplating of this {@link ModuleConfigs} * @return The ModuleConfigs instance. */ - ModuleConfigs templatingModuleConfig( - @Nonnull final TemplatingModuleConfig templatingModuleConfig); + ModuleConfigs promptTemplating(@Nonnull final PromptTemplatingModuleConfig promptTemplating); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/OrchestrationConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/OrchestrationConfig.java index 9cfde53b3..7c5fc2721 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/OrchestrationConfig.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/OrchestrationConfig.java @@ -28,14 +28,11 @@ public class OrchestrationConfig // CHECKSTYLE:ON { - @JsonProperty("module_configurations") - private ModuleConfigs moduleConfigurations; + @JsonProperty("modules") + private ModuleConfigs modules; @JsonProperty("stream") - private Boolean stream = false; - - @JsonProperty("stream_options") - private GlobalStreamOptions streamOptions; + private GlobalStreamOptions stream; @JsonAnySetter @JsonAnyGetter private final Map cloudSdkCustomFields = new LinkedHashMap<>(); @@ -44,102 +41,67 @@ public class OrchestrationConfig protected OrchestrationConfig() {} /** - * Set the moduleConfigurations of this {@link OrchestrationConfig} instance and return the same - * instance. + * Set the modules of this {@link OrchestrationConfig} instance and return the same instance. * - * @param moduleConfigurations The moduleConfigurations of this {@link OrchestrationConfig} + * @param modules The modules of this {@link OrchestrationConfig} * @return The same instance of this {@link OrchestrationConfig} class */ @Nonnull - public OrchestrationConfig moduleConfigurations( - @Nonnull final ModuleConfigs moduleConfigurations) { - this.moduleConfigurations = moduleConfigurations; + public OrchestrationConfig modules(@Nonnull final ModuleConfigs modules) { + this.modules = modules; return this; } /** - * Get moduleConfigurations + * Get modules * - * @return moduleConfigurations The moduleConfigurations of this {@link OrchestrationConfig} - * instance. + * @return modules The modules of this {@link OrchestrationConfig} instance. */ @Nonnull - public ModuleConfigs getModuleConfigurations() { - return moduleConfigurations; + public ModuleConfigs getModules() { + return modules; } /** - * Set the moduleConfigurations of this {@link OrchestrationConfig} instance. + * Set the modules of this {@link OrchestrationConfig} instance. * - * @param moduleConfigurations The moduleConfigurations of this {@link OrchestrationConfig} + * @param modules The modules of this {@link OrchestrationConfig} */ - public void setModuleConfigurations(@Nonnull final ModuleConfigs moduleConfigurations) { - this.moduleConfigurations = moduleConfigurations; + public void setModules(@Nonnull final ModuleConfigs modules) { + this.modules = modules; } /** * Set the stream of this {@link OrchestrationConfig} instance and return the same instance. * - * @param stream If true, the response will be streamed back to the client + * @param stream The stream of this {@link OrchestrationConfig} * @return The same instance of this {@link OrchestrationConfig} class */ @Nonnull - public OrchestrationConfig stream(@Nullable final Boolean stream) { + public OrchestrationConfig stream(@Nullable final GlobalStreamOptions stream) { this.stream = stream; return this; } /** - * If true, the response will be streamed back to the client + * Get stream * * @return stream The stream of this {@link OrchestrationConfig} instance. */ @Nonnull - public Boolean isStream() { + public GlobalStreamOptions getStream() { return stream; } /** * Set the stream of this {@link OrchestrationConfig} instance. * - * @param stream If true, the response will be streamed back to the client + * @param stream The stream of this {@link OrchestrationConfig} */ - public void setStream(@Nullable final Boolean stream) { + public void setStream(@Nullable final GlobalStreamOptions stream) { this.stream = stream; } - /** - * Set the streamOptions of this {@link OrchestrationConfig} instance and return the same - * instance. - * - * @param streamOptions The streamOptions of this {@link OrchestrationConfig} - * @return The same instance of this {@link OrchestrationConfig} class - */ - @Nonnull - public OrchestrationConfig streamOptions(@Nullable final GlobalStreamOptions streamOptions) { - this.streamOptions = streamOptions; - return this; - } - - /** - * Get streamOptions - * - * @return streamOptions The streamOptions of this {@link OrchestrationConfig} instance. - */ - @Nonnull - public GlobalStreamOptions getStreamOptions() { - return streamOptions; - } - - /** - * Set the streamOptions of this {@link OrchestrationConfig} instance. - * - * @param streamOptions The streamOptions of this {@link OrchestrationConfig} - */ - public void setStreamOptions(@Nullable final GlobalStreamOptions streamOptions) { - this.streamOptions = streamOptions; - } - /** * Get the names of the unrecognizable properties of the {@link OrchestrationConfig}. * @@ -179,10 +141,8 @@ public Object getCustomField(@Nonnull final String name) throws NoSuchElementExc @Nonnull public Map toMap() { final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); - if (moduleConfigurations != null) - declaredFields.put("moduleConfigurations", moduleConfigurations); + if (modules != null) declaredFields.put("modules", modules); if (stream != null) declaredFields.put("stream", stream); - if (streamOptions != null) declaredFields.put("streamOptions", streamOptions); return declaredFields; } @@ -208,14 +168,13 @@ public boolean equals(@Nullable final java.lang.Object o) { } final OrchestrationConfig orchestrationConfig = (OrchestrationConfig) o; return Objects.equals(this.cloudSdkCustomFields, orchestrationConfig.cloudSdkCustomFields) - && Objects.equals(this.moduleConfigurations, orchestrationConfig.moduleConfigurations) - && Objects.equals(this.stream, orchestrationConfig.stream) - && Objects.equals(this.streamOptions, orchestrationConfig.streamOptions); + && Objects.equals(this.modules, orchestrationConfig.modules) + && Objects.equals(this.stream, orchestrationConfig.stream); } @Override public int hashCode() { - return Objects.hash(moduleConfigurations, stream, streamOptions, cloudSdkCustomFields); + return Objects.hash(modules, stream, cloudSdkCustomFields); } @Override @@ -223,11 +182,8 @@ public int hashCode() { public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("class OrchestrationConfig {\n"); - sb.append(" moduleConfigurations: ") - .append(toIndentedString(moduleConfigurations)) - .append("\n"); + sb.append(" modules: ").append(toIndentedString(modules)).append("\n"); sb.append(" stream: ").append(toIndentedString(stream)).append("\n"); - sb.append(" streamOptions: ").append(toIndentedString(streamOptions)).append("\n"); cloudSdkCustomFields.forEach( (k, v) -> sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); @@ -250,18 +206,17 @@ private String toIndentedString(final java.lang.Object o) { * instance with all required arguments. */ public static Builder create() { - return (moduleConfigurations) -> - new OrchestrationConfig().moduleConfigurations(moduleConfigurations); + return (modules) -> new OrchestrationConfig().modules(modules); } /** Builder helper class. */ public interface Builder { /** - * Set the moduleConfigurations of this {@link OrchestrationConfig} instance. + * Set the modules of this {@link OrchestrationConfig} instance. * - * @param moduleConfigurations The moduleConfigurations of this {@link OrchestrationConfig} + * @param modules The modules of this {@link OrchestrationConfig} * @return The OrchestrationConfig instance. */ - OrchestrationConfig moduleConfigurations(@Nonnull final ModuleConfigs moduleConfigurations); + OrchestrationConfig modules(@Nonnull final ModuleConfigs modules); } } diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/PromptTemplatingModuleConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/PromptTemplatingModuleConfig.java new file mode 100644 index 000000000..98d06ea1d --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/PromptTemplatingModuleConfig.java @@ -0,0 +1,240 @@ +/* + * Internal Orchestration Service API + * 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. + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.orchestration.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** PromptTemplatingModuleConfig */ +// CHECKSTYLE:OFF +public class PromptTemplatingModuleConfig +// CHECKSTYLE:ON +{ + @JsonProperty("prompt") + private PromptTemplatingModuleConfigPrompt prompt; + + @JsonProperty("model") + private LLMModelDetails model; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for PromptTemplatingModuleConfig. */ + protected PromptTemplatingModuleConfig() {} + + /** + * Set the prompt of this {@link PromptTemplatingModuleConfig} instance and return the same + * instance. + * + * @param prompt The prompt of this {@link PromptTemplatingModuleConfig} + * @return The same instance of this {@link PromptTemplatingModuleConfig} class + */ + @Nonnull + public PromptTemplatingModuleConfig prompt( + @Nonnull final PromptTemplatingModuleConfigPrompt prompt) { + this.prompt = prompt; + return this; + } + + /** + * Get prompt + * + * @return prompt The prompt of this {@link PromptTemplatingModuleConfig} instance. + */ + @Nonnull + public PromptTemplatingModuleConfigPrompt getPrompt() { + return prompt; + } + + /** + * Set the prompt of this {@link PromptTemplatingModuleConfig} instance. + * + * @param prompt The prompt of this {@link PromptTemplatingModuleConfig} + */ + public void setPrompt(@Nonnull final PromptTemplatingModuleConfigPrompt prompt) { + this.prompt = prompt; + } + + /** + * Set the model of this {@link PromptTemplatingModuleConfig} instance and return the same + * instance. + * + * @param model The model of this {@link PromptTemplatingModuleConfig} + * @return The same instance of this {@link PromptTemplatingModuleConfig} class + */ + @Nonnull + public PromptTemplatingModuleConfig model(@Nonnull final LLMModelDetails model) { + this.model = model; + return this; + } + + /** + * Get model + * + * @return model The model of this {@link PromptTemplatingModuleConfig} instance. + */ + @Nonnull + public LLMModelDetails getModel() { + return model; + } + + /** + * Set the model of this {@link PromptTemplatingModuleConfig} instance. + * + * @param model The model of this {@link PromptTemplatingModuleConfig} + */ + public void setModel(@Nonnull final LLMModelDetails model) { + this.model = model; + } + + /** + * Get the names of the unrecognizable properties of the {@link PromptTemplatingModuleConfig}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link PromptTemplatingModuleConfig} + * instance. + * + * @deprecated Use {@link #toMap()} instead. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + @Deprecated + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "PromptTemplatingModuleConfig has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link PromptTemplatingModuleConfig} instance including + * unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (prompt != null) declaredFields.put("prompt", prompt); + if (model != null) declaredFields.put("model", model); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link PromptTemplatingModuleConfig} instance. If the + * map previously contained a mapping for the key, the old value is replaced by the specified + * value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final PromptTemplatingModuleConfig promptTemplatingModuleConfig = + (PromptTemplatingModuleConfig) o; + return Objects.equals( + this.cloudSdkCustomFields, promptTemplatingModuleConfig.cloudSdkCustomFields) + && Objects.equals(this.prompt, promptTemplatingModuleConfig.prompt) + && Objects.equals(this.model, promptTemplatingModuleConfig.model); + } + + @Override + public int hashCode() { + return Objects.hash(prompt, model, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class PromptTemplatingModuleConfig {\n"); + sb.append(" prompt: ").append(toIndentedString(prompt)).append("\n"); + sb.append(" model: ").append(toIndentedString(model)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** + * Create a type-safe, fluent-api builder object to construct a new {@link + * PromptTemplatingModuleConfig} instance with all required arguments. + */ + public static Builder create() { + return (prompt) -> (model) -> new PromptTemplatingModuleConfig().prompt(prompt).model(model); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the prompt of this {@link PromptTemplatingModuleConfig} instance. + * + * @param prompt The prompt of this {@link PromptTemplatingModuleConfig} + * @return The PromptTemplatingModuleConfig builder. + */ + Builder1 prompt(@Nonnull final PromptTemplatingModuleConfigPrompt prompt); + } + + /** Builder helper class. */ + public interface Builder1 { + /** + * Set the model of this {@link PromptTemplatingModuleConfig} instance. + * + * @param model The model of this {@link PromptTemplatingModuleConfig} + * @return The PromptTemplatingModuleConfig instance. + */ + PromptTemplatingModuleConfig model(@Nonnull final LLMModelDetails model); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TemplatingModuleConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/PromptTemplatingModuleConfigPrompt.java similarity index 84% rename from orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TemplatingModuleConfig.java rename to orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/PromptTemplatingModuleConfigPrompt.java index a2f65146b..ef1267eab 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TemplatingModuleConfig.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/PromptTemplatingModuleConfigPrompt.java @@ -14,10 +14,13 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -/** TemplatingModuleConfig */ +/** + * The prompt template to be used. Can be either a user defined template or a reference to a + * template in the prompt registry. + */ @JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION) @JsonSubTypes({ @JsonSubTypes.Type(value = Template.class), @JsonSubTypes.Type(value = TemplateRef.class), }) -public interface TemplatingModuleConfig {} +public interface PromptTemplatingModuleConfigPrompt {} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Template.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Template.java index f7b38d0d7..5dce760e1 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Template.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Template.java @@ -29,7 +29,7 @@ /** Template */ // CHECKSTYLE:OFF -public class Template implements TemplatingModuleConfig +public class Template implements PromptTemplatingModuleConfigPrompt // CHECKSTYLE:ON { @JsonProperty("template") diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TemplateRef.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TemplateRef.java index 11cad22f0..4d83583b0 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TemplateRef.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TemplateRef.java @@ -25,7 +25,7 @@ /** TemplateRef */ // CHECKSTYLE:OFF -public class TemplateRef implements TemplatingModuleConfig +public class TemplateRef implements PromptTemplatingModuleConfigPrompt // CHECKSTYLE:ON { @JsonProperty("template_ref") diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TranslationModuleConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TranslationModuleConfig.java new file mode 100644 index 000000000..22e82e088 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/TranslationModuleConfig.java @@ -0,0 +1,208 @@ +/* + * Internal Orchestration Service API + * 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. + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.sap.ai.sdk.orchestration.model; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** Configuration for translation module */ +// CHECKSTYLE:OFF +public class TranslationModuleConfig +// CHECKSTYLE:ON +{ + @JsonProperty("input") + private SAPDocumentTranslation input; + + @JsonProperty("output") + private SAPDocumentTranslation output; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for TranslationModuleConfig. */ + protected TranslationModuleConfig() {} + + /** + * Set the input of this {@link TranslationModuleConfig} instance and return the same instance. + * + * @param input The input of this {@link TranslationModuleConfig} + * @return The same instance of this {@link TranslationModuleConfig} class + */ + @Nonnull + public TranslationModuleConfig input(@Nullable final SAPDocumentTranslation input) { + this.input = input; + return this; + } + + /** + * Get input + * + * @return input The input of this {@link TranslationModuleConfig} instance. + */ + @Nonnull + public SAPDocumentTranslation getInput() { + return input; + } + + /** + * Set the input of this {@link TranslationModuleConfig} instance. + * + * @param input The input of this {@link TranslationModuleConfig} + */ + public void setInput(@Nullable final SAPDocumentTranslation input) { + this.input = input; + } + + /** + * Set the output of this {@link TranslationModuleConfig} instance and return the same instance. + * + * @param output The output of this {@link TranslationModuleConfig} + * @return The same instance of this {@link TranslationModuleConfig} class + */ + @Nonnull + public TranslationModuleConfig output(@Nullable final SAPDocumentTranslation output) { + this.output = output; + return this; + } + + /** + * Get output + * + * @return output The output of this {@link TranslationModuleConfig} instance. + */ + @Nonnull + public SAPDocumentTranslation getOutput() { + return output; + } + + /** + * Set the output of this {@link TranslationModuleConfig} instance. + * + * @param output The output of this {@link TranslationModuleConfig} + */ + public void setOutput(@Nullable final SAPDocumentTranslation output) { + this.output = output; + } + + /** + * Get the names of the unrecognizable properties of the {@link TranslationModuleConfig}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link TranslationModuleConfig} instance. + * + * @deprecated Use {@link #toMap()} instead. + * @param name The name of the property + * @return The value of the property + * @throws NoSuchElementException If no property with the given name could be found. + */ + @Nullable + @Deprecated + public Object getCustomField(@Nonnull final String name) throws NoSuchElementException { + if (!cloudSdkCustomFields.containsKey(name)) { + throw new NoSuchElementException( + "TranslationModuleConfig has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link TranslationModuleConfig} instance including + * unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (input != null) declaredFields.put("input", input); + if (output != null) declaredFields.put("output", output); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link TranslationModuleConfig} instance. If the map + * previously contained a mapping for the key, the old value is replaced by the specified value. + * + * @param customFieldName The name of the property + * @param customFieldValue The value of the property + */ + @JsonIgnore + public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) { + cloudSdkCustomFields.put(customFieldName, customFieldValue); + } + + @Override + public boolean equals(@Nullable final java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final TranslationModuleConfig translationModuleConfig = (TranslationModuleConfig) o; + return Objects.equals(this.cloudSdkCustomFields, translationModuleConfig.cloudSdkCustomFields) + && Objects.equals(this.input, translationModuleConfig.input) + && Objects.equals(this.output, translationModuleConfig.output); + } + + @Override + public int hashCode() { + return Objects.hash(input, output, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class TranslationModuleConfig {\n"); + sb.append(" input: ").append(toIndentedString(input)).append("\n"); + sb.append(" output: ").append(toIndentedString(output)).append("\n"); + cloudSdkCustomFields.forEach( + (k, v) -> + sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n")); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(final java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + + /** Create a new {@link TranslationModuleConfig} instance. No arguments are required. */ + public static TranslationModuleConfig create() { + return new TranslationModuleConfig(); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java index f9e58b568..040306ddf 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java @@ -12,7 +12,7 @@ import com.sap.ai.sdk.orchestration.model.ChatCompletionTool; import com.sap.ai.sdk.orchestration.model.ChatCompletionTool.TypeEnum; import com.sap.ai.sdk.orchestration.model.FunctionObject; -import com.sap.ai.sdk.orchestration.model.LLMModuleConfig; +import com.sap.ai.sdk.orchestration.model.LLMModelDetails; import com.sap.ai.sdk.orchestration.model.Template; import java.util.List; import java.util.Map; @@ -60,7 +60,7 @@ public class OrchestrationChatOptions implements ToolCallingChatOptions { @Nonnull @Override public String getModel() { - return getLlmConfigNonNull().getModelName(); + return getLlmConfigNonNull().getName(); } /** @@ -70,7 +70,7 @@ public String getModel() { */ @Nonnull public String getModelVersion() { - return getLlmConfigNonNull().getModelVersion(); + return getLlmConfigNonNull().getVersion(); } /** @@ -173,7 +173,7 @@ public T copy() { @SuppressWarnings("unchecked") @Nullable private T getLlmConfigParam(@Nonnull final String param) { - return ((Map) getLlmConfigNonNull().getModelParams()).get(param); + return ((Map) getLlmConfigNonNull().getParams()).get(param); } @Override @@ -193,7 +193,7 @@ public Boolean getInternalToolExecutionEnabled() { } @Nonnull - private LLMModuleConfig getLlmConfigNonNull() { + private LLMModelDetails getLlmConfigNonNull() { return Objects.requireNonNull( config.getLlmConfig(), "LLM config is not set. Please set it: new OrchestrationChatOptions(new OrchestrationModuleConfig().withLlmConfig(...))"); diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatDelta.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatDelta.java index e03be99f0..23577e1f1 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatDelta.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatDelta.java @@ -26,9 +26,7 @@ public class OrchestrationSpringChatDelta extends ChatResponse { OrchestrationSpringChatDelta(@Nonnull final OrchestrationChatCompletionDelta delta) { - super( - toGenerations(delta.getOrchestrationResult()), - toChatResponseMetadata(delta.getOrchestrationResult())); + super(toGenerations(delta.getFinalResult()), toChatResponseMetadata(delta.getFinalResult())); } @Nonnull @@ -40,7 +38,7 @@ static List toGenerations(@Nonnull final LLMModuleResultStreaming re static Generation toGeneration(@Nonnull final LLMChoiceStreaming choice) { val metadata = ChatGenerationMetadata.builder().finishReason(choice.getFinishReason()); metadata.metadata("index", choice.getIndex()); - if (choice.getLogprobs() != null) { + if (choice.getLogprobs() != null && !choice.getLogprobs().getContent().isEmpty()) { metadata.metadata("logprobs", choice.getLogprobs().getContent()); } return new Generation(new AssistantMessage(choice.getDelta().getContent()), metadata.build()); diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatResponse.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatResponse.java index 9c69f03e1..c9e1ce49b 100644 --- a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatResponse.java +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationSpringChatResponse.java @@ -31,9 +31,8 @@ public class OrchestrationSpringChatResponse extends ChatResponse { OrchestrationSpringChatResponse(@Nonnull final OrchestrationChatResponse orchestrationResponse) { super( - toGenerations(orchestrationResponse.getOriginalResponse().getOrchestrationResult()), - toChatResponseMetadata( - orchestrationResponse.getOriginalResponse().getOrchestrationResult())); + toGenerations(orchestrationResponse.getOriginalResponse().getFinalResult()), + toChatResponseMetadata(orchestrationResponse.getOriginalResponse().getFinalResult())); this.orchestrationResponse = orchestrationResponse; } @@ -46,7 +45,7 @@ static List toGenerations(@Nonnull final LLMModuleResult result) { static Generation toGeneration(@Nonnull final LLMChoice choice) { val metadata = ChatGenerationMetadata.builder().finishReason(choice.getFinishReason()); metadata.metadata("index", choice.getIndex()); - if (choice.getLogprobs() != null) { + if (choice.getLogprobs() != null && !choice.getLogprobs().getContent().isEmpty()) { metadata.metadata("logprobs", choice.getLogprobs().getContent()); } val toolCalls = diff --git a/orchestration/src/main/resources/spec/orchestration.yaml b/orchestration/src/main/resources/spec/orchestration.yaml index c4bcd5dcf..865fe50ff 100644 --- a/orchestration/src/main/resources/spec/orchestration.yaml +++ b/orchestration/src/main/resources/spec/orchestration.yaml @@ -1,7 +1,7 @@ openapi: 3.0.0 servers: - - url: "/" + - url: "/v2" description: Internal Orchestration Service API x-sap-shortText: "Orchestration provides common capabilities for business AI scenarios, such as content filtering, data masking, and grounding" @@ -16,15 +16,17 @@ info: tags: - name: OrchestrationCompletion description: Run an orchestrated completion inference request + - name: OrchestrationEmbeddings + description: Make an embeddings request paths: - /v1/completion: + /completion: post: tags: - OrchestrationCompletion summary: orchestrated completion inference description: Run an orchestrated completion inference request - operationId: orchestration.v1.endpoints.create + operationId: orchestration.v2.endpoints.create requestBody: required: true content: @@ -46,14 +48,14 @@ paths: default: $ref: "#/components/responses/CommonError" - /v2/embeddings: + /embeddings: post: tags: - OrchestrationEmbeddings summary: orchestrated embeddings inference description: > Generate embeddings for input strings. - operationId: orchestration.v1.endpoints.create_embeddings + operationId: orchestration.v2.endpoints.create_embeddings requestBody: required: true content: @@ -79,12 +81,12 @@ components: CompletionPostRequest: type: object required: - - orchestration_config + - config additionalProperties: false properties: - orchestration_config: + config: $ref: "#/components/schemas/OrchestrationConfig" - input_params: + placeholder_values: type: object example: groundingInput: "What is SAP Joule?" @@ -521,16 +523,16 @@ components: type: object required: - request_id - - orchestration_result - - module_results + - final_result + - intermediate_results properties: request_id: description: ID of the request type: string example: "d4a67ea1-2bf9-4df7-8105-d48203ccff76" - module_results: + intermediate_results: $ref: "#/components/schemas/ModuleResults" - orchestration_result: + final_result: $ref: "#/components/schemas/LLMModuleResult" CompletionPostResponseStreaming: @@ -541,45 +543,36 @@ components: request_id: description: ID of the request type: string - module_results: + intermediate_results: $ref: "#/components/schemas/ModuleResultsStreaming" - orchestration_result: + final_result: $ref: "#/components/schemas/LLMModuleResultStreaming" OrchestrationConfig: type: object required: - - module_configurations + - modules additionalProperties: false properties: - module_configurations: + modules: $ref: "#/components/schemas/ModuleConfigs" stream: - type: boolean - description: If true, the response will be streamed back to the client - default: false - stream_options: $ref: "#/components/schemas/GlobalStreamOptions" ModuleConfigs: type: object required: - - llm_module_config - - templating_module_config + - prompt_templating additionalProperties: false properties: - llm_module_config: - $ref: "#/components/schemas/LLMModuleConfig" - templating_module_config: - $ref: "#/components/schemas/TemplatingModuleConfig" - filtering_module_config: + prompt_templating: + $ref: "#/components/schemas/PromptTemplatingModuleConfig" + filtering: $ref: "#/components/schemas/FilteringModuleConfig" - masking_module_config: + masking: $ref: "#/components/schemas/MaskingModuleConfig" - grounding_module_config: + grounding: $ref: "#/components/schemas/GroundingModuleConfig" - input_translation_module_config: - $ref: "#/components/schemas/InputTranslationModuleConfig" - output_translation_module_config: - $ref: "#/components/schemas/OutputTranslationModuleConfig" + translation: + $ref: "#/components/schemas/TranslationModuleConfig" # Abstract base class encompassing fields for both `ModuleResults` and `ModuleResultsStreaming` # Not to be instantiated by llm-orchestration code ModuleResultsBase: @@ -630,10 +623,14 @@ components: items: $ref: "#/components/schemas/LLMChoiceStreaming" GlobalStreamOptions: - description: Options for streaming. Will be ignored if stream is false. + description: Options for streaming. Will be ignored if enabled is false. type: object additionalProperties: false properties: + enabled: + type: boolean + description: If true, the response will be streamed back to the client + default: false chunk_size: type: integer description: Minimum number of characters per chunk that post-LLM modules operate on. @@ -648,34 +645,6 @@ components: type: string example: ["\n", ".", "?", "!"] - # --- LLM MODULE --- - LLMModuleConfig: - type: object - required: - - model_name - additionalProperties: false - properties: - model_name: - description: Model name as in LLM Access configuration - example: "gpt-4o-mini" - type: string - model_params: # optional, default values are used for mandatory model parameters - description: Model parameters - type: object - example: - max_tokens: 300 - temperature: 0.1 - frequency_penalty: 0 - presence_penalty: 0 - n: 2 - logprobs: true - stream_options: - include_usage: true - additionalProperties: true - model_version: - description: Version of the model to use - type: string - default: "latest" GenericModuleResult: type: object description: Generic module result @@ -691,7 +660,7 @@ components: description: Additional data object from the module LLMModuleResult: type: object - description: Output of LLM module. Follows the OpenAI spec. + description: Output from LLM. Follows the OpenAI spec. required: - id - object @@ -815,12 +784,50 @@ components: description: Total number of tokens used example: 50 - # --- Templating Module --- - - TemplatingModuleConfig: - oneOf: - - $ref: "#/components/schemas/Template" - - $ref: "#/components/schemas/TemplateRef" + # --- Prompt Templating Module --- + PromptTemplatingModuleConfig: + type: object + required: + - prompt + - model + additionalProperties: false + properties: + prompt: + description: > + The prompt template to be used. Can be either a user defined template or a reference to a template in the prompt registry. + oneOf: + - $ref: "#/components/schemas/Template" + - $ref: "#/components/schemas/TemplateRef" + model: + description: > + The model and parameters to be used for the prompt templating. This is the model that will be used to generate the response. + $ref: "#/components/schemas/LLMModelDetails" + LLMModelDetails: + type: object + required: + - name + additionalProperties: false + properties: + name: + type: string + description: Name of the model as in LLM Access configuration + example: "gpt-4o-mini" + version: + type: string + description: Version of the model to be used + default: "latest" + params: + type: object + description: Additional parameters for the model. Default values are used for mandatory parameters. + additionalProperties: true + example: + max_tokens: 300 + temperature: 0.1 + frequency_penalty: 0 + presence_penalty: 0 + n: 2 + stream_options: + include_usage: true # --- Templating Module with User Defined Template --- # response_format api definition taken from: https://github.com/openai/openai-openapi/blob/e0cb2d721753e13e69e918465795d6e9f87ab15a/openapi.yaml#L12286 @@ -858,7 +865,8 @@ components: example: template: - role: user - content: "How can the features of AI in SAP BTP specifically {{?groundingOutput}}, be applied to {{?inputContext}}" + # escape curly braces to avoid jinja2 interpreting them + content: "How can the features of AI in SAP BTP specifically {{'{{?groundingOutput}}'}}, be applied to {{'{{?inputContext}}'}}" defaults: inputContext: The default text that will be used in the template if inputContext is not set @@ -1134,15 +1142,15 @@ components: type: object additionalProperties: false properties: - Hate: + hate: $ref: "#/components/schemas/AzureThreshold" - SelfHarm: + self_harm: $ref: "#/components/schemas/AzureThreshold" - Sexual: + sexual: $ref: "#/components/schemas/AzureThreshold" - Violence: + violence: $ref: "#/components/schemas/AzureThreshold" - PromptShield: + prompt_shield: type: boolean description: A flag to use prompt shield default: false @@ -1152,13 +1160,13 @@ components: type: object additionalProperties: false properties: - Hate: + hate: $ref: "#/components/schemas/AzureThreshold" - SelfHarm: + self_harm: $ref: "#/components/schemas/AzureThreshold" - Sexual: + sexual: $ref: "#/components/schemas/AzureThreshold" - Violence: + violence: $ref: "#/components/schemas/AzureThreshold" AzureThreshold: @@ -1392,8 +1400,7 @@ components: config: type: object required: - - input_params - - output_param + - placeholders additionalProperties: false properties: filters: @@ -1402,17 +1409,25 @@ components: oneOf: - $ref: "#/components/schemas/DocumentGroundingFilter" description: Document grounding service filters to be used - input_params: - type: array - minItems: 1 - items: - type: string - example: groundingInput - description: Contains the input parameters used for grounding input questions - output_param: - type: string - description: Parameter name used for grounding output - example: groundingOutput + placeholders: + type: object + additionalProperties: false + required: + - input + - output + properties: + input: + type: array + minItems: 1 + items: + type: string + example: groundingInput + description: Contains the input parameters used for grounding input questions + output: + type: string + description: Placeholder name for grounding output + example: groundingOutput + description: Placeholders to be used for grounding input questions and output metadata_params: type: array items: @@ -1540,12 +1555,19 @@ components: title: SearchSelectOptionEnum # --- Translation Module --- - InputTranslationModuleConfig: - oneOf: - - $ref: "#/components/schemas/SAPDocumentTranslation" - OutputTranslationModuleConfig: - oneOf: - - $ref: "#/components/schemas/SAPDocumentTranslation" + TranslationModuleConfig: + type: object + description: Configuration for translation module + additionalProperties: false + properties: + input: + description: Configuration for input translation + oneOf: + - $ref: "#/components/schemas/SAPDocumentTranslation" + output: + description: Configuration for output translation + oneOf: + - $ref: "#/components/schemas/SAPDocumentTranslation" SAPDocumentTranslation: type: object required: @@ -1574,8 +1596,7 @@ components: type: string description: Language to which the text should be translated. example: "en-US" - - ErrorResponse: + Error: type: object required: - request_id @@ -1596,10 +1617,10 @@ components: type: string description: Where the error occurred example: "LLM Module" - module_results: + intermediate_results: $ref: "#/components/schemas/ModuleResults" - ErrorResponseStreaming: + ErrorStreaming: type: object required: - request_id @@ -1620,9 +1641,25 @@ components: type: string description: Where the error occurred example: "LLM Module" - module_results: + intermediate_results: $ref: "#/components/schemas/ModuleResultsStreaming" + ErrorResponse: + type: object + required: + - error + properties: + error: + $ref: "#/components/schemas/Error" + + ErrorResponseStreaming: + type: object + required: + - error + properties: + error: + $ref: "#/components/schemas/ErrorStreaming" + # ref : https://github.com/openai/openai-python/blob/main/src/openai/types/chat/chat_completion_token_logprob.py ChatCompletionTokenLogprob: type: object @@ -1702,4 +1739,4 @@ components: type: http scheme: bearer bearerFormat: JWT - description: To use this API, you must have an AI Core access token. + description: To use this API, you must have an AI Core access token. \ No newline at end of file diff --git a/orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfigTest.java b/orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfigTest.java index 79255d199..21191c198 100644 --- a/orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfigTest.java +++ b/orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfigTest.java @@ -149,9 +149,9 @@ void testLLMConfig() { var config = new OrchestrationModuleConfig().withLlmConfig(aiModel); assertThat(config.getLlmConfig()).isNotNull(); - assertThat(config.getLlmConfig().getModelName()).isEqualTo(GPT_4O.getName()); - assertThat(config.getLlmConfig().getModelParams()).isEqualTo(params); - assertThat(config.getLlmConfig().getModelVersion()).isEqualTo(version); + assertThat(config.getLlmConfig().getName()).isEqualTo(GPT_4O.getName()); + assertThat(config.getLlmConfig().getParams()).isEqualTo(params); + assertThat(config.getLlmConfig().getVersion()).isEqualTo(version); assertThat(GPT_4O.getParams()).withFailMessage("Static models should be unchanged").isEmpty(); assertThat(GPT_4O.getVersion()) @@ -170,8 +170,8 @@ void testGroundingConfig() { GroundingModuleConfigConfig configConfig = config.getGroundingConfig().getConfig(); assertThat(configConfig).isNotNull(); - assertThat(configConfig.getInputParams()).containsExactly("userMessage"); - assertThat(configConfig.getOutputParam()).isEqualTo("groundingContext"); + assertThat(configConfig.getPlaceholders().getInput()).containsExactly("userMessage"); + assertThat(configConfig.getPlaceholders().getOutput()).isEqualTo("groundingContext"); List filters = configConfig.getFilters(); assertThat(filters).hasSize(1); diff --git a/orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java b/orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java index b06ea7f7f..060ca8430 100644 --- a/orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java +++ b/orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java @@ -21,6 +21,7 @@ import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.GPT_4O_MINI; import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.*; import static com.sap.ai.sdk.orchestration.model.AzureThreshold.NUMBER_0; +import static com.sap.ai.sdk.orchestration.model.AzureThreshold.NUMBER_4; import static com.sap.ai.sdk.orchestration.model.AzureThreshold.NUMBER_6; import static com.sap.ai.sdk.orchestration.model.ResponseChatMessage.RoleEnum.ASSISTANT; import static com.sap.ai.sdk.orchestration.model.UserChatMessage.RoleEnum.USER; @@ -62,6 +63,7 @@ import com.sap.ai.sdk.orchestration.model.GroundingFilterSearchConfiguration; import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig; import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfig; +import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfigPlaceholders; import com.sap.ai.sdk.orchestration.model.KeyValueListPair; import com.sap.ai.sdk.orchestration.model.LlamaGuard38b; import com.sap.ai.sdk.orchestration.model.MaskingModuleConfig; @@ -140,7 +142,7 @@ void reset() { @Test void testCompletion() { stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .willReturn( aResponse() .withBodyFile("templatingResponse.json") @@ -154,7 +156,7 @@ void testCompletion() { @Test void testCompletionError() { stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .willReturn( aResponse() .withStatus(500) @@ -169,7 +171,7 @@ void testCompletionError() { @Test void testGrounding() throws IOException { stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .willReturn( aResponse() .withBodyFile("groundingResponse.json") @@ -188,8 +190,10 @@ void testGrounding() throws IOException { .chunkMetadata(List.of(KeyValueListPair.create().key("chunk metadata").value("1"))); final var groundingConfigConfig = GroundingModuleConfigConfig.create() - .inputParams(List.of("query")) - .outputParam("results") + .placeholders( + GroundingModuleConfigConfigPlaceholders.create() + .input(List.of("query")) + .output("results")) .addFiltersItem(databaseFilter); final var groundingConfig = GroundingModuleConfig.create() @@ -216,7 +220,7 @@ void testGrounding() throws IOException { assertThat(response.getOriginalResponse().getRequestId()) .isEqualTo("e5d2add4-408c-4da5-84ca-1d8b0fe350c8"); - var moduleResults = response.getOriginalResponse().getModuleResults(); + var moduleResults = response.getOriginalResponse().getIntermediateResults(); assertThat(moduleResults).isNotNull(); var groundingModule = moduleResults.getGrounding(); @@ -231,7 +235,7 @@ void testGrounding() throws IOException { "First chunk```Second chunk```Last found chunk"); assertThat(groundingModule.getData()).isEqualTo(groundingData); - var inputMasking = response.getOriginalResponse().getModuleResults().getInputMasking(); + var inputMasking = response.getOriginalResponse().getIntermediateResults().getInputMasking(); assertThat(inputMasking.getMessage()) .isEqualTo("Input to LLM and Grounding is masked successfully."); Object data = inputMasking.getData(); @@ -245,14 +249,15 @@ void testGrounding() throws IOException { try (var requestInputStream = fileLoader.apply("groundingRequest.json")) { final String request = new String(requestInputStream.readAllBytes()); - verify(postRequestedFor(urlPathEqualTo("/completion")).withRequestBody(equalToJson(request))); + verify( + postRequestedFor(urlPathEqualTo("/v2/completion")).withRequestBody(equalToJson(request))); } } @Test void testGroundingWithHelpSapCom() throws IOException { stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .willReturn( aResponse() .withBodyFile("groundingHelpSapComResponse.json") @@ -266,14 +271,21 @@ void testGroundingWithHelpSapCom() throws IOException { val response = client.chatCompletion(prompt, configWithGrounding); assertThat( - response.getOriginalResponse().getModuleResults().getGrounding().getData().toString()) + response + .getOriginalResponse() + .getIntermediateResults() + .getGrounding() + .getData() + .toString()) .contains( "A fuzzy search is a search technique that is designed to be fast and tolerant of errors"); assertThat(response.getContent()).startsWith("A fuzzy search is a search technique"); try (var requestInputStream = fileLoader.apply("groundingHelpSapComRequest.json")) { final String request = new String(requestInputStream.readAllBytes()); - verify(postRequestedFor(urlPathEqualTo("/completion")).withRequestBody(equalToJson(request))); + verify( + postRequestedFor(urlPathEqualTo("/v2/completion")) + .withRequestBody(equalToJson(request, true, true))); } } @@ -307,7 +319,7 @@ void testTemplating() throws IOException { .isEqualTo("Orchestration Service funktioniert!"); assertThat(messageList.get(2).role()).isEqualTo("assistant"); - var llm = response.getModuleResults().getLlm(); + var llm = response.getIntermediateResults().getLlm(); assertThat(llm).isNotNull(); assertThat(llm.getId()).isEqualTo("chatcmpl-9lzPV4kLrXjFckOp2yY454wksWBoj"); assertThat(llm.getObject()).isEqualTo("chat.completion"); @@ -323,7 +335,7 @@ void testTemplating() throws IOException { assertThat(usage.getCompletionTokens()).isEqualTo(7); assertThat(usage.getPromptTokens()).isEqualTo(19); assertThat(usage.getTotalTokens()).isEqualTo(26); - var orchestrationResult = response.getOrchestrationResult(); + var orchestrationResult = response.getFinalResult(); assertThat(orchestrationResult.getId()).isEqualTo("chatcmpl-9lzPV4kLrXjFckOp2yY454wksWBoj"); assertThat(orchestrationResult.getObject()).isEqualTo("chat.completion"); assertThat(orchestrationResult.getCreated()).isEqualTo(1721224505); @@ -353,20 +365,35 @@ void testBadRequest() { .willReturn( jsonResponse( """ - { - "request_id": "51043a32-01f5-429a-b0e7-3a99432e43a4", - "code": 400, - "message": "Missing required parameters: ['input']", - "location": "Module: Templating", - "module_results": {} + { "error": + { + "request_id": "51043a32-01f5-429a-b0e7-3a99432e43a4", + "code": 400, + "message": "Missing required parameters: ['input']", + "location": "Module: Templating", + "intermediate_results": {} + } } """, SC_BAD_REQUEST))); assertThatThrownBy(() -> client.chatCompletion(prompt, config)) - .isInstanceOf(OrchestrationClientException.class) - .hasMessage( - "Request failed with status 400 (Bad Request): Missing required parameters: ['input']"); + .isInstanceOfSatisfying( + OrchestrationClientException.class, + e -> { + assertThat(e.getMessage()) + .isEqualTo( + "Request failed with status 400 (Bad Request): Missing required parameters: ['input']"); + assertThat(e.getErrorResponseStreaming()).isNull(); + assertThat(e.getErrorResponse()).isNotNull(); + assertThat(e.getErrorResponse().getError().getMessage()) + .isEqualTo("Missing required parameters: ['input']"); + assertThat(e.getErrorResponse().getError().getCode()).isEqualTo(SC_BAD_REQUEST); + assertThat(e.getErrorResponse().getError().getRequestId()) + .isEqualTo("51043a32-01f5-429a-b0e7-3a99432e43a4"); + assertThat(e.getErrorResponse().getError().getLocation()) + .isEqualTo("Module: Templating"); + }); } @Test @@ -395,7 +422,7 @@ void filteringLoose() throws IOException { // verify that null fields are absent from the sent request try (var requestInputStream = fileLoader.apply("filteringLooseRequest.json")) { final String request = new String(requestInputStream.readAllBytes()); - verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(request))); + verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(request, true, true))); } } @@ -420,42 +447,43 @@ void inputFilteringStrict() { new LlamaGuardFilter().config(LlamaGuard38b.create().violentCrimes(true)); final var configWithFilter = config.withInputFiltering(azureFilter, llamaFilter); - try { - client.chatCompletion(prompt, configWithFilter); - } catch (OrchestrationFilterException.Input e) { - assertThat(e.getMessage()) - .isEqualTo( - "Request failed with status 400 (Bad Request): 400 - Filtering Module - Input Filter: Prompt filtered due to safety violations. Please modify the prompt and try again."); - assertThat(e.getStatusCode()).isEqualTo(SC_BAD_REQUEST); - assertThat(e.getFilterDetails()) - .isEqualTo( - Map.of( - "azure_content_safety", + assertThatThrownBy(() -> client.chatCompletion(prompt, configWithFilter)) + .isInstanceOfSatisfying( + OrchestrationFilterException.Input.class, + e -> { + assertThat(e.getMessage()) + .isEqualTo( + "Request failed with status 400 (Bad Request): 400 - Filtering Module - Input Filter: Prompt filtered due to safety violations. Please modify the prompt and try again."); + assertThat(e.getStatusCode()).isEqualTo(SC_BAD_REQUEST); + assertThat(e.getFilterDetails()) + .isEqualTo( Map.of( - "Hate", 6, - "SelfHarm", 0, - "Sexual", 0, - "Violence", 6, - "userPromptAnalysis", Map.of("attackDetected", false)), - "llama_guard_3_8b", Map.of("violent_crimes", true))); - - final var errorResponse = e.getErrorResponse(); - assertThat(errorResponse).isNotNull(); - assertThat(errorResponse).isInstanceOf(ErrorResponse.class); - assertThat(errorResponse.getCode()).isEqualTo(SC_BAD_REQUEST); - assertThat(errorResponse.getMessage()) - .isEqualTo( - "400 - Filtering Module - Input Filter: Prompt filtered due to safety violations. Please modify the prompt and try again."); - - assertThat(e.getAzureContentSafetyInput()).isNotNull(); - assertThat(e.getAzureContentSafetyInput().getHate()).isEqualTo(NUMBER_6); - assertThat(e.getAzureContentSafetyInput().getSelfHarm()).isEqualTo(NUMBER_0); - assertThat(e.getAzureContentSafetyInput().getSexual()).isEqualTo(NUMBER_0); - assertThat(e.getAzureContentSafetyInput().getViolence()).isEqualTo(NUMBER_6); - - assertThat(e.getLlamaGuard38b()).isNotNull(); - assertThat(e.getLlamaGuard38b().isViolentCrimes()).isTrue(); - } + "azure_content_safety", + Map.of( + "Hate", 6, + "SelfHarm", 0, + "Sexual", 0, + "Violence", 6, + "userPromptAnalysis", Map.of("attackDetected", false)), + "llama_guard_3_8b", Map.of("violent_crimes", true))); + + final var errorResponse = e.getErrorResponse(); + assertThat(errorResponse).isNotNull(); + assertThat(errorResponse).isInstanceOf(ErrorResponse.class); + assertThat(errorResponse.getError().getCode()).isEqualTo(SC_BAD_REQUEST); + assertThat(errorResponse.getError().getMessage()) + .isEqualTo( + "400 - Filtering Module - Input Filter: Prompt filtered due to safety violations. Please modify the prompt and try again."); + + assertThat(e.getAzureContentSafetyInput()).isNotNull(); + assertThat(e.getAzureContentSafetyInput().getHate()).isEqualTo(NUMBER_6); + assertThat(e.getAzureContentSafetyInput().getSelfHarm()).isEqualTo(NUMBER_0); + assertThat(e.getAzureContentSafetyInput().getSexual()).isEqualTo(NUMBER_0); + assertThat(e.getAzureContentSafetyInput().getViolence()).isEqualTo(NUMBER_6); + + assertThat(e.getLlamaGuard38b()).isNotNull(); + assertThat(e.getLlamaGuard38b().isViolentCrimes()).isTrue(); + }); } @Test @@ -473,33 +501,36 @@ void outputFilteringStrict() { new LlamaGuardFilter().config(LlamaGuard38b.create().violentCrimes(true)); final var configWithFilter = config.withOutputFiltering(azureFilter, llamaFilter); - try { - client.chatCompletion(prompt, configWithFilter).getContent(); - } catch (OrchestrationFilterException.Output e) { - assertThat(e.getMessage()).isEqualTo("Content filter filtered the output."); - assertThat(e.getFilterDetails()) - .isEqualTo( - Map.of( - "index", 0, - "azure_content_safety", + assertThatThrownBy(client.chatCompletion(prompt, configWithFilter)::getContent) + .isInstanceOfSatisfying( + OrchestrationFilterException.Output.class, + e -> { + assertThat(e.getMessage()).isEqualTo("Content filter filtered the output."); + assertThat(e.getFilterDetails()) + .isEqualTo( Map.of( - "Hate", 6, - "SelfHarm", 0, - "Sexual", 0, - "Violence", 6), - "llama_guard_3_8b", Map.of("violent_crimes", true))); - assertThat(e.getErrorResponse()).isNull(); - assertThat(e.getStatusCode()).isNull(); - - assertThat(e.getAzureContentSafetyOutput()).isNotNull(); - assertThat(e.getAzureContentSafetyOutput().getHate()).isEqualTo(NUMBER_6); - assertThat(e.getAzureContentSafetyOutput().getSelfHarm()).isEqualTo(NUMBER_0); - assertThat(e.getAzureContentSafetyOutput().getSexual()).isEqualTo(NUMBER_0); - assertThat(e.getAzureContentSafetyOutput().getViolence()).isEqualTo(NUMBER_6); - - assertThat(e.getLlamaGuard38b()).isNotNull(); - assertThat(e.getLlamaGuard38b().isViolentCrimes()).isTrue(); - } + "index", + 0, + "azure_content_safety", + Map.of( + "Hate", 6, + "SelfHarm", 0, + "Sexual", 0, + "Violence", 6), + "llama_guard_3_8b", + Map.of("violent_crimes", true))); + assertThat(e.getErrorResponse()).isNull(); + assertThat(e.getStatusCode()).isNull(); + + assertThat(e.getAzureContentSafetyOutput()).isNotNull(); + assertThat(e.getAzureContentSafetyOutput().getHate()).isEqualTo(NUMBER_6); + assertThat(e.getAzureContentSafetyOutput().getSelfHarm()).isEqualTo(NUMBER_0); + assertThat(e.getAzureContentSafetyOutput().getSexual()).isEqualTo(NUMBER_0); + assertThat(e.getAzureContentSafetyOutput().getViolence()).isEqualTo(NUMBER_6); + + assertThat(e.getLlamaGuard38b()).isNotNull(); + assertThat(e.getLlamaGuard38b().isViolentCrimes()).isTrue(); + }); } @Test @@ -550,7 +581,7 @@ void maskingPseudonymization() throws IOException { final var response = result.getOriginalResponse(); assertThat(response).isNotNull(); - GenericModuleResult inputMasking = response.getModuleResults().getInputMasking(); + GenericModuleResult inputMasking = response.getIntermediateResults().getInputMasking(); assertThat(inputMasking).isNotNull(); assertThat(inputMasking.getMessage()).isEqualTo("Input to LLM is masked successfully."); assertThat(inputMasking.getData()).isNotNull(); @@ -559,7 +590,7 @@ void maskingPseudonymization() throws IOException { // verify that the request is sent correctly try (var requestInputStream = fileLoader.apply("maskingRequest.json")) { final String request = new String(requestInputStream.readAllBytes()); - verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(request))); + verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(request, true, true))); } } @@ -621,7 +652,7 @@ void testErrorHandling(@Nonnull final Runnable request) { .assertThatThrownBy(request::run) .describedAs("Error objects from Orchestration should be interpreted") .isInstanceOf(OrchestrationClientException.class) - .hasMessageContaining("'orchestration_config' is a required property"); + .hasMessageContaining("'config' is a required property"); softly .assertThatThrownBy(request::run) @@ -713,7 +744,7 @@ void testThrowsOnContentFilter() { when(deltaWithContentFilter.getFinishReason()).thenReturn("content_filter"); var moduleResults = mock(ModuleResultsStreaming.class); - when(deltaWithContentFilter.getModuleResults()).thenReturn(moduleResults); + when(deltaWithContentFilter.getIntermediateResults()).thenReturn(moduleResults); var outputFiltering = mock(GenericModuleResult.class); when(moduleResults.getOutputFiltering()).thenReturn(outputFiltering); @@ -752,8 +783,28 @@ void streamChatCompletionOutputFilterErrorHandling() throws IOException { try (Stream stream = client.streamChatCompletion(prompt, config)) { assertThatThrownBy(() -> stream.forEach(System.out::println)) - .isInstanceOf(OrchestrationFilterException.Output.class) - .hasMessage("Content filter filtered the output."); + .hasMessage("Content filter filtered the output.") + .isInstanceOfSatisfying( + OrchestrationFilterException.Output.class, + e -> { + assertThat(e.getErrorResponse()).isNull(); + assertThat(e.getErrorResponseStreaming()).isNull(); + assertThat(e.getStatusCode()).isNull(); + + assertThat(e.getFilterDetails()) + .isEqualTo( + Map.of( + "index", + 0, + "azure_content_safety", + Map.of("Hate", 0, "SelfHarm", 0, "Sexual", 0, "Violence", 4))); + + assertThat(e.getAzureContentSafetyOutput()).isNotNull(); + assertThat(e.getAzureContentSafetyOutput().getHate()).isEqualTo(NUMBER_0); + assertThat(e.getAzureContentSafetyOutput().getSelfHarm()).isEqualTo(NUMBER_0); + assertThat(e.getAzureContentSafetyOutput().getSexual()).isEqualTo(NUMBER_0); + assertThat(e.getAzureContentSafetyOutput().getViolence()).isEqualTo(NUMBER_4); + }); } Mockito.verify(inputStream, times(1)).close(); @@ -803,9 +854,9 @@ void streamChatCompletionDeltas() throws IOException { assertThat(deltaList.get(2).getFinishReason()).isEqualTo("stop"); // should be of type LLMModuleResultStreaming, will be fixed with a discriminator - var result0 = deltaList.get(0).getOrchestrationResult(); - var result1 = deltaList.get(1).getOrchestrationResult(); - var result2 = deltaList.get(2).getOrchestrationResult(); + var result0 = deltaList.get(0).getFinalResult(); + var result1 = deltaList.get(1).getFinalResult(); + var result2 = deltaList.get(2).getFinalResult(); assertThat(result0.getSystemFingerprint()).isEmpty(); assertThat(result0.getId()).isEmpty(); @@ -823,7 +874,7 @@ void streamChatCompletionDeltas() throws IOException { final ChatDelta message0 = choices0.getDelta(); assertThat(message0.getRole()).isEqualTo(""); assertThat(message0.getContent()).isEqualTo(""); - final var templating = deltaList.get(0).getModuleResults().getTemplating(); + final var templating = deltaList.get(0).getIntermediateResults().getTemplating(); assertThat(templating).hasSize(1); final var templateItem = (UserChatMessage) templating.get(0); @@ -869,7 +920,7 @@ void streamChatCompletionDeltas() throws IOException { @Test void testMultiMessage() throws IOException { stubFor( - post("/completion") + post("/v2/completion") .willReturn(aResponse().withStatus(SC_OK).withBodyFile("multiMessageResponse.json"))); var llmWithImageSupportConfig = new OrchestrationModuleConfig().withLlmConfig(GPT_4O_MINI); @@ -924,7 +975,7 @@ void testMultiMessage() throws IOException { "Well, this image features the logo of SAP, a software company, set against a gradient blue background transitioning from light to dark. The main color in the image is blue."); assertThat(response).isNotNull(); - var llmResults = response.getModuleResults().getLlm(); + var llmResults = response.getIntermediateResults().getLlm(); assertThat(llmResults).isNotNull(); assertThat(llmResults.getChoices()).hasSize(1); assertThat(llmResults.getChoices().get(0).getMessage().getContent()) @@ -932,7 +983,7 @@ void testMultiMessage() throws IOException { "Well, this image features the logo of SAP, a software company, set against a gradient blue background transitioning from light to dark. The main color in the image is blue."); assertThat(llmResults.getChoices().get(0).getFinishReason()).isEqualTo("stop"); assertThat(llmResults.getChoices().get(0).getMessage().getRole()).isEqualTo(ASSISTANT); - var orchestrationResult = response.getOrchestrationResult(); + var orchestrationResult = response.getFinalResult(); assertThat(orchestrationResult.getChoices()).hasSize(1); assertThat(orchestrationResult.getChoices().get(0).getMessage().getContent()) .isEqualTo( @@ -943,7 +994,7 @@ void testMultiMessage() throws IOException { try (var requestInputStream = fileLoader.apply("multiMessageRequest.json")) { final String requestBody = new String(requestInputStream.readAllBytes()); verify( - postRequestedFor(urlPathEqualTo("/completion")) + postRequestedFor(urlPathEqualTo("/v2/completion")) .withRequestBody(equalToJson(requestBody))); } } @@ -1125,7 +1176,8 @@ void testTemplateFromPromptRegistryById() throws IOException { final var response = client.chatCompletion(prompt, configWithTemplate); assertThat(response.getContent()).startsWith("I sistemi ERP (Enterprise Resource Planning)"); - assertThat(response.getOriginalResponse().getModuleResults().getTemplating()).hasSize(2); + assertThat(response.getOriginalResponse().getIntermediateResults().getTemplating()) + .hasSize(2); try (var requestInputStream = fileLoader.apply("templateReferenceByIdRequest.json")) { final String request = new String(requestInputStream.readAllBytes()); @@ -1151,7 +1203,7 @@ void testTemplateFromPromptRegistryByScenario() throws IOException { final var response = client.chatCompletion(prompt, configWithTemplate); assertThat(response.getContent()).startsWith("I sistemi ERP (Enterprise Resource Planning)"); - assertThat(response.getOriginalResponse().getModuleResults().getTemplating()).hasSize(2); + assertThat(response.getOriginalResponse().getIntermediateResults().getTemplating()).hasSize(2); try (var requestInputStream = fileLoader.apply("templateReferenceByScenarioRequest.json")) { final String request = new String(requestInputStream.readAllBytes()); diff --git a/orchestration/src/test/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModelTest.java b/orchestration/src/test/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModelTest.java index 38b16f1d6..ca16b78a6 100644 --- a/orchestration/src/test/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModelTest.java +++ b/orchestration/src/test/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModelTest.java @@ -79,7 +79,7 @@ void reset() { @Test void testCompletion() { stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .willReturn( aResponse() .withBodyFile("templatingResponse.json") @@ -149,7 +149,7 @@ void testStreamCompletion() throws IOException { @Test void testToolCallsWithoutExecution() throws IOException { stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .willReturn( aResponse() .withBodyFile("toolCallsResponse.json") @@ -183,7 +183,7 @@ void testToolCallsWithoutExecution() throws IOException { void testToolCallsWithExecution() throws IOException { // https://platform.openai.com/docs/guides/function-calling stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .inScenario("Tool Calls") .whenScenarioStateIs(STARTED) .willReturn( @@ -193,7 +193,7 @@ void testToolCallsWithExecution() throws IOException { .willSetStateTo("Second Call")); stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .inScenario("Tool Calls") .whenScenarioStateIs("Second Call") .willReturn( @@ -221,7 +221,7 @@ void testToolCallsWithExecution() throws IOException { @Test void testChatMemory() throws IOException { stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .inScenario("Chat Memory") .whenScenarioStateIs(STARTED) .willReturn( @@ -231,7 +231,7 @@ void testChatMemory() throws IOException { .willSetStateTo("Second Call")); stubFor( - post(urlPathEqualTo("/completion")) + post(urlPathEqualTo("/v2/completion")) .inScenario("Chat Memory") .whenScenarioStateIs("Second Call") .willReturn( diff --git a/orchestration/src/test/resources/__files/error500Response.json b/orchestration/src/test/resources/__files/error500Response.json index 1156041cc..fa284baf6 100644 --- a/orchestration/src/test/resources/__files/error500Response.json +++ b/orchestration/src/test/resources/__files/error500Response.json @@ -1,14 +1,16 @@ { - "request_id": "d647775b-725b-428a-90b7-348cbf30f7f4", - "code": 500, - "message": "Internal Server Error", - "location": "Masking Module - Masking", - "module_results": { - "templating": [ - { - "role": "user", - "content": "yo" - } - ] + "error": { + "request_id": "d647775b-725b-428a-90b7-348cbf30f7f4", + "code": 500, + "message": "Internal Server Error", + "location": "Masking Module - Masking", + "intermediate_results": { + "templating": [ + { + "role": "user", + "content": "yo" + } + ] + } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/errorJsonSchemaResponse.json b/orchestration/src/test/resources/__files/errorJsonSchemaResponse.json index 62544892a..ce2af889d 100644 --- a/orchestration/src/test/resources/__files/errorJsonSchemaResponse.json +++ b/orchestration/src/test/resources/__files/errorJsonSchemaResponse.json @@ -1,6 +1,6 @@ { "request_id": "0759f249-a261-4cb7-99d5-ea6eae2c141c", - "module_results": { + "intermediate_results": { "templating": [ { "role": "user", @@ -34,7 +34,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-AzmCw5QZBi6zQkJPQhvsyjW4Fe90c", "object": "chat.completion", "created": 1739286682, @@ -56,4 +56,4 @@ "total_tokens": 78 } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/errorResponse.json b/orchestration/src/test/resources/__files/errorResponse.json index 6964cbc16..c8f8144d9 100644 --- a/orchestration/src/test/resources/__files/errorResponse.json +++ b/orchestration/src/test/resources/__files/errorResponse.json @@ -1,7 +1,9 @@ { - "request_id": "59468e72-7309-4299-b988-bf3bbea461f8", - "code": 400, - "message": "'orchestration_config' is a required property", - "location": "request body", - "module_results": {} + "error": { + "request_id": "59468e72-7309-4299-b988-bf3bbea461f8", + "code": 400, + "message": "'config' is a required property", + "location": "request body", + "intermediate_results": {} + } } \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/filteringLooseResponse.json b/orchestration/src/test/resources/__files/filteringLooseResponse.json index ce2545f04..b48d6bfa6 100644 --- a/orchestration/src/test/resources/__files/filteringLooseResponse.json +++ b/orchestration/src/test/resources/__files/filteringLooseResponse.json @@ -1,6 +1,6 @@ { "request_id": "b329745f-4b6b-4d42-b891-974b33689a19", - "module_results": { + "intermediate_results": { "grounding": null, "templating": [ { @@ -13,10 +13,10 @@ "message": "Input filter passed successfully.", "data": { "original_service_response": { - "Hate": 0, - "SelfHarm": 0, - "Sexual": 0, - "Violence": 2 + "hate": 0, + "self_harm": 0, + "sexual": 0, + "violence": 2 }, "checked_text": "Create a rental posting for subletting my apartment in the downtown area. Keep it short. Make sure to add the following disclaimer to the end. Do not change it! ```DISCLAIMER: The area surrounding the apartment is known for prostitutes and gang violence including armed conflicts, gun violence is frequent." } @@ -34,8 +34,7 @@ "role": "assistant", "content": "Cozy Downtown Apartment for Sublet!\n\nLooking for a temporary place to call home in the heart of downtown? Look no further! This cozy apartment is up for subletting and offers a convenient and vibrant city living experience.\n\nFeatures:\n- Prime location" }, - "logprobs": { - }, + "logprobs": {}, "finish_reason": "length" } ], @@ -49,17 +48,17 @@ "message": "Output filter passed successfully.", "data": { "original_service_response": { - "Hate": 0, - "SelfHarm": 0, - "Sexual": 0, - "Violence": 0 + "hate": 0, + "self_harm": 0, + "sexual": 0, + "violence": 0 }, "checked_text": "Cozy Downtown Apartment for Sublet!\n\nLooking for a temporary place to call home in the heart of downtown? Look no further! This cozy apartment is up for subletting and offers a convenient and vibrant city living experience.\n\nFeatures:\n- Prime location" } }, "output_unmasking": null }, - "orchestration_result": { + "final_result": { "object": "chat.completion", "id": "chatcmpl-9o4df7DpIjY6CJdfe9hws1lrWZbHq", "created": 1721721259, @@ -72,8 +71,7 @@ "role": "assistant", "content": "Cozy Downtown Apartment for Sublet!\n\nLooking for a temporary place to call home in the heart of downtown? Look no further! This cozy apartment is up for subletting and offers a convenient and vibrant city living experience.\n\nFeatures:\n- Prime location" }, - "logprobs": { - }, + "logprobs": {}, "finish_reason": "length" } ], @@ -83,4 +81,4 @@ "total_tokens": 118 } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/groundingHelpSapComResponse.json b/orchestration/src/test/resources/__files/groundingHelpSapComResponse.json index 997df815f..7f046395a 100644 --- a/orchestration/src/test/resources/__files/groundingHelpSapComResponse.json +++ b/orchestration/src/test/resources/__files/groundingHelpSapComResponse.json @@ -1,6 +1,6 @@ { "request_id": "47ee9f8c-3c54-4028-aabe-358f89409de9", - "module_results": { + "intermediate_results": { "grounding": { "message": "grounding result", "data": { @@ -37,7 +37,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-B7fExAgihXpKnBaaJ3uXnLgmaC6Ox", "object": "chat.completion", "created": 1741166523, diff --git a/orchestration/src/test/resources/__files/groundingResponse.json b/orchestration/src/test/resources/__files/groundingResponse.json index 19ff167f4..3270d5b57 100644 --- a/orchestration/src/test/resources/__files/groundingResponse.json +++ b/orchestration/src/test/resources/__files/groundingResponse.json @@ -1,6 +1,6 @@ { "request_id": "e5d2add4-408c-4da5-84ca-1d8b0fe350c8", - "module_results": { + "intermediate_results": { "grounding": { "message": "grounding result", "data": { @@ -44,7 +44,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-Apz5s3CMf99jkOnxvPshH1rGLwvvU", "object": "chat.completion", "created": 1736952936, @@ -66,4 +66,4 @@ "total_tokens": 380 } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/jsonObjectResponse.json b/orchestration/src/test/resources/__files/jsonObjectResponse.json index 78d2d9ab1..3d5ea9b23 100644 --- a/orchestration/src/test/resources/__files/jsonObjectResponse.json +++ b/orchestration/src/test/resources/__files/jsonObjectResponse.json @@ -1,6 +1,6 @@ { "request_id": "f353a729-3391-4cec-bbf9-7ab39d34ebc1", - "module_results": { + "intermediate_results": { "templating": [ { "role": "user", @@ -34,7 +34,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-Azm2iclgMiLcQHP3cGQANArkxoiGx", "object": "chat.completion", "created": 1739286048, diff --git a/orchestration/src/test/resources/__files/jsonSchemaResponse.json b/orchestration/src/test/resources/__files/jsonSchemaResponse.json index 4d8816ed0..6236f02dc 100644 --- a/orchestration/src/test/resources/__files/jsonSchemaResponse.json +++ b/orchestration/src/test/resources/__files/jsonSchemaResponse.json @@ -1,6 +1,6 @@ { "request_id": "0759f249-a261-4cb7-99d5-ea6eae2c141c", - "module_results": { + "intermediate_results": { "templating": [ { "role": "user", @@ -34,7 +34,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-AzmCw5QZBi6zQkJPQhvsyjW4Fe90c", "object": "chat.completion", "created": 1739286682, diff --git a/orchestration/src/test/resources/__files/maskingResponse.json b/orchestration/src/test/resources/__files/maskingResponse.json index 15b194ffe..3120fc636 100644 --- a/orchestration/src/test/resources/__files/maskingResponse.json +++ b/orchestration/src/test/resources/__files/maskingResponse.json @@ -1,6 +1,6 @@ { "request_id": "c252c73e-849f-4fa7-8b35-b16f3434a0da", - "module_results": { + "intermediate_results": { "templating": [ { "role": "system", @@ -50,7 +50,7 @@ } ] }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-AUr7GVVoQbg52GRbADpkx4hQvDBiz", "object": "chat.completion", "created": 1731917382, @@ -72,4 +72,4 @@ "total_tokens": 198 } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/multiMessageResponse.json b/orchestration/src/test/resources/__files/multiMessageResponse.json index c04de51ba..900b8f6ff 100644 --- a/orchestration/src/test/resources/__files/multiMessageResponse.json +++ b/orchestration/src/test/resources/__files/multiMessageResponse.json @@ -1,6 +1,6 @@ { "request_id": "8d973a0d-c2cf-437b-a765-08d66bf446d8", - "module_results": { + "intermediate_results": { "templating": [ { "role": "system", @@ -59,7 +59,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-AyGx4yLYUH79TK81i21BaABoUpf4v", "object": "chat.completion", "created": 1738928206, diff --git a/orchestration/src/test/resources/__files/outputFilteringStrict.json b/orchestration/src/test/resources/__files/outputFilteringStrict.json index 72e69619f..e34f2bce6 100644 --- a/orchestration/src/test/resources/__files/outputFilteringStrict.json +++ b/orchestration/src/test/resources/__files/outputFilteringStrict.json @@ -1,6 +1,6 @@ { "request_id": "3db65fd0-7945-45ed-82f5-fe3811325fd5", - "module_results": { + "intermediate_results": { "templating": [ { "role": "system", @@ -52,7 +52,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "", "object": "chat.completion", "created": 1753449453, diff --git a/orchestration/src/test/resources/__files/responseFormatTextResponse.json b/orchestration/src/test/resources/__files/responseFormatTextResponse.json index c8be61c5a..38ac850c6 100644 --- a/orchestration/src/test/resources/__files/responseFormatTextResponse.json +++ b/orchestration/src/test/resources/__files/responseFormatTextResponse.json @@ -1,6 +1,6 @@ { "request_id": "2fe5cbeb-4cdc-4a62-8d0b-29bbd8acde07", - "module_results": { + "intermediate_results": { "templating": [ { "role": "user", @@ -34,7 +34,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-AzmS9fd4aGRUdEVsQufpFXSVStfck", "object": "chat.completion", "created": 1739287625, diff --git a/orchestration/src/test/resources/__files/streamChatCompletionInputFilter.json b/orchestration/src/test/resources/__files/streamChatCompletionInputFilter.json index 4d46693de..656f1339a 100644 --- a/orchestration/src/test/resources/__files/streamChatCompletionInputFilter.json +++ b/orchestration/src/test/resources/__files/streamChatCompletionInputFilter.json @@ -3,7 +3,7 @@ "code": 400, "message": "Content filtered due to safety violations. Please modify the prompt and try again.", "location": "Filtering Module - Input Filter", - "module_results": { + "intermediate_results": { "templating": [ { "role": "user", @@ -14,9 +14,9 @@ "message": "Content filtered due to safety violations. Please modify the prompt and try again.", "data": { "azure_content_safety": { - "Hate": 2 + "hate": 2 } } } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/strictInputFilterResponse.json b/orchestration/src/test/resources/__files/strictInputFilterResponse.json index 2cdaaa105..9b4f086aa 100644 --- a/orchestration/src/test/resources/__files/strictInputFilterResponse.json +++ b/orchestration/src/test/resources/__files/strictInputFilterResponse.json @@ -1,29 +1,31 @@ { - "request_id": "7ed0869f-05be-406b-8124-e9d94516c190", - "code": 400, - "message": "400 - Filtering Module - Input Filter: Prompt filtered due to safety violations. Please modify the prompt and try again.", - "location": "Filtering Module - Input Filter", - "module_results": { - "templating": [ - { - "content": "Let us paint the parliament red with blood of our enemies.", - "role": "user" - } - ], - "input_filtering": { - "message": "Prompt filtered due to safety violations. Please modify the prompt and try again.", - "data": { - "azure_content_safety": { - "Hate": 6, - "SelfHarm": 0, - "Sexual": 0, - "Violence": 6, - "userPromptAnalysis": { - "attackDetected": false + "error": { + "request_id": "7ed0869f-05be-406b-8124-e9d94516c190", + "code": 400, + "message": "400 - Filtering Module - Input Filter: Prompt filtered due to safety violations. Please modify the prompt and try again.", + "location": "Filtering Module - Input Filter", + "intermediate_results": { + "templating": [ + { + "content": "Let us paint the parliament red with blood of our enemies.", + "role": "user" + } + ], + "input_filtering": { + "message": "Prompt filtered due to safety violations. Please modify the prompt and try again.", + "data": { + "azure_content_safety": { + "Hate": 6, + "SelfHarm": 0, + "Sexual": 0, + "Violence": 6, + "userPromptAnalysis": { + "attackDetected": false + } + }, + "llama_guard_3_8b": { + "violent_crimes": true } - }, - "llama_guard_3_8b": { - "violent_crimes": true } } } diff --git a/orchestration/src/test/resources/__files/templateReferenceResponse.json b/orchestration/src/test/resources/__files/templateReferenceResponse.json index 3cdc2ca03..9c933eb69 100644 --- a/orchestration/src/test/resources/__files/templateReferenceResponse.json +++ b/orchestration/src/test/resources/__files/templateReferenceResponse.json @@ -1,6 +1,6 @@ { "request_id": "c02a6e4c-5552-4a72-a801-b6512d4f2f2a", - "module_results": { + "intermediate_results": { "templating": [ { "role": "system", @@ -34,7 +34,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-B6zYkaS7gjo5Ye6U87iK0B2dp4hde", "object": "chat.completion", "created": 1741006302, diff --git a/orchestration/src/test/resources/__files/templatingResponse.json b/orchestration/src/test/resources/__files/templatingResponse.json index db75c56ee..1f95f859a 100644 --- a/orchestration/src/test/resources/__files/templatingResponse.json +++ b/orchestration/src/test/resources/__files/templatingResponse.json @@ -1,6 +1,6 @@ { "request_id": "26ea36b5-c196-4806-a9a6-a686f0c6ad91", - "module_results": { + "intermediate_results": { "templating": [ { "role": "system", @@ -41,7 +41,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-9lzPV4kLrXjFckOp2yY454wksWBoj", "object": "chat.completion", "created": 1721224505, @@ -62,4 +62,4 @@ "total_tokens": 26 } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/toolCallsResponse.json b/orchestration/src/test/resources/__files/toolCallsResponse.json index 5a0f30f0e..761bc787c 100644 --- a/orchestration/src/test/resources/__files/toolCallsResponse.json +++ b/orchestration/src/test/resources/__files/toolCallsResponse.json @@ -1,6 +1,6 @@ { "request_id": "935d602a-021d-4da1-a8d9-b4bae42f5720", - "module_results": { + "intermediate_results": { "templating": [ { "role": "user", @@ -48,7 +48,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-AxUvsJ4kwEGSGFp6ha89MBWdU9lCW", "object": "chat.completion", "created": 1738743620, @@ -88,4 +88,4 @@ "total_tokens": 121 } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/__files/toolCallsResponse2.json b/orchestration/src/test/resources/__files/toolCallsResponse2.json index 53037d1c9..076687786 100644 --- a/orchestration/src/test/resources/__files/toolCallsResponse2.json +++ b/orchestration/src/test/resources/__files/toolCallsResponse2.json @@ -1,6 +1,6 @@ { "request_id": "935d602a-021d-4da1-a8d9-b4bae42f5720", - "module_results": { + "intermediate_results": { "templating": [ { "role": "user", @@ -62,7 +62,7 @@ } } }, - "orchestration_result": { + "final_result": { "id": "chatcmpl-AxUvsJ4kwEGSGFp6ha89MBWdU9lCW", "object": "chat.completion", "created": 1738743620, @@ -84,4 +84,4 @@ "total_tokens": 121 } } -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/chatMemory.json b/orchestration/src/test/resources/chatMemory.json index bcff50015..e54805028 100644 --- a/orchestration/src/test/resources/chatMemory.json +++ b/orchestration/src/test/resources/chatMemory.json @@ -1,33 +1,34 @@ { - "orchestration_config": { - "module_configurations": { - "llm_module_config": { - "model_name" : "gpt-4o", - "model_params": {}, - "model_version": "latest" - }, - "templating_module_config": { - "template": [ - { - "role": "user", - "content": "What is the capital of France?" - }, - { - "role": "assistant", - "content" : "Le service d'orchestration fonctionne!", - "tool_calls" : [ ] - }, - { - "role": "user", - "content": "And what is the typical food there?" - } - ], - "defaults": {}, - "tools": [] + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": {}, + "version": "latest" + }, + "prompt": { + "template": [ + { + "role": "user", + "content": "What is the capital of France?" + }, + { + "role": "assistant", + "content": "Le service d'orchestration fonctionne!", + "tool_calls": [] + }, + { + "role": "user", + "content": "And what is the typical food there?" + } + ], + "defaults": {}, + "tools": [] + } } - }, - "stream": false + } }, - "input_params": {}, + "placeholder_values": {}, "messages_history": [] -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/filteringLooseRequest.json b/orchestration/src/test/resources/filteringLooseRequest.json index eb0f49f32..0bad22cee 100644 --- a/orchestration/src/test/resources/filteringLooseRequest.json +++ b/orchestration/src/test/resources/filteringLooseRequest.json @@ -1,38 +1,40 @@ { - "orchestration_config": { - "module_configurations": { - "llm_module_config": { - "model_name": "gpt-4o", - "model_params": { - "temperature": 0.1, - "max_tokens": 50, - "frequency_penalty": 0, - "presence_penalty": 0, - "top_p" : 1, - "n" : 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "temperature": 0.1, + "max_tokens": 50, + "frequency_penalty": 0, + "presence_penalty": 0, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version": "latest" - }, - "templating_module_config": { - "template": [ - { - "role": "user", - "content": "Hello World! Why is this phrase so famous?" - } - ], - "defaults" : { }, - "tools" : [ ] + "prompt": { + "template": [ + { + "role": "user", + "content": "Hello World! Why is this phrase so famous?" + } + ], + "defaults": {}, + "tools": [] + } }, - "filtering_module_config": { + "filtering": { "input": { "filters": [ { "type": "azure_content_safety", "config": { - "Hate": 4, - "SelfHarm": 4, - "Sexual": 4, - "Violence": 4 + "hate": 4, + "self_harm": 4, + "sexual": 4, + "violence": 4 } }, { @@ -48,19 +50,17 @@ { "type": "azure_content_safety", "config": { - "Hate": 4, - "SelfHarm": 4, - "Sexual": 4, - "Violence": 4 + "hate": 4, + "self_harm": 4, + "sexual": 4, + "violence": 4 } } ] } } - }, - "stream": false - }, - "input_params": { + } }, + "placeholder_values": {}, "messages_history": [] -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/groundingHelpSapComRequest.json b/orchestration/src/test/resources/groundingHelpSapComRequest.json index 37b5fee37..7dbce7039 100644 --- a/orchestration/src/test/resources/groundingHelpSapComRequest.json +++ b/orchestration/src/test/resources/groundingHelpSapComRequest.json @@ -1,45 +1,56 @@ { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o", - "model_params" : { - "max_tokens" : 50, - "temperature" : 0.1, - "frequency_penalty" : 0, - "presence_penalty" : 0, - "top_p" : 1, - "n" : 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "max_tokens": 50, + "temperature": 0.1, + "frequency_penalty": 0, + "presence_penalty": 0, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template" : [ { - "role" : "user", - "content" : "{{?userMessage}} Use the following information as additional context: {{?groundingContext}}" - } ], - "defaults" : { }, - "tools" : [ ] + "prompt": { + "template": [ + { + "role": "user", + "content": "{{?userMessage}} Use the following information as additional context: {{?groundingContext}}" + } + ], + "defaults": {}, + "tools": [] + } }, - "grounding_module_config" : { - "type" : "document_grounding_service", - "config" : { - "filters" : [ { - "data_repositories" : [ "*" ], - "data_repository_type" : "help.sap.com", - "data_repository_metadata" : [ ], - "document_metadata" : [ ], - "chunk_metadata" : [ ] - } ], - "input_params" : [ "userMessage" ], - "output_param" : "groundingContext" + "grounding": { + "type": "document_grounding_service", + "config": { + "filters": [ + { + "data_repositories": [ + "*" + ], + "data_repository_type": "help.sap.com", + "data_repository_metadata": [], + "document_metadata": [], + "chunk_metadata": [] + } + ], + "placeholders": { + "input": [ + "userMessage" + ], + "output": "groundingContext" + } } } - }, - "stream" : false + } }, - "input_params" : { - "userMessage" : "What is a fuzzy search?" + "placeholder_values": { + "userMessage": "What is a fuzzy search?" }, - "messages_history" : [ ] + "messages_history": [] } \ No newline at end of file diff --git a/orchestration/src/test/resources/groundingRequest.json b/orchestration/src/test/resources/groundingRequest.json index e22194d9e..f89fdea20 100644 --- a/orchestration/src/test/resources/groundingRequest.json +++ b/orchestration/src/test/resources/groundingRequest.json @@ -1,69 +1,97 @@ { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o", - "model_params" : { - "max_tokens" : 50, - "temperature" : 0.1, - "frequency_penalty" : 0, - "presence_penalty" : 0, - "top_p" : 1, - "n" : 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "max_tokens": 50, + "temperature": 0.1, + "frequency_penalty": 0, + "presence_penalty": 0, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template" : [ { - "role" : "system", - "content" : "Context message with embedded grounding results. {{?results}}" - } ], - "defaults" : { }, - "tools" : [ ] + "prompt": { + "template": [ + { + "role": "system", + "content": "Context message with embedded grounding results. {{?results}}" + } + ], + "defaults": {}, + "tools": [] + } }, - "masking_module_config" : { - "masking_providers" : [ { - "type" : "sap_data_privacy_integration", - "method" : "anonymization", - "entities" : [ { - "type" : "profile-sensitive-data" - } ], - "allowlist" : [ "SAP", "Joule" ], - "mask_grounding_input" : { - "enabled" : true + "masking": { + "masking_providers": [ + { + "type": "sap_data_privacy_integration", + "method": "anonymization", + "entities": [ + { + "type": "profile-sensitive-data" + } + ], + "allowlist": [ + "SAP", + "Joule" + ], + "mask_grounding_input": { + "enabled": true + } } - } ] + ] }, - "grounding_module_config" : { - "type" : "document_grounding_service", - "config" : { - "filters" : [ { - "search_config" : { - "max_chunk_count" : 3 - }, - "data_repositories" : [ "*" ], - "data_repository_type" : "vector", - "data_repository_metadata" : [ ], - "document_metadata" : [ { - "key" : "document metadata", - "value" : [ "2" ], - "select_mode" : [ "ignoreIfKeyAbsent" ] - } ], - "chunk_metadata" : [ { - "key" : "chunk metadata", - "value" : [ "1" ] - } ] - } ], - "input_params" : [ "query" ], - "output_param" : "results", - "metadata_params" : [ ] + "grounding": { + "type": "document_grounding_service", + "config": { + "filters": [ + { + "search_config": { + "max_chunk_count": 3 + }, + "data_repositories": [ + "*" + ], + "data_repository_type": "vector", + "data_repository_metadata": [], + "document_metadata": [ + { + "key": "document metadata", + "value": [ + "2" + ], + "select_mode": [ + "ignoreIfKeyAbsent" + ] + } + ], + "chunk_metadata": [ + { + "key": "chunk metadata", + "value": [ + "1" + ] + } + ] + } + ], + "placeholders": { + "input": [ + "query" + ], + "output": "results" + }, + "metadata_params": [] } } - }, - "stream" : false + } }, - "input_params" : { - "query" : "String used for similarity search in database" + "placeholder_values": { + "query": "String used for similarity search in database" }, - "messages_history" : [ ] -} + "messages_history": [] +} \ No newline at end of file diff --git a/orchestration/src/test/resources/jsonObjectRequest.json b/orchestration/src/test/resources/jsonObjectRequest.json index b386108c8..906751456 100644 --- a/orchestration/src/test/resources/jsonObjectRequest.json +++ b/orchestration/src/test/resources/jsonObjectRequest.json @@ -1,28 +1,32 @@ { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o-mini", - "model_params" : { }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template" : [ { - "role" : "user", - "content" : "What is 'apple' in German?" - }, { - "role" : "system", - "content" : "You are a language translator. Answer using the following JSON format: {\"language\": ..., \"translation\": ...}" - } ], - "defaults" : { }, - "response_format" : { - "type" : "json_object" + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o-mini", + "params": {}, + "version": "latest" }, - "tools" : [ ] + "prompt": { + "template": [ + { + "role": "user", + "content": "What is 'apple' in German?" + }, + { + "role": "system", + "content": "You are a language translator. Answer using the following JSON format: {\"language\": ..., \"translation\": ...}" + } + ], + "defaults": {}, + "response_format": { + "type": "json_object" + }, + "tools": [] + } } - }, - "stream" : false + } }, - "input_params" : { }, - "messages_history" : [ ] + "placeholder_values": {}, + "messages_history": [] } \ No newline at end of file diff --git a/orchestration/src/test/resources/jsonSchemaRequest.json b/orchestration/src/test/resources/jsonSchemaRequest.json index c2c697672..2ab7decb8 100644 --- a/orchestration/src/test/resources/jsonSchemaRequest.json +++ b/orchestration/src/test/resources/jsonSchemaRequest.json @@ -1,46 +1,53 @@ { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o-mini", - "model_params" : { }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template" : [ { - "role" : "user", - "content" : "Whats 'apple' in German?" - }, { - "role" : "system", - "content" : "You are a language translator." - } ], - "defaults" : { }, - "response_format" : { - "type" : "json_schema", - "json_schema" : { - "description" : "Output schema for language translation.", - "name" : "Translation-Schema", - "schema" : { - "type" : "object", - "properties" : { - "language" : { - "type" : "string" + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o-mini", + "params": {}, + "version": "latest" + }, + "prompt": { + "template": [ + { + "role": "user", + "content": "Whats 'apple' in German?" + }, + { + "role": "system", + "content": "You are a language translator." + } + ], + "defaults": {}, + "response_format": { + "type": "json_schema", + "json_schema": { + "description": "Output schema for language translation.", + "name": "Translation-Schema", + "schema": { + "type": "object", + "properties": { + "language": { + "type": "string" + }, + "translation": { + "type": "string" + } }, - "translation" : { - "type" : "string" - } + "required": [ + "language", + "translation" + ], + "additionalProperties": false }, - "required" : [ "language", "translation" ], - "additionalProperties" : false - }, - "strict" : true - } - }, - "tools" : [ ] + "strict": true + } + }, + "tools": [] + } } - }, - "stream" : false + } }, - "input_params" : { }, - "messages_history" : [ ] + "placeholder_values": {}, + "messages_history": [] } \ No newline at end of file diff --git a/orchestration/src/test/resources/localTemplateRequest.json b/orchestration/src/test/resources/localTemplateRequest.json index ee1e21318..91149d958 100644 --- a/orchestration/src/test/resources/localTemplateRequest.json +++ b/orchestration/src/test/resources/localTemplateRequest.json @@ -1,77 +1,89 @@ { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o", - "model_params" : { - "max_tokens" : 50, - "temperature" : 0.1, - "frequency_penalty" : 0, - "presence_penalty" : 0, - "top_p" : 1, - "n" : 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "max_tokens": 50, + "temperature": 0.1, + "frequency_penalty": 0, + "presence_penalty": 0, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template" : [ { - "role" : "system", - "content" : "You are a language translator." - }, { - "role" : "user", - "content" : "Whats {{ ?word }} in {{ ?language }}?" - } ], - "defaults" : { - "word" : "apple" - }, - "response_format" : { - "type" : "json_schema", - "json_schema" : { - "name" : "translation-schema", - "description" : "Translate the given word into the provided language.", - "strict" : true, - "schema" : { - "type" : "object", - "additionalProperties" : false, - "required" : [ "language", "translation" ], - "properties" : { - "language" : { - "type" : "string" - }, - "translation" : { - "type" : "string" + "prompt": { + "template": [ + { + "role": "system", + "content": "You are a language translator." + }, + { + "role": "user", + "content": "Whats {{ ?word }} in {{ ?language }}?" + } + ], + "defaults": { + "word": "apple" + }, + "response_format": { + "type": "json_schema", + "json_schema": { + "name": "translation-schema", + "description": "Translate the given word into the provided language.", + "strict": true, + "schema": { + "type": "object", + "additionalProperties": false, + "required": [ + "language", + "translation" + ], + "properties": { + "language": { + "type": "string" + }, + "translation": { + "type": "string" + } } } } - } - }, - "tools" : [ { - "type" : "function", - "function" : { - "description" : "Translate a word.", - "name" : "translate", - "parameters" : { - "type" : "object", - "additionalProperties" : false, - "required" : [ "language", "wordToTranslate" ], - "properties" : { - "language" : { - "type" : "string" + }, + "tools": [ + { + "type": "function", + "function": { + "description": "Translate a word.", + "name": "translate", + "parameters": { + "type": "object", + "additionalProperties": false, + "required": [ + "language", + "wordToTranslate" + ], + "properties": { + "language": { + "type": "string" + }, + "wordToTranslate": { + "type": "string" + } + } }, - "wordToTranslate" : { - "type" : "string" - } + "strict": true } - }, - "strict" : true - } - } ] + } + ] + } } - }, - "stream" : false + } }, - "input_params" : { - "language" : "German" + "placeholder_values": { + "language": "German" }, - "messages_history" : [ ] + "messages_history": [] } \ No newline at end of file diff --git a/orchestration/src/test/resources/maskingRequest.json b/orchestration/src/test/resources/maskingRequest.json index ad4e4748e..418eb4961 100644 --- a/orchestration/src/test/resources/maskingRequest.json +++ b/orchestration/src/test/resources/maskingRequest.json @@ -1,29 +1,31 @@ { - "orchestration_config": { - "module_configurations": { - "llm_module_config": { - "model_name": "gpt-4o", - "model_params": { - "presence_penalty": 0, - "frequency_penalty": 0, - "max_tokens": 50, - "temperature": 0.1, - "top_p" : 1, - "n" : 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "presence_penalty": 0, + "frequency_penalty": 0, + "max_tokens": 50, + "temperature": 0.1, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version": "latest" - }, - "templating_module_config": { - "template": [ - { - "role": "user", - "content": "Hello World! Why is this phrase so famous?" - } - ], - "defaults" : { }, - "tools" : [ ] + "prompt": { + "template": [ + { + "role": "user", + "content": "Hello World! Why is this phrase so famous?" + } + ], + "defaults": {}, + "tools": [] + } }, - "masking_module_config": { + "masking": { "masking_providers": [ { "type": "sap_data_privacy_integration", @@ -33,16 +35,15 @@ "type": "profile-phone" } ], - "allowlist" : [ ], - "mask_grounding_input" : { - "enabled" : false + "allowlist": [], + "mask_grounding_input": { + "enabled": false } } ] } - }, - "stream": false + } }, - "input_params": {}, + "placeholder_values": {}, "messages_history": [] -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/messagesHistoryRequest.json b/orchestration/src/test/resources/messagesHistoryRequest.json index 42d860930..21e08393a 100644 --- a/orchestration/src/test/resources/messagesHistoryRequest.json +++ b/orchestration/src/test/resources/messagesHistoryRequest.json @@ -1,32 +1,33 @@ { - "orchestration_config": { - "module_configurations": { - "llm_module_config": { - "model_name": "gpt-4o", - "model_params": { - "presence_penalty": 0, - "frequency_penalty": 0, - "max_tokens": 50, - "temperature": 0.1, - "top_p": 1, - "n": 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "presence_penalty": 0, + "frequency_penalty": 0, + "max_tokens": 50, + "temperature": 0.1, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version": "latest" - }, - "templating_module_config": { - "template": [ - { - "role": "user", - "content": "What is the typical food there?" - } - ], - "defaults": {}, - "tools": [] + "prompt": { + "template": [ + { + "role": "user", + "content": "What is the typical food there?" + } + ], + "defaults": {}, + "tools": [] + } } - }, - "stream": false + } }, - "input_params": {}, + "placeholder_values": {}, "messages_history": [ { "role": "user", @@ -47,4 +48,4 @@ "tool_calls": [] } ] -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/multiMessageRequest.json b/orchestration/src/test/resources/multiMessageRequest.json index c88a4d7f6..5f549cc9f 100644 --- a/orchestration/src/test/resources/multiMessageRequest.json +++ b/orchestration/src/test/resources/multiMessageRequest.json @@ -1,44 +1,55 @@ - { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o-mini", - "model_params" : { }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template" : [ { - "role" : "user", - "content" : [ { - "type" : "text", - "text" : "What is in this image?" - }, { - "type" : "text", - "text" : "And what is the main color?" - }, { - "type" : "image_url", - "image_url" : { - "url" : "https://upload.wikimedia.org/wikipedia/commons/thumb/5/59/SAP_2011_logo.svg/440px-SAP_2011_logo.svg.png", - "detail" : "auto" + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o-mini", + "params": {}, + "version": "latest" + }, + "prompt": { + "template": [ + { + "role": "user", + "content": [ + { + "type": "text", + "text": "What is in this image?" + }, + { + "type": "text", + "text": "And what is the main color?" + }, + { + "type": "image_url", + "image_url": { + "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/5/59/SAP_2011_logo.svg/440px-SAP_2011_logo.svg.png", + "detail": "auto" + } + } + ] } - } ] - } ], - "defaults" : { }, - "tools" : [ ] + ], + "defaults": {}, + "tools": [] + } } - }, - "stream" : false + } }, - "input_params" : { }, - "messages_history" : [ { - "role" : "system", - "content" : [ { - "type" : "text", - "text" : "Please answer in exactly two sentences." - }, { - "type" : "text", - "text" : "Start the first sentence with the word 'Well'." - } ] - } ] + "placeholder_values": {}, + "messages_history": [ + { + "role": "system", + "content": [ + { + "type": "text", + "text": "Please answer in exactly two sentences." + }, + { + "type": "text", + "text": "Start the first sentence with the word 'Well'." + } + ] + } + ] } \ No newline at end of file diff --git a/orchestration/src/test/resources/responseFormatTextRequest.json b/orchestration/src/test/resources/responseFormatTextRequest.json index 8c50cb6da..5318ed0a9 100644 --- a/orchestration/src/test/resources/responseFormatTextRequest.json +++ b/orchestration/src/test/resources/responseFormatTextRequest.json @@ -1,28 +1,32 @@ { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o-mini", - "model_params" : { }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template" : [ { - "role" : "user", - "content" : "What is 'apple' in German?" - }, { - "role" : "system", - "content" : "You are a language translator. Answer using JSON." - } ], - "defaults" : { }, - "response_format" : { - "type" : "text" + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o-mini", + "params": {}, + "version": "latest" }, - "tools" : [ ] + "prompt": { + "template": [ + { + "role": "user", + "content": "What is 'apple' in German?" + }, + { + "role": "system", + "content": "You are a language translator. Answer using JSON." + } + ], + "defaults": {}, + "response_format": { + "type": "text" + }, + "tools": [] + } } - }, - "stream" : false + } }, - "input_params" : { }, - "messages_history" : [ ] + "placeholder_values": {}, + "messages_history": [] } \ No newline at end of file diff --git a/orchestration/src/test/resources/streamChatCompletion.txt b/orchestration/src/test/resources/streamChatCompletion.txt index 15a7bbd88..bd162db60 100644 --- a/orchestration/src/test/resources/streamChatCompletion.txt +++ b/orchestration/src/test/resources/streamChatCompletion.txt @@ -1,4 +1,4 @@ -data: {"request_id": "5bd87b41-6368-4c18-aaae-47ab82e9475b", "module_results": {"templating": [{"role": "user", "content": "Hello world! Why is this phrase so famous?"}]}, "orchestration_result": {"id": "", "object": "", "created": 0, "model": "", "system_fingerprint": "", "choices": [{"index": 0, "delta": {"role": "", "content": ""}, "finish_reason": ""}]}} -data: {"request_id": "5bd87b41-6368-4c18-aaae-47ab82e9475b", "module_results": {"llm": {"id": "chatcmpl-AYZSQQwWv7ajJsyDBpMG4X01BBJxq", "object": "chat.completion.chunk", "created": 1732802814, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "Sure"}, "finish_reason": ""}]}}, "orchestration_result": {"id": "chatcmpl-AYZSQQwWv7ajJsyDBpMG4X01BBJxq", "object": "chat.completion.chunk", "created": 1732802814, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "Sure"}, "finish_reason": ""}]}} -data: {"request_id": "5bd87b41-6368-4c18-aaae-47ab82e9475b", "module_results": {"llm": {"id": "chatcmpl-AYZSQQwWv7ajJsyDBpMG4X01BBJxq", "object": "chat.completion.chunk", "created": 1732802814, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "!"}, "finish_reason": "stop"}]}}, "orchestration_result": {"id": "chatcmpl-AYZSQQwWv7ajJsyDBpMG4X01BBJxq", "object": "chat.completion.chunk", "created": 1732802814, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "!"}, "finish_reason": "stop"}]}} +data: {"request_id": "5bd87b41-6368-4c18-aaae-47ab82e9475b", "intermediate_results": {"templating": [{"role": "user", "content": "Hello world! Why is this phrase so famous?"}]}, "final_result": {"id": "", "object": "", "created": 0, "model": "", "system_fingerprint": "", "choices": [{"index": 0, "delta": {"role": "", "content": ""}, "finish_reason": ""}]}} +data: {"request_id": "5bd87b41-6368-4c18-aaae-47ab82e9475b", "intermediate_results": {"llm": {"id": "chatcmpl-AYZSQQwWv7ajJsyDBpMG4X01BBJxq", "object": "chat.completion.chunk", "created": 1732802814, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "Sure"}, "finish_reason": ""}]}}, "final_result": {"id": "chatcmpl-AYZSQQwWv7ajJsyDBpMG4X01BBJxq", "object": "chat.completion.chunk", "created": 1732802814, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "Sure"}, "finish_reason": ""}]}} +data: {"request_id": "5bd87b41-6368-4c18-aaae-47ab82e9475b", "intermediate_results": {"llm": {"id": "chatcmpl-AYZSQQwWv7ajJsyDBpMG4X01BBJxq", "object": "chat.completion.chunk", "created": 1732802814, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "!"}, "finish_reason": "stop"}]}}, "final_result": {"id": "chatcmpl-AYZSQQwWv7ajJsyDBpMG4X01BBJxq", "object": "chat.completion.chunk", "created": 1732802814, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "!"}, "finish_reason": "stop"}]}} data: [DONE] diff --git a/orchestration/src/test/resources/streamChatCompletionOutputFilter.txt b/orchestration/src/test/resources/streamChatCompletionOutputFilter.txt index cb473481a..1c8430542 100644 --- a/orchestration/src/test/resources/streamChatCompletionOutputFilter.txt +++ b/orchestration/src/test/resources/streamChatCompletionOutputFilter.txt @@ -1,2 +1,2 @@ -data: {"request_id": "eec90bca-a43e-43fa-864e-1d8962341350", "module_results": {"templating": [{"role": "user", "content": "Create 3 paraphrases of the following text: 'I hate you.'"}]}, "orchestration_result": {"id": "", "object": "", "created": 0, "model": "", "system_fingerprint": "", "choices": [{"index": 0, "delta": {"role": "", "content": ""}, "finish_reason": ""}]}} -data: {"request_id": "eec90bca-a43e-43fa-864e-1d8962341350", "module_results": {"llm": {"id": "chatcmpl-Ab4mSDp5DXFu7hfbs2DkCsVJaM4IP", "object": "chat.completion.chunk", "created": 1733399876, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "1. I can't stand you.\n2. You are detestable to me.\n3. I have a strong aversion towards you."}, "finish_reason": "stop"}]}, "output_filtering": {"message": "Content filtered due to safety violations. Model returned a result violating the safety threshold. Please modify the prompt and try again.", "data": {"original_service_response": {"azure_content_safety": {"content_allowed": false, "original_service_response": {"Hate": 2}, "checked_text": "1. I can't stand you. 2. You are detestable to me. 3. I have a strong aversion towards you."}}}}}, "orchestration_result": {"id": "chatcmpl-Ab4mSDp5DXFu7hfbs2DkCsVJaM4IP", "object": "chat.completion.chunk", "created": 1733399876, "model": "gpt-35-turbo", "system_fingerprint": "fp_808245b034", "choices": [{"index": 0, "delta": {"role": "assistant", "content": ""}, "finish_reason": "content_filter"}]}} +data: {"request_id": "b089074d-5689-4977-9bdc-ce469bbdf476", "intermediate_results": {"templating": [{"role": "system", "content": "Give three paraphrases for the following sentence"}, {"content": "'We shall spill blood tonight', said the operation in-charge.", "role": "user"}]}, "final_result": {"id": "", "object": "", "created": 0, "model": "", "system_fingerprint": "", "choices": [{"index": 0, "delta": {"content": ""}}]}} +data: {"request_id": "b089074d-5689-4977-9bdc-ce469bbdf476", "intermediate_results": {"output_filtering": {"message": "LLM response filtered due to safety violations. Model returned a result violating the safety threshold. Please modify the prompt and try again.", "data": {"choices": [{"index": 0, "azure_content_safety": {"Hate": 0, "SelfHarm": 0, "Sexual": 0, "Violence": 4}}]}}, "llm": {"id": "", "object": "chat.completion.chunk", "created": 1754497351, "model": "gemini-1.5-flash", "choices": [{"index": 0, "delta": {"role": "assistant", "content": "1. \"There will be bloodshed tonight,\" the operation leader announced.\n2. The head of the operation declared, \"Tonight, we will have casualties.\""}, "finish_reason": "stop"}], "usage": {"completion_tokens": 0, "prompt_tokens": 0, "total_tokens": 0}}}, "final_result": {"id": "", "object": "chat.completion.chunk", "created": 1754497351, "model": "gemini-1.5-flash", "choices": [{"index": 0, "delta": {"role": "assistant", "content": ""}, "finish_reason": "content_filter"}], "usage": {"completion_tokens": 0, "prompt_tokens": 0, "total_tokens": 0}}} diff --git a/orchestration/src/test/resources/templateReferenceByIdRequest.json b/orchestration/src/test/resources/templateReferenceByIdRequest.json index 18e3b7d0e..3e42c5de3 100644 --- a/orchestration/src/test/resources/templateReferenceByIdRequest.json +++ b/orchestration/src/test/resources/templateReferenceByIdRequest.json @@ -1,29 +1,30 @@ { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o", - "model_params" : { - "max_tokens" : 50, - "temperature" : 0.1, - "frequency_penalty" : 0, - "presence_penalty" : 0, - "top_p" : 1, - "n" : 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "max_tokens": 50, + "temperature": 0.1, + "frequency_penalty": 0, + "presence_penalty": 0, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template_ref" : { - "id" : "21cb1358-0bf1-4f43-870b-00f14d0f9f16" + "prompt": { + "template_ref": { + "id": "21cb1358-0bf1-4f43-870b-00f14d0f9f16" + } } } - }, - "stream" : false + } }, - "input_params" : { - "input" : "Cloud ERP systems", - "language" : "Italian" + "placeholder_values": { + "input": "Cloud ERP systems", + "language": "Italian" }, - "messages_history" : [ ] + "messages_history": [] } \ No newline at end of file diff --git a/orchestration/src/test/resources/templateReferenceByScenarioRequest.json b/orchestration/src/test/resources/templateReferenceByScenarioRequest.json index e5448f403..7b7bd8e07 100644 --- a/orchestration/src/test/resources/templateReferenceByScenarioRequest.json +++ b/orchestration/src/test/resources/templateReferenceByScenarioRequest.json @@ -1,31 +1,32 @@ { - "orchestration_config" : { - "module_configurations" : { - "llm_module_config" : { - "model_name" : "gpt-4o", - "model_params" : { - "max_tokens" : 50, - "temperature" : 0.1, - "frequency_penalty" : 0, - "presence_penalty" : 0, - "top_p" : 1, - "n" : 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "max_tokens": 50, + "temperature": 0.1, + "frequency_penalty": 0, + "presence_penalty": 0, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version" : "latest" - }, - "templating_module_config" : { - "template_ref" : { - "scenario" : "test", - "name" : "test", - "version" : "0.0.1" + "prompt": { + "template_ref": { + "scenario": "test", + "name": "test", + "version": "0.0.1" + } } } - }, - "stream" : false + } }, - "input_params" : { - "input" : "Cloud ERP systems", - "language" : "Italian" + "placeholder_values": { + "input": "Cloud ERP systems", + "language": "Italian" }, - "messages_history" : [ ] + "messages_history": [] } \ No newline at end of file diff --git a/orchestration/src/test/resources/templatingRequest.json b/orchestration/src/test/resources/templatingRequest.json index 45a90724e..cc7454159 100644 --- a/orchestration/src/test/resources/templatingRequest.json +++ b/orchestration/src/test/resources/templatingRequest.json @@ -1,33 +1,34 @@ { - "orchestration_config": { - "module_configurations": { - "llm_module_config": { - "model_name": "gpt-4o", - "model_params": { - "max_tokens": 50, - "temperature": 0.1, - "frequency_penalty": 0, - "presence_penalty": 0, - "top_p" : 1, - "n" : 1 + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": { + "max_tokens": 50, + "temperature": 0.1, + "frequency_penalty": 0, + "presence_penalty": 0, + "top_p": 1, + "n": 1 + }, + "version": "latest" }, - "model_version": "latest" - }, - "templating_module_config": { - "template": [ - { - "role": "user", - "content": "{{?input}}" - } - ], - "defaults" : { }, - "tools" : [ ] + "prompt": { + "template": [ + { + "role": "user", + "content": "{{?input}}" + } + ], + "defaults": {}, + "tools": [] + } } - }, - "stream": false + } }, - "input_params": { + "placeholder_values": { "input": "Reply with 'Orchestration Service is working!' in German" }, "messages_history": [] -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/toolCallsRequest.json b/orchestration/src/test/resources/toolCallsRequest.json index 6347b3cee..a66dc255a 100644 --- a/orchestration/src/test/resources/toolCallsRequest.json +++ b/orchestration/src/test/resources/toolCallsRequest.json @@ -1,62 +1,63 @@ { - "orchestration_config": { - "module_configurations": { - "llm_module_config": { - "model_name": "gpt-4o", - "model_params": {}, - "model_version": "latest" - }, - "templating_module_config": { - "template": [ - { - "role": "user", - "content": "What is the weather in Potsdam and in Toulouse?" - } - ], - "defaults": {}, - "tools": [ - { - "type": "function", - "function": { - "description": "Get the weather in location", - "name": "getCurrentWeather", - "parameters": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "type": "object", - "properties": { - "arg0": { - "type": "object", - "properties": { - "location": { - "type": "string" + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": {}, + "version": "latest" + }, + "prompt": { + "template": [ + { + "role": "user", + "content": "What is the weather in Potsdam and in Toulouse?" + } + ], + "defaults": {}, + "tools": [ + { + "type": "function", + "function": { + "description": "Get the weather in location", + "name": "getCurrentWeather", + "parameters": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": false, + "type": "object", + "properties": { + "arg0": { + "type": "object", + "properties": { + "location": { + "type": "string" + }, + "unit": { + "type": "string", + "enum": [ + "C", + "F" + ] + } }, - "unit": { - "type": "string", - "enum": [ - "C", - "F" - ] - } - }, - "required": [ - "location", - "unit" - ] - } + "required": [ + "location", + "unit" + ] + } + }, + "required": [ + "arg0" + ] }, - "required": [ - "arg0" - ] - }, - "strict": false + "strict": false + } } - } - ] + ] + } } - }, - "stream": false + } }, - "input_params": {}, + "placeholder_values": {}, "messages_history": [] -} +} \ No newline at end of file diff --git a/orchestration/src/test/resources/toolCallsRequest2.json b/orchestration/src/test/resources/toolCallsRequest2.json index 33882e448..d2c790c50 100644 --- a/orchestration/src/test/resources/toolCallsRequest2.json +++ b/orchestration/src/test/resources/toolCallsRequest2.json @@ -1,93 +1,94 @@ { - "orchestration_config": { - "module_configurations": { - "llm_module_config": { - "model_name": "gpt-4o", - "model_params": {}, - "model_version": "latest" - }, - "templating_module_config": { - "template": [ - { - "role": "user", - "content": "What is the weather in Potsdam and in Toulouse?" - }, - { - "role": "assistant", - "tool_calls": [ - { - "id": "call_LOyP7EVdeqFlGEmVzmPdCVey", - "type": "function", - "function": { - "name": "getCurrentWeather", - "arguments": "{\"arg0\": {\"location\": \"Potsdam\", \"unit\": \"C\"}}" - } - }, - { - "id": "call_bwFjnXCfCO4N3f0bMtFMlNSg", - "type": "function", - "function": { - "name": "getCurrentWeather", - "arguments": "{\"arg0\": {\"location\": \"Toulouse\", \"unit\": \"C\"}}" + "config": { + "modules": { + "prompt_templating": { + "model": { + "name": "gpt-4o", + "params": {}, + "version": "latest" + }, + "prompt": { + "template": [ + { + "role": "user", + "content": "What is the weather in Potsdam and in Toulouse?" + }, + { + "role": "assistant", + "tool_calls": [ + { + "id": "call_LOyP7EVdeqFlGEmVzmPdCVey", + "type": "function", + "function": { + "name": "getCurrentWeather", + "arguments": "{\"arg0\": {\"location\": \"Potsdam\", \"unit\": \"C\"}}" + } + }, + { + "id": "call_bwFjnXCfCO4N3f0bMtFMlNSg", + "type": "function", + "function": { + "name": "getCurrentWeather", + "arguments": "{\"arg0\": {\"location\": \"Toulouse\", \"unit\": \"C\"}}" + } } - } - ] - }, - { - "role": "tool", - "tool_call_id": "call_LOyP7EVdeqFlGEmVzmPdCVey", - "content": "{\"temp\":30.0,\"unit\":\"C\"}" - }, - { - "role": "tool", - "tool_call_id": "call_bwFjnXCfCO4N3f0bMtFMlNSg", - "content": "{\"temp\":30.0,\"unit\":\"C\"}" - } - ], - "defaults": {}, - "tools": [ - { - "type": "function", - "function": { - "description": "Get the weather in location", - "name": "getCurrentWeather", - "parameters": { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "additionalProperties": false, - "type": "object", - "properties": { - "arg0": { - "type": "object", - "properties": { - "location": { - "type": "string" + ] + }, + { + "role": "tool", + "tool_call_id": "call_LOyP7EVdeqFlGEmVzmPdCVey", + "content": "{\"temp\":30.0,\"unit\":\"C\"}" + }, + { + "role": "tool", + "tool_call_id": "call_bwFjnXCfCO4N3f0bMtFMlNSg", + "content": "{\"temp\":30.0,\"unit\":\"C\"}" + } + ], + "defaults": {}, + "tools": [ + { + "type": "function", + "function": { + "description": "Get the weather in location", + "name": "getCurrentWeather", + "parameters": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": false, + "type": "object", + "properties": { + "arg0": { + "type": "object", + "properties": { + "location": { + "type": "string" + }, + "unit": { + "type": "string", + "enum": [ + "C", + "F" + ] + } }, - "unit": { - "type": "string", - "enum": [ - "C", - "F" - ] - } - }, - "required": [ - "location", - "unit" - ] - } + "required": [ + "location", + "unit" + ] + } + }, + "required": [ + "arg0" + ] }, - "required": [ - "arg0" - ] - }, - "strict": false + "strict": false + } } - } - ] + ] + } } - }, - "stream": false + } }, - "input_params": {}, + "placeholder_values": {}, "messages_history": [] -} +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 256270ca4..36445874a 100644 --- a/pom.xml +++ b/pom.xml @@ -684,6 +684,7 @@ https://gitbox.apache.org/repos/asf?p=maven-pmd-plugin.git;a=blob_plain;f=src/ma com/sap/ai/sdk/prompt/registry/model/* com/sap/ai/sdk/prompt/registry/client/* com/sap/ai/sdk/app/**/* + com/sap/ai/sdk/orchestration/JacksonMixins* diff --git a/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OrchestrationTest.java b/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OrchestrationTest.java index 2f89a0c08..379abd476 100644 --- a/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OrchestrationTest.java +++ b/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OrchestrationTest.java @@ -82,7 +82,7 @@ void testStreamChatCompletion() { @Test void testTemplate() { assertThat(service.getConfig().getLlmConfig()).isNotNull(); - val modelName = service.getConfig().getLlmConfig().getModelName(); + val modelName = service.getConfig().getLlmConfig().getName(); val result = service.template("German"); val response = result.getOriginalResponse(); @@ -91,7 +91,7 @@ void testTemplate() { assertThat(((TextItem) result.getAllMessages().get(0).content().items().get(0)).text()) .isEqualTo("Reply with 'Orchestration Service is working!' in German"); assertThat(result.getAllMessages().get(0).role()).isEqualTo("user"); - var llm = response.getModuleResults().getLlm(); + var llm = response.getIntermediateResults().getLlm(); assertThat(llm.getId()).isEmpty(); assertThat(llm.getObject()).isEqualTo("chat.completion"); assertThat(llm.getCreated()).isGreaterThan(1); @@ -106,7 +106,7 @@ void testTemplate() { assertThat(usage.getPromptTokens()).isGreaterThan(1); assertThat(usage.getTotalTokens()).isGreaterThan(1); - var orchestrationResult = (response.getOrchestrationResult()); + var orchestrationResult = (response.getFinalResult()); assertThat(orchestrationResult.getObject()).isEqualTo("chat.completion"); assertThat(orchestrationResult.getCreated()).isGreaterThan(1); assertThat(orchestrationResult.getModel()).isEqualTo(modelName); @@ -132,10 +132,10 @@ void testMessagesHistory() { void testMaskingAnonymization() { var response = service.maskingAnonymization(DPIEntities.PERSON); var result = response.getOriginalResponse(); - var llmChoice = (result.getOrchestrationResult()).getChoices().get(0); + var llmChoice = (result.getFinalResult()).getChoices().get(0); assertThat(llmChoice.getFinishReason()).isEqualTo("stop"); - var maskingResult = result.getModuleResults().getInputMasking(); + var maskingResult = result.getIntermediateResults().getInputMasking(); assertThat(maskingResult.getMessage()).isNotEmpty(); var data = (Map) maskingResult.getData(); var maskedMessage = (String) data.get("masked_template"); @@ -143,7 +143,7 @@ void testMaskingAnonymization() { .describedAs("The masked input should not contain any user names") .doesNotContain("Alice", "Bob"); - assertThat(result.getModuleResults().getOutputUnmasking()).isEmpty(); + assertThat(result.getIntermediateResults().getOutputUnmasking()).isEmpty(); } @SuppressWarnings("unchecked") @@ -151,13 +151,13 @@ void testMaskingAnonymization() { void testMaskingPseudonymization() { var response = service.maskingPseudonymization(DPIEntities.PERSON); var result = response.getOriginalResponse(); - var llmChoice = (result.getOrchestrationResult()).getChoices().get(0); + var llmChoice = (result.getFinalResult()).getChoices().get(0); assertThat(llmChoice.getFinishReason()).isEqualTo("stop"); assertThat(llmChoice.getMessage().getContent()) .describedAs("The final response should contain the original user name") .contains("Mallory"); - var maskingResult = result.getModuleResults().getInputMasking(); + var maskingResult = result.getIntermediateResults().getInputMasking(); assertThat(maskingResult.getMessage()).isNotEmpty(); var data = (Map) maskingResult.getData(); var maskedMessage = (String) data.get("masked_template"); @@ -166,7 +166,7 @@ void testMaskingPseudonymization() { .doesNotContain("Mallory", "Alice", "Bob") .contains("MASKED_PERSON"); - var unmaskingResult = result.getModuleResults().getOutputUnmasking(); + var unmaskingResult = result.getIntermediateResults().getOutputUnmasking(); assertThat(unmaskingResult).isNotEmpty(); assertThat(unmaskingResult.get(0).getMessage().getContent()) .describedAs("The unmasking step should replace the pseudonyms used by the LLM") @@ -180,14 +180,15 @@ void testGrounding() { assertThat(System.getProperty("aicore.landscape")).isNotEqualTo("production"); var response = service.grounding("What does Joule do?", true); var result = response.getOriginalResponse(); - var llmChoice = (result.getOrchestrationResult()).getChoices().get(0); + var llmChoice = (result.getFinalResult()).getChoices().get(0); assertThat(response).isNotNull(); assertThat(llmChoice.getFinishReason()).isEqualTo("stop"); - assertThat(result.getModuleResults().getGrounding()).isNotNull(); - assertThat(result.getModuleResults().getGrounding().getData()).isNotNull(); - assertThat(result.getModuleResults().getGrounding().getMessage()).isEqualTo("grounding result"); + assertThat(result.getIntermediateResults().getGrounding()).isNotNull(); + assertThat(result.getIntermediateResults().getGrounding().getData()).isNotNull(); + assertThat(result.getIntermediateResults().getGrounding().getMessage()) + .isEqualTo("grounding result"); - var maskingResult = result.getModuleResults().getInputMasking(); + var maskingResult = result.getIntermediateResults().getInputMasking(); assertThat(maskingResult.getMessage()).isNotEmpty(); } @@ -198,7 +199,7 @@ void testGroundingSharepoint() { var response = service.groundingSharepoint("What is the secret for the AI SDK e2e test?"); assertThat(response).isNotNull(); var result = response.getOriginalResponse(); - var llmChoice = result.getOrchestrationResult().getChoices().get(0); + var llmChoice = result.getFinalResult().getChoices().get(0); assertThat(llmChoice.getMessage().getContent()).contains("&)UPnkL_izT)&1u%?2Kg*Y.@qFqR@/"); } @@ -206,7 +207,7 @@ void testGroundingSharepoint() { void testCompletionWithResourceGroup() { var response = service.completionWithResourceGroup("ai-sdk-java-e2e", "Hello world!"); var result = response.getOriginalResponse(); - var llmChoice = (result.getOrchestrationResult()).getChoices().get(0); + var llmChoice = (result.getFinalResult()).getChoices().get(0); assertThat(llmChoice.getFinishReason()).isEqualTo("stop"); assertThat(llmChoice.getMessage().getContent()).isNotEmpty(); } @@ -240,7 +241,7 @@ void testInputFilteringLenient() { assertThat(response.getChoice().getFinishReason()).isEqualTo("stop"); assertThat(response.getContent()).isNotEmpty(); - var filterResult = response.getOriginalResponse().getModuleResults().getInputFiltering(); + var filterResult = response.getOriginalResponse().getIntermediateResults().getInputFiltering(); assertThat(filterResult.getMessage()).contains("passed"); // prompt shield is a filter } @@ -272,7 +273,7 @@ void testOutputFilteringLenient() { assertThat(response.getChoice().getFinishReason()).isEqualTo("stop"); assertThat(response.getContent()).isNotEmpty(); - var filterResult = response.getOriginalResponse().getModuleResults().getOutputFiltering(); + var filterResult = response.getOriginalResponse().getIntermediateResults().getOutputFiltering(); assertThat(filterResult.getMessage()).containsPattern("0 of \\d+ choices failed"); } @@ -302,7 +303,7 @@ void testLlamaGuardDisabled() { assertThat(response.getChoice().getFinishReason()).isEqualTo("stop"); assertThat(response.getContent()).isNotEmpty(); - var filterResult = response.getOriginalResponse().getModuleResults().getInputFiltering(); + var filterResult = response.getOriginalResponse().getIntermediateResults().getInputFiltering(); assertThat(filterResult.getMessage()).contains("skipped"); } @@ -313,7 +314,7 @@ void testImageInput() { .imageInput( "https://upload.wikimedia.org/wikipedia/commons/thumb/5/59/SAP_2011_logo.svg/440px-SAP_2011_logo.svg.png") .getOriginalResponse(); - val choices = (result.getOrchestrationResult()).getChoices(); + val choices = (result.getFinalResult()).getChoices(); assertThat(choices.get(0).getMessage().getContent()).isNotEmpty(); } @@ -332,7 +333,7 @@ void testImageInputBase64() { System.out.println("Error fetching or reading the image from URL: " + e.getMessage()); } val result = service.imageInput(dataUrl).getOriginalResponse(); - val choices = (result.getOrchestrationResult()).getChoices(); + val choices = (result.getFinalResult()).getChoices(); assertThat(choices.get(0).getMessage().getContent()).isNotEmpty(); } @@ -343,7 +344,7 @@ void testMultiStringInput() { .multiStringInput( List.of("What is the capital of France?", "What is Chess about?", "What is 2+2?")) .getOriginalResponse(); - val choices = (result.getOrchestrationResult()).getChoices(); + val choices = (result.getFinalResult()).getChoices(); assertThat(choices.get(0).getMessage().getContent()).isNotEmpty(); } @@ -358,7 +359,7 @@ void testResponseFormatJsonSchema() { @Test void testResponseFormatJsonObject() { val result = service.responseFormatJsonObject("apple").getOriginalResponse(); - val choices = (result.getOrchestrationResult()).getChoices(); + val choices = (result.getFinalResult()).getChoices(); assertThat(choices.get(0).getMessage().getContent()).isNotEmpty(); assertThat(choices.get(0).getMessage().getContent()).contains("\"language\":"); assertThat(choices.get(0).getMessage().getContent()).contains("\"translation\":"); @@ -367,14 +368,14 @@ void testResponseFormatJsonObject() { @Test void testResponseFormatText() { val result = service.responseFormatText("apple").getOriginalResponse(); - val choices = (result.getOrchestrationResult()).getChoices(); + val choices = (result.getFinalResult()).getChoices(); assertThat(choices.get(0).getMessage().getContent()).isNotEmpty(); } @Test void testTemplateFromPromptRegistryById() { val result = service.templateFromPromptRegistryById("Cloud ERP systems").getOriginalResponse(); - val choices = (result.getOrchestrationResult()).getChoices(); + val choices = (result.getFinalResult()).getChoices(); assertThat(choices.get(0).getMessage().getContent()).isNotEmpty(); } @@ -382,7 +383,7 @@ void testTemplateFromPromptRegistryById() { void testTemplateFromPromptRegistryByScenario() { val result = service.templateFromPromptRegistryByScenario("Cloud ERP systems").getOriginalResponse(); - val choices = (result.getOrchestrationResult()).getChoices(); + val choices = (result.getFinalResult()).getChoices(); assertThat(choices.get(0).getMessage().getContent()).isNotEmpty(); } @@ -393,7 +394,7 @@ void testLocalPromptTemplate() throws IOException { .localPromptTemplate( Files.readString(Path.of("src/main/resources/promptTemplateExample.yaml"))) .getOriginalResponse(); - val choices = (result.getOrchestrationResult()).getChoices(); + val choices = (result.getFinalResult()).getChoices(); assertThat(choices.get(0).getMessage().getContent()).isNotEmpty(); } @@ -445,9 +446,9 @@ void testTranslation() { assertThat(content).contains("Der", "ist"); GenericModuleResult inputTranslation = - result.getOriginalResponse().getModuleResults().getInputTranslation(); + result.getOriginalResponse().getIntermediateResults().getInputTranslation(); GenericModuleResult outputTranslation = - result.getOriginalResponse().getModuleResults().getOutputTranslation(); + result.getOriginalResponse().getIntermediateResults().getOutputTranslation(); assertThat(inputTranslation).isNotNull(); assertThat(outputTranslation).isNotNull(); assertThat(inputTranslation.getMessage()).isEqualTo("Input to LLM is translated successfully."); diff --git a/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/SpringAiOrchestrationTest.java b/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/SpringAiOrchestrationTest.java index 175e8aaa1..450a10fda 100644 --- a/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/SpringAiOrchestrationTest.java +++ b/sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/SpringAiOrchestrationTest.java @@ -68,7 +68,7 @@ void testInputFilteringStrict() { .isInstanceOf(OrchestrationClientException.class) .hasMessageContaining( "Prompt filtered due to safety violations. Please modify the prompt and try again.") - .hasMessageContaining("400 Bad Request"); + .hasMessageContaining("400 (Bad Request)"); } @Test @@ -84,7 +84,7 @@ void testInputFilteringLenient() { ((OrchestrationSpringChatResponse) response) .getOrchestrationResponse() .getOriginalResponse() - .getModuleResults() + .getIntermediateResults() .getInputFiltering(); assertThat(filterResult.getMessage()).contains("skipped"); } @@ -102,7 +102,7 @@ void testOutputFilteringStrict() { ((OrchestrationSpringChatResponse) response) .getOrchestrationResponse() .getOriginalResponse() - .getModuleResults() + .getIntermediateResults() .getOutputFiltering(); assertThat(filterResult.getMessage()).containsPattern("1 of 1 choices failed"); } @@ -120,7 +120,7 @@ void testOutputFilteringLenient() { ((OrchestrationSpringChatResponse) response) .getOrchestrationResponse() .getOriginalResponse() - .getModuleResults() + .getIntermediateResults() .getOutputFiltering(); assertThat(filterResult.getMessage()).containsPattern("0 of \\d+ choices failed"); }