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 999d3161c..1b6434a05 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 @@ -8,29 +8,18 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.annotations.Beta; import com.sap.ai.sdk.core.AiCoreService; -import com.sap.ai.sdk.core.DeploymentResolutionException; -import com.sap.ai.sdk.core.common.ClientResponseHandler; -import com.sap.ai.sdk.core.common.ClientStreamingHandler; -import com.sap.ai.sdk.core.common.StreamedDelta; import com.sap.ai.sdk.orchestration.model.CompletionPostRequest; import com.sap.ai.sdk.orchestration.model.CompletionPostResponseSynchronous; +import com.sap.ai.sdk.orchestration.model.EmbeddingsPostRequest; +import com.sap.ai.sdk.orchestration.model.EmbeddingsPostResponse; import com.sap.ai.sdk.orchestration.model.ModuleConfigs; import com.sap.ai.sdk.orchestration.model.OrchestrationConfig; -import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor; import com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination; -import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException; -import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException; -import com.sap.cloud.sdk.cloudplatform.connectivity.exception.HttpClientInstantiationException; -import java.io.IOException; import java.util.function.Supplier; import java.util.stream.Stream; import javax.annotation.Nonnull; import lombok.extern.slf4j.Slf4j; import lombok.val; -import org.apache.hc.client5.http.classic.methods.HttpPost; -import org.apache.hc.core5.http.ContentType; -import org.apache.hc.core5.http.io.entity.StringEntity; -import org.apache.hc.core5.http.message.BasicClassicHttpRequest; /** Client to execute requests to the orchestration service. */ @Slf4j @@ -39,12 +28,13 @@ public class OrchestrationClient { static final ObjectMapper JACKSON = getOrchestrationObjectMapper(); - @Nonnull private final Supplier destinationSupplier; + private final OrchestrationHttpExecutor executor; /** Default constructor. */ public OrchestrationClient() { - destinationSupplier = + final Supplier destinationSupplier = () -> new AiCoreService().getInferenceDestination().forScenario(DEFAULT_SCENARIO); + this.executor = new OrchestrationHttpExecutor(destinationSupplier); } /** @@ -64,7 +54,7 @@ public OrchestrationClient() { */ @Beta public OrchestrationClient(@Nonnull final HttpDestination destination) { - this.destinationSupplier = () -> destination; + this.executor = new OrchestrationHttpExecutor(() -> destination); } /** @@ -150,15 +140,7 @@ private static void throwOnContentFilter(@Nonnull final OrchestrationChatComplet @Nonnull public CompletionPostResponseSynchronous executeRequest( @Nonnull final CompletionPostRequest request) throws OrchestrationClientException { - final String jsonRequest; - try { - jsonRequest = JACKSON.writeValueAsString(request); - log.debug("Serialized request into JSON payload: {}", jsonRequest); - } catch (final JsonProcessingException e) { - throw new OrchestrationClientException("Failed to serialize request parameters", e); - } - - return executeRequest(jsonRequest); + return executor.execute("/completion", request, CompletionPostResponseSynchronous.class); } /** @@ -199,38 +181,8 @@ public OrchestrationChatResponse executeRequestFromJsonModuleConfig( } requestJson.set("orchestration_config", moduleConfigJson); - final String body; - try { - body = JACKSON.writeValueAsString(requestJson); - } catch (JsonProcessingException e) { - throw new OrchestrationClientException("Failed to serialize request to JSON", e); - } - return new OrchestrationChatResponse(executeRequest(body)); - } - - @Nonnull - CompletionPostResponseSynchronous executeRequest(@Nonnull final String request) { - val postRequest = new HttpPost("/completion"); - postRequest.setEntity(new StringEntity(request, ContentType.APPLICATION_JSON)); - - try { - val destination = destinationSupplier.get(); - log.debug("Using destination {} to connect to orchestration service", destination); - val client = ApacheHttpClient5Accessor.getHttpClient(destination); - val handler = - new ClientResponseHandler<>( - CompletionPostResponseSynchronous.class, - OrchestrationError.class, - OrchestrationClientException::new) - .objectMapper(JACKSON); - return client.execute(postRequest, handler); - } catch (DeploymentResolutionException - | DestinationAccessException - | DestinationNotFoundException - | HttpClientInstantiationException - | IOException e) { - throw new OrchestrationClientException("Failed to execute request", e); - } + return new OrchestrationChatResponse( + executor.execute("/completion", requestJson, CompletionPostResponseSynchronous.class)); } /** @@ -245,42 +197,20 @@ CompletionPostResponseSynchronous executeRequest(@Nonnull final String request) public Stream streamChatCompletionDeltas( @Nonnull final CompletionPostRequest request) throws OrchestrationClientException { request.getOrchestrationConfig().setStream(true); - return executeStream("/completion", request, OrchestrationChatCompletionDelta.class); - } - - @Nonnull - private Stream executeStream( - @Nonnull final String path, - @Nonnull final Object payload, - @Nonnull final Class deltaType) { - final var request = new HttpPost(path); - serializeAndSetHttpEntity(request, payload); - return streamRequest(request, deltaType); - } - - private static void serializeAndSetHttpEntity( - @Nonnull final BasicClassicHttpRequest request, @Nonnull final Object payload) { - try { - final var json = JACKSON.writeValueAsString(payload); - request.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); - } catch (final JsonProcessingException e) { - throw new OrchestrationClientException("Failed to serialize request parameters", e); - } + return executor.stream(request); } + /** + * Generate embeddings for the given request. + * + * @param request the request containing the input text and other parameters. + * @return the response containing the embeddings. + * @throws OrchestrationClientException if the request fails + * @since 1.9.0 + */ @Nonnull - private Stream streamRequest( - final BasicClassicHttpRequest request, @Nonnull final Class deltaType) { - try { - val destination = destinationSupplier.get(); - log.debug("Using destination {} to connect to orchestration service", destination); - val client = ApacheHttpClient5Accessor.getHttpClient(destination); - return new ClientStreamingHandler<>( - deltaType, OrchestrationError.class, OrchestrationClientException::new) - .objectMapper(JACKSON) - .handleStreamingResponse(client.executeOpen(null, request, null)); - } catch (final IOException e) { - throw new OrchestrationClientException("Request to the Orchestration service failed", e); - } + public EmbeddingsPostResponse embed(@Nonnull final EmbeddingsPostRequest request) + throws OrchestrationClientException { + return executor.execute("/v2/embeddings", request, EmbeddingsPostResponse.class); } } 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 new file mode 100644 index 000000000..b5c51bfc8 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationHttpExecutor.java @@ -0,0 +1,98 @@ +package com.sap.ai.sdk.orchestration; + +import static com.sap.ai.sdk.orchestration.OrchestrationJacksonConfiguration.getOrchestrationObjectMapper; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sap.ai.sdk.core.DeploymentResolutionException; +import com.sap.ai.sdk.core.common.ClientResponseHandler; +import com.sap.ai.sdk.core.common.ClientStreamingHandler; +import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor; +import com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination; +import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException; +import com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationNotFoundException; +import com.sap.cloud.sdk.cloudplatform.connectivity.exception.HttpClientInstantiationException; +import java.io.IOException; +import java.util.function.Supplier; +import java.util.stream.Stream; +import javax.annotation.Nonnull; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.io.entity.StringEntity; + +@Slf4j +class OrchestrationHttpExecutor { + private final Supplier destinationSupplier; + private static final ObjectMapper JACKSON = getOrchestrationObjectMapper(); + + OrchestrationHttpExecutor(@Nonnull final Supplier destinationSupplier) + throws OrchestrationClientException { + this.destinationSupplier = destinationSupplier; + } + + @Nonnull + T execute( + @Nonnull final String path, + @Nonnull final Object payload, + @Nonnull final Class responseType) { + try { + val json = JACKSON.writeValueAsString(payload); + log.debug("Serialized request into JSON payload: {}", json); + val request = new HttpPost(path); + request.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); + + val client = getHttpClient(); + + val handler = + new ClientResponseHandler<>( + responseType, OrchestrationError.class, OrchestrationClientException::new) + .objectMapper(JACKSON); + return client.execute(request, handler); + + } catch (JsonProcessingException e) { + throw new OrchestrationClientException("Failed to serialize request payload for " + path, e); + } catch (DeploymentResolutionException + | DestinationAccessException + | DestinationNotFoundException + | HttpClientInstantiationException + | IOException e) { + throw new OrchestrationClientException( + "Request to Orchestration service failed for " + path, e); + } + } + + @Nonnull + Stream stream(@Nonnull final Object payload) { + try { + + val json = JACKSON.writeValueAsString(payload); + val request = new HttpPost("/completion"); + request.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON)); + val client = getHttpClient(); + + return new ClientStreamingHandler<>( + OrchestrationChatCompletionDelta.class, + OrchestrationError.class, + OrchestrationClientException::new) + .objectMapper(JACKSON) + .handleStreamingResponse(client.executeOpen(null, request, null)); + + } catch (JsonProcessingException e) { + throw new OrchestrationClientException( + "Failed to serialize payload for streaming request", e); + } catch (IOException e) { + throw new OrchestrationClientException( + "Streaming request to the Orchestration service failed", e); + } + } + + @Nonnull + private HttpClient getHttpClient() { + val destination = destinationSupplier.get(); + log.debug("Using destination {} to connect to orchestration service", destination); + return ApacheHttpClient5Accessor.getHttpClient(destination); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Embedding.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Embedding.java new file mode 100644 index 000000000..712a16b91 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/Embedding.java @@ -0,0 +1,52 @@ +/* + * 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 java.math.BigDecimal; +import java.util.List; +import javax.annotation.Nonnull; + +/** Embedding */ +public interface Embedding { + /** Helper class to create a String that implements {@link Embedding}. */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue @Nonnull String value) + implements Embedding {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerString create(@Nonnull final String val) { + return new InnerString(val); + } + + /** Helper class to create a list of BigDecimal that implements {@link Embedding}. */ + record InnerBigDecimals( + @com.fasterxml.jackson.annotation.JsonValue @Nonnull List values) + implements Embedding {} + + /** + * Creator to enable deserialization of a list of BigDecimal. + * + * @param val the value to use + * @return a new instance of {@link InnerBigDecimals}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerBigDecimals create(@Nonnull final List val) { + return new InnerBigDecimals(val); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingResult.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingResult.java new file mode 100644 index 000000000..12dfde521 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingResult.java @@ -0,0 +1,338 @@ +/* + * 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.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +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; + +/** Represents an embedding vector returned by embedding endpoint. */ +// CHECKSTYLE:OFF +public class EmbeddingResult +// CHECKSTYLE:ON +{ + /** The object type, which is always \"embedding\". */ + public enum ObjectEnum { + /** The EMBEDDING option of this EmbeddingResult */ + EMBEDDING("embedding"), + + /** The UNKNOWN_DEFAULT_OPEN_API option of this EmbeddingResult */ + UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api"); + + private String value; + + ObjectEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type EmbeddingResult + */ + @JsonCreator + @Nonnull + public static ObjectEnum fromValue(@Nonnull final String value) { + for (ObjectEnum b : ObjectEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return UNKNOWN_DEFAULT_OPEN_API; + } + } + + @JsonProperty("object") + private ObjectEnum _object; + + @JsonProperty("embedding") + private Embedding embedding; + + @JsonProperty("index") + private Integer index; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingResult. */ + protected EmbeddingResult() {} + + /** + * Set the _object of this {@link EmbeddingResult} instance and return the same instance. + * + * @param _object The object type, which is always \"embedding\". + * @return The same instance of this {@link EmbeddingResult} class + */ + @Nonnull + public EmbeddingResult _object(@Nonnull final ObjectEnum _object) { + this._object = _object; + return this; + } + + /** + * The object type, which is always \"embedding\". + * + * @return _object The _object of this {@link EmbeddingResult} instance. + */ + @Nonnull + public ObjectEnum getObject() { + return _object; + } + + /** + * Set the _object of this {@link EmbeddingResult} instance. + * + * @param _object The object type, which is always \"embedding\". + */ + public void setObject(@Nonnull final ObjectEnum _object) { + this._object = _object; + } + + /** + * Set the embedding of this {@link EmbeddingResult} instance and return the same instance. + * + * @param embedding The embedding of this {@link EmbeddingResult} + * @return The same instance of this {@link EmbeddingResult} class + */ + @Nonnull + public EmbeddingResult embedding(@Nonnull final Embedding embedding) { + this.embedding = embedding; + return this; + } + + /** + * Get embedding + * + * @return embedding The embedding of this {@link EmbeddingResult} instance. + */ + @Nonnull + public Embedding getEmbedding() { + return embedding; + } + + /** + * Set the embedding of this {@link EmbeddingResult} instance. + * + * @param embedding The embedding of this {@link EmbeddingResult} + */ + public void setEmbedding(@Nonnull final Embedding embedding) { + this.embedding = embedding; + } + + /** + * Set the index of this {@link EmbeddingResult} instance and return the same instance. + * + * @param index The index of the embedding in the list of embeddings. + * @return The same instance of this {@link EmbeddingResult} class + */ + @Nonnull + public EmbeddingResult index(@Nonnull final Integer index) { + this.index = index; + return this; + } + + /** + * The index of the embedding in the list of embeddings. + * + * @return index The index of this {@link EmbeddingResult} instance. + */ + @Nonnull + public Integer getIndex() { + return index; + } + + /** + * Set the index of this {@link EmbeddingResult} instance. + * + * @param index The index of the embedding in the list of embeddings. + */ + public void setIndex(@Nonnull final Integer index) { + this.index = index; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingResult}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingResult} 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("EmbeddingResult has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingResult} instance including unrecognized + * properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (_object != null) declaredFields.put("_object", _object); + if (embedding != null) declaredFields.put("embedding", embedding); + if (index != null) declaredFields.put("index", index); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingResult} 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 EmbeddingResult embeddingResult = (EmbeddingResult) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingResult.cloudSdkCustomFields) + && Objects.equals(this._object, embeddingResult._object) + && Objects.equals(this.embedding, embeddingResult.embedding) + && Objects.equals(this.index, embeddingResult.index); + } + + @Override + public int hashCode() { + return Objects.hash(_object, embedding, index, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingResult {\n"); + sb.append(" _object: ").append(toIndentedString(_object)).append("\n"); + sb.append(" embedding: ").append(toIndentedString(embedding)).append("\n"); + sb.append(" index: ").append(toIndentedString(index)).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 EmbeddingResult} + * instance with all required arguments. + */ + public static Builder create() { + return (_object) -> + (embedding) -> + (index) -> new EmbeddingResult()._object(_object).embedding(embedding).index(index); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the _object of this {@link EmbeddingResult} instance. + * + * @param _object The object type, which is always \"embedding\". + * @return The EmbeddingResult builder. + */ + Builder1 _object(@Nonnull final ObjectEnum _object); + } + + /** Builder helper class. */ + public interface Builder1 { + /** + * Set the embedding of this {@link EmbeddingResult} instance. + * + * @param embedding The embedding of this {@link EmbeddingResult} + * @return The EmbeddingResult builder. + */ + Builder2 embedding(@Nonnull final Embedding embedding); + } + + /** Builder helper class. */ + public interface Builder2 { + /** + * Set the index of this {@link EmbeddingResult} instance. + * + * @param index The index of the embedding in the list of embeddings. + * @return The EmbeddingResult instance. + */ + EmbeddingResult index(@Nonnull final Integer index); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsInput.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsInput.java new file mode 100644 index 000000000..7a8007616 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsInput.java @@ -0,0 +1,283 @@ +/* + * 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.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +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; + +/** EmbeddingsInput */ +// CHECKSTYLE:OFF +public class EmbeddingsInput +// CHECKSTYLE:ON +{ + @JsonProperty("text") + private EmbeddingsInputText text; + + /** Gets or Sets type */ + public enum TypeEnum { + /** The TEXT option of this EmbeddingsInput */ + TEXT("text"), + + /** The DOCUMENT option of this EmbeddingsInput */ + DOCUMENT("document"), + + /** The QUERY option of this EmbeddingsInput */ + QUERY("query"), + + /** The UNKNOWN_DEFAULT_OPEN_API option of this EmbeddingsInput */ + UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api"); + + private String value; + + TypeEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type EmbeddingsInput + */ + @JsonCreator + @Nonnull + public static TypeEnum fromValue(@Nonnull final String value) { + for (TypeEnum b : TypeEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return UNKNOWN_DEFAULT_OPEN_API; + } + } + + @JsonProperty("type") + private TypeEnum type; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsInput. */ + protected EmbeddingsInput() {} + + /** + * Set the text of this {@link EmbeddingsInput} instance and return the same instance. + * + * @param text The text of this {@link EmbeddingsInput} + * @return The same instance of this {@link EmbeddingsInput} class + */ + @Nonnull + public EmbeddingsInput text(@Nonnull final EmbeddingsInputText text) { + this.text = text; + return this; + } + + /** + * Get text + * + * @return text The text of this {@link EmbeddingsInput} instance. + */ + @Nonnull + public EmbeddingsInputText getText() { + return text; + } + + /** + * Set the text of this {@link EmbeddingsInput} instance. + * + * @param text The text of this {@link EmbeddingsInput} + */ + public void setText(@Nonnull final EmbeddingsInputText text) { + this.text = text; + } + + /** + * Set the type of this {@link EmbeddingsInput} instance and return the same instance. + * + * @param type The type of this {@link EmbeddingsInput} + * @return The same instance of this {@link EmbeddingsInput} class + */ + @Nonnull + public EmbeddingsInput type(@Nullable final TypeEnum type) { + this.type = type; + return this; + } + + /** + * Get type + * + * @return type The type of this {@link EmbeddingsInput} instance. + */ + @Nonnull + public TypeEnum getType() { + return type; + } + + /** + * Set the type of this {@link EmbeddingsInput} instance. + * + * @param type The type of this {@link EmbeddingsInput} + */ + public void setType(@Nullable final TypeEnum type) { + this.type = type; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsInput}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsInput} 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("EmbeddingsInput has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsInput} instance including unrecognized + * properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (text != null) declaredFields.put("text", text); + if (type != null) declaredFields.put("type", type); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsInput} 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 EmbeddingsInput embeddingsInput = (EmbeddingsInput) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsInput.cloudSdkCustomFields) + && Objects.equals(this.text, embeddingsInput.text) + && Objects.equals(this.type, embeddingsInput.type); + } + + @Override + public int hashCode() { + return Objects.hash(text, type, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsInput {\n"); + sb.append(" text: ").append(toIndentedString(text)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).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 EmbeddingsInput} + * instance with all required arguments. + */ + public static Builder create() { + return (text) -> new EmbeddingsInput().text(text); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the text of this {@link EmbeddingsInput} instance. + * + * @param text The text of this {@link EmbeddingsInput} + * @return The EmbeddingsInput instance. + */ + EmbeddingsInput text(@Nonnull final EmbeddingsInputText text); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsInputText.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsInputText.java new file mode 100644 index 000000000..3e726dfbd --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsInputText.java @@ -0,0 +1,50 @@ +/* + * 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 java.util.List; +import javax.annotation.Nonnull; + +/** Text input for which embeddings need to be generated */ +public interface EmbeddingsInputText { + /** Helper class to create a String that implements {@link EmbeddingsInputText}. */ + record InnerString(@com.fasterxml.jackson.annotation.JsonValue @Nonnull String value) + implements EmbeddingsInputText {} + + /** + * Creator to enable deserialization of a String. + * + * @param val the value to use + * @return a new instance of {@link InnerString}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerString create(@Nonnull final String val) { + return new InnerString(val); + } + + /** Helper class to create a list of String that implements {@link EmbeddingsInputText}. */ + record InnerStrings(@com.fasterxml.jackson.annotation.JsonValue @Nonnull List values) + implements EmbeddingsInputText {} + + /** + * Creator to enable deserialization of a list of String. + * + * @param val the value to use + * @return a new instance of {@link InnerStrings}. + */ + @com.fasterxml.jackson.annotation.JsonCreator + @Nonnull + static InnerStrings create(@Nonnull final List val) { + return new InnerStrings(val); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelConfig.java new file mode 100644 index 000000000..c246b72aa --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelConfig.java @@ -0,0 +1,185 @@ +/* + * 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; + +/** EmbeddingsModelConfig */ +// CHECKSTYLE:OFF +public class EmbeddingsModelConfig +// CHECKSTYLE:ON +{ + @JsonProperty("model") + private EmbeddingsModelDetails model; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsModelConfig. */ + protected EmbeddingsModelConfig() {} + + /** + * Set the model of this {@link EmbeddingsModelConfig} instance and return the same instance. + * + * @param model The model of this {@link EmbeddingsModelConfig} + * @return The same instance of this {@link EmbeddingsModelConfig} class + */ + @Nonnull + public EmbeddingsModelConfig model(@Nonnull final EmbeddingsModelDetails model) { + this.model = model; + return this; + } + + /** + * Get model + * + * @return model The model of this {@link EmbeddingsModelConfig} instance. + */ + @Nonnull + public EmbeddingsModelDetails getModel() { + return model; + } + + /** + * Set the model of this {@link EmbeddingsModelConfig} instance. + * + * @param model The model of this {@link EmbeddingsModelConfig} + */ + public void setModel(@Nonnull final EmbeddingsModelDetails model) { + this.model = model; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsModelConfig}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsModelConfig} 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( + "EmbeddingsModelConfig has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsModelConfig} instance including + * unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (model != null) declaredFields.put("model", model); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsModelConfig} 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 EmbeddingsModelConfig embeddingsModelConfig = (EmbeddingsModelConfig) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsModelConfig.cloudSdkCustomFields) + && Objects.equals(this.model, embeddingsModelConfig.model); + } + + @Override + public int hashCode() { + return Objects.hash(model, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsModelConfig {\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 EmbeddingsModelConfig} + * instance with all required arguments. + */ + public static Builder create() { + return (model) -> new EmbeddingsModelConfig().model(model); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the model of this {@link EmbeddingsModelConfig} instance. + * + * @param model The model of this {@link EmbeddingsModelConfig} + * @return The EmbeddingsModelConfig instance. + */ + EmbeddingsModelConfig model(@Nonnull final EmbeddingsModelDetails model); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelDetails.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelDetails.java new file mode 100644 index 000000000..1907156c8 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelDetails.java @@ -0,0 +1,259 @@ +/* + * 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; + +/** EmbeddingsModelDetails */ +// CHECKSTYLE:OFF +public class EmbeddingsModelDetails +// CHECKSTYLE:ON +{ + @JsonProperty("name") + private String name; + + @JsonProperty("version") + private String version = "latest"; + + @JsonProperty("params") + private EmbeddingsModelParams params; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsModelDetails. */ + protected EmbeddingsModelDetails() {} + + /** + * Set the name of this {@link EmbeddingsModelDetails} instance and return the same instance. + * + * @param name The name of this {@link EmbeddingsModelDetails} + * @return The same instance of this {@link EmbeddingsModelDetails} class + */ + @Nonnull + public EmbeddingsModelDetails name(@Nonnull final String name) { + this.name = name; + return this; + } + + /** + * Get name + * + * @return name The name of this {@link EmbeddingsModelDetails} instance. + */ + @Nonnull + public String getName() { + return name; + } + + /** + * Set the name of this {@link EmbeddingsModelDetails} instance. + * + * @param name The name of this {@link EmbeddingsModelDetails} + */ + public void setName(@Nonnull final String name) { + this.name = name; + } + + /** + * Set the version of this {@link EmbeddingsModelDetails} instance and return the same instance. + * + * @param version The version of this {@link EmbeddingsModelDetails} + * @return The same instance of this {@link EmbeddingsModelDetails} class + */ + @Nonnull + public EmbeddingsModelDetails version(@Nullable final String version) { + this.version = version; + return this; + } + + /** + * Get version + * + * @return version The version of this {@link EmbeddingsModelDetails} instance. + */ + @Nonnull + public String getVersion() { + return version; + } + + /** + * Set the version of this {@link EmbeddingsModelDetails} instance. + * + * @param version The version of this {@link EmbeddingsModelDetails} + */ + public void setVersion(@Nullable final String version) { + this.version = version; + } + + /** + * Set the params of this {@link EmbeddingsModelDetails} instance and return the same instance. + * + * @param params The params of this {@link EmbeddingsModelDetails} + * @return The same instance of this {@link EmbeddingsModelDetails} class + */ + @Nonnull + public EmbeddingsModelDetails params(@Nullable final EmbeddingsModelParams params) { + this.params = params; + return this; + } + + /** + * Get params + * + * @return params The params of this {@link EmbeddingsModelDetails} instance. + */ + @Nonnull + public EmbeddingsModelParams getParams() { + return params; + } + + /** + * Set the params of this {@link EmbeddingsModelDetails} instance. + * + * @param params The params of this {@link EmbeddingsModelDetails} + */ + public void setParams(@Nullable final EmbeddingsModelParams params) { + this.params = params; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsModelDetails}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsModelDetails} 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( + "EmbeddingsModelDetails has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsModelDetails} 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 EmbeddingsModelDetails} 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 EmbeddingsModelDetails embeddingsModelDetails = (EmbeddingsModelDetails) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsModelDetails.cloudSdkCustomFields) + && Objects.equals(this.name, embeddingsModelDetails.name) + && Objects.equals(this.version, embeddingsModelDetails.version) + && Objects.equals(this.params, embeddingsModelDetails.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 EmbeddingsModelDetails {\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 EmbeddingsModelDetails} + * instance with all required arguments. + */ + public static Builder create() { + return (name) -> new EmbeddingsModelDetails().name(name); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the name of this {@link EmbeddingsModelDetails} instance. + * + * @param name The name of this {@link EmbeddingsModelDetails} + * @return The EmbeddingsModelDetails instance. + */ + EmbeddingsModelDetails name(@Nonnull final String name); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelParams.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelParams.java new file mode 100644 index 000000000..9bc236003 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModelParams.java @@ -0,0 +1,313 @@ +/* + * 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.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +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; + +/** + * Additional parameters for generating input's embeddings. Default values are used for + * mandatory parameters. + */ +// CHECKSTYLE:OFF +public class EmbeddingsModelParams +// CHECKSTYLE:ON +{ + @JsonProperty("dimensions") + private Integer dimensions; + + /** OpenAI's spec allows for 'float' and 'base64' encoding formats. */ + public enum EncodingFormatEnum { + /** The FLOAT option of this EmbeddingsModelParams */ + FLOAT("float"), + + /** The BASE64 option of this EmbeddingsModelParams */ + BASE64("base64"), + + /** The BINARY option of this EmbeddingsModelParams */ + BINARY("binary"), + + /** The UNKNOWN_DEFAULT_OPEN_API option of this EmbeddingsModelParams */ + UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api"); + + private String value; + + EncodingFormatEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type EmbeddingsModelParams + */ + @JsonCreator + @Nonnull + public static EncodingFormatEnum fromValue(@Nonnull final String value) { + for (EncodingFormatEnum b : EncodingFormatEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return UNKNOWN_DEFAULT_OPEN_API; + } + } + + @JsonProperty("encoding_format") + private EncodingFormatEnum encodingFormat; + + @JsonProperty("normalize") + private Boolean normalize; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsModelParams. */ + protected EmbeddingsModelParams() {} + + /** + * Set the dimensions of this {@link EmbeddingsModelParams} instance and return the same instance. + * + * @param dimensions The number of dimensions the resulting output embeddings should have. + * @return The same instance of this {@link EmbeddingsModelParams} class + */ + @Nonnull + public EmbeddingsModelParams dimensions(@Nullable final Integer dimensions) { + this.dimensions = dimensions; + return this; + } + + /** + * The number of dimensions the resulting output embeddings should have. + * + * @return dimensions The dimensions of this {@link EmbeddingsModelParams} instance. + */ + @Nonnull + public Integer getDimensions() { + return dimensions; + } + + /** + * Set the dimensions of this {@link EmbeddingsModelParams} instance. + * + * @param dimensions The number of dimensions the resulting output embeddings should have. + */ + public void setDimensions(@Nullable final Integer dimensions) { + this.dimensions = dimensions; + } + + /** + * Set the encodingFormat of this {@link EmbeddingsModelParams} instance and return the same + * instance. + * + * @param encodingFormat OpenAI's spec allows for 'float' and 'base64' + * encoding formats. + * @return The same instance of this {@link EmbeddingsModelParams} class + */ + @Nonnull + public EmbeddingsModelParams encodingFormat(@Nullable final EncodingFormatEnum encodingFormat) { + this.encodingFormat = encodingFormat; + return this; + } + + /** + * OpenAI's spec allows for 'float' and 'base64' encoding formats. + * + * @return encodingFormat The encodingFormat of this {@link EmbeddingsModelParams} instance. + */ + @Nonnull + public EncodingFormatEnum getEncodingFormat() { + return encodingFormat; + } + + /** + * Set the encodingFormat of this {@link EmbeddingsModelParams} instance. + * + * @param encodingFormat OpenAI's spec allows for 'float' and 'base64' + * encoding formats. + */ + public void setEncodingFormat(@Nullable final EncodingFormatEnum encodingFormat) { + this.encodingFormat = encodingFormat; + } + + /** + * Set the normalize of this {@link EmbeddingsModelParams} instance and return the same instance. + * + * @param normalize The normalize of this {@link EmbeddingsModelParams} + * @return The same instance of this {@link EmbeddingsModelParams} class + */ + @Nonnull + public EmbeddingsModelParams normalize(@Nullable final Boolean normalize) { + this.normalize = normalize; + return this; + } + + /** + * Get normalize + * + * @return normalize The normalize of this {@link EmbeddingsModelParams} instance. + */ + @Nonnull + public Boolean isNormalize() { + return normalize; + } + + /** + * Set the normalize of this {@link EmbeddingsModelParams} instance. + * + * @param normalize The normalize of this {@link EmbeddingsModelParams} + */ + public void setNormalize(@Nullable final Boolean normalize) { + this.normalize = normalize; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsModelParams}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsModelParams} 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( + "EmbeddingsModelParams has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsModelParams} instance including + * unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (dimensions != null) declaredFields.put("dimensions", dimensions); + if (encodingFormat != null) declaredFields.put("encodingFormat", encodingFormat); + if (normalize != null) declaredFields.put("normalize", normalize); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsModelParams} 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 EmbeddingsModelParams embeddingsModelParams = (EmbeddingsModelParams) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsModelParams.cloudSdkCustomFields) + && Objects.equals(this.dimensions, embeddingsModelParams.dimensions) + && Objects.equals(this.encodingFormat, embeddingsModelParams.encodingFormat) + && Objects.equals(this.normalize, embeddingsModelParams.normalize); + } + + @Override + public int hashCode() { + return Objects.hash(dimensions, encodingFormat, normalize, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsModelParams {\n"); + sb.append(" dimensions: ").append(toIndentedString(dimensions)).append("\n"); + sb.append(" encodingFormat: ").append(toIndentedString(encodingFormat)).append("\n"); + sb.append(" normalize: ").append(toIndentedString(normalize)).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 EmbeddingsModelParams} instance. No arguments are required. */ + public static EmbeddingsModelParams create() { + return new EmbeddingsModelParams(); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModuleConfigs.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModuleConfigs.java new file mode 100644 index 000000000..2de5063ab --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsModuleConfigs.java @@ -0,0 +1,223 @@ +/* + * 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; + +/** EmbeddingsModuleConfigs */ +// CHECKSTYLE:OFF +public class EmbeddingsModuleConfigs +// CHECKSTYLE:ON +{ + @JsonProperty("embeddings") + private EmbeddingsModelConfig embeddings; + + @JsonProperty("masking") + private MaskingModuleConfig masking; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsModuleConfigs. */ + protected EmbeddingsModuleConfigs() {} + + /** + * Set the embeddings of this {@link EmbeddingsModuleConfigs} instance and return the same + * instance. + * + * @param embeddings The embeddings of this {@link EmbeddingsModuleConfigs} + * @return The same instance of this {@link EmbeddingsModuleConfigs} class + */ + @Nonnull + public EmbeddingsModuleConfigs embeddings(@Nonnull final EmbeddingsModelConfig embeddings) { + this.embeddings = embeddings; + return this; + } + + /** + * Get embeddings + * + * @return embeddings The embeddings of this {@link EmbeddingsModuleConfigs} instance. + */ + @Nonnull + public EmbeddingsModelConfig getEmbeddings() { + return embeddings; + } + + /** + * Set the embeddings of this {@link EmbeddingsModuleConfigs} instance. + * + * @param embeddings The embeddings of this {@link EmbeddingsModuleConfigs} + */ + public void setEmbeddings(@Nonnull final EmbeddingsModelConfig embeddings) { + this.embeddings = embeddings; + } + + /** + * Set the masking of this {@link EmbeddingsModuleConfigs} instance and return the same instance. + * + * @param masking The masking of this {@link EmbeddingsModuleConfigs} + * @return The same instance of this {@link EmbeddingsModuleConfigs} class + */ + @Nonnull + public EmbeddingsModuleConfigs masking(@Nullable final MaskingModuleConfig masking) { + this.masking = masking; + return this; + } + + /** + * Get masking + * + * @return masking The masking of this {@link EmbeddingsModuleConfigs} instance. + */ + @Nonnull + public MaskingModuleConfig getMasking() { + return masking; + } + + /** + * Set the masking of this {@link EmbeddingsModuleConfigs} instance. + * + * @param masking The masking of this {@link EmbeddingsModuleConfigs} + */ + public void setMasking(@Nullable final MaskingModuleConfig masking) { + this.masking = masking; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsModuleConfigs}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsModuleConfigs} 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( + "EmbeddingsModuleConfigs has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsModuleConfigs} instance including + * unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (embeddings != null) declaredFields.put("embeddings", embeddings); + if (masking != null) declaredFields.put("masking", masking); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsModuleConfigs} 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 EmbeddingsModuleConfigs embeddingsModuleConfigs = (EmbeddingsModuleConfigs) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsModuleConfigs.cloudSdkCustomFields) + && Objects.equals(this.embeddings, embeddingsModuleConfigs.embeddings) + && Objects.equals(this.masking, embeddingsModuleConfigs.masking); + } + + @Override + public int hashCode() { + return Objects.hash(embeddings, masking, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsModuleConfigs {\n"); + sb.append(" embeddings: ").append(toIndentedString(embeddings)).append("\n"); + sb.append(" masking: ").append(toIndentedString(masking)).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 + * EmbeddingsModuleConfigs} instance with all required arguments. + */ + public static Builder create() { + return (embeddings) -> new EmbeddingsModuleConfigs().embeddings(embeddings); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the embeddings of this {@link EmbeddingsModuleConfigs} instance. + * + * @param embeddings The embeddings of this {@link EmbeddingsModuleConfigs} + * @return The EmbeddingsModuleConfigs instance. + */ + EmbeddingsModuleConfigs embeddings(@Nonnull final EmbeddingsModelConfig embeddings); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsOrchestrationConfig.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsOrchestrationConfig.java new file mode 100644 index 000000000..622f65162 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsOrchestrationConfig.java @@ -0,0 +1,192 @@ +/* + * 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; + +/** EmbeddingsOrchestrationConfig */ +// CHECKSTYLE:OFF +public class EmbeddingsOrchestrationConfig +// CHECKSTYLE:ON +{ + @JsonProperty("module_configs") + private EmbeddingsModuleConfigs moduleConfigs; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsOrchestrationConfig. */ + protected EmbeddingsOrchestrationConfig() {} + + /** + * Set the moduleConfigs of this {@link EmbeddingsOrchestrationConfig} instance and return the + * same instance. + * + * @param moduleConfigs The moduleConfigs of this {@link EmbeddingsOrchestrationConfig} + * @return The same instance of this {@link EmbeddingsOrchestrationConfig} class + */ + @Nonnull + public EmbeddingsOrchestrationConfig moduleConfigs( + @Nonnull final EmbeddingsModuleConfigs moduleConfigs) { + this.moduleConfigs = moduleConfigs; + return this; + } + + /** + * Get moduleConfigs + * + * @return moduleConfigs The moduleConfigs of this {@link EmbeddingsOrchestrationConfig} instance. + */ + @Nonnull + public EmbeddingsModuleConfigs getModuleConfigs() { + return moduleConfigs; + } + + /** + * Set the moduleConfigs of this {@link EmbeddingsOrchestrationConfig} instance. + * + * @param moduleConfigs The moduleConfigs of this {@link EmbeddingsOrchestrationConfig} + */ + public void setModuleConfigs(@Nonnull final EmbeddingsModuleConfigs moduleConfigs) { + this.moduleConfigs = moduleConfigs; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsOrchestrationConfig}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsOrchestrationConfig} + * 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( + "EmbeddingsOrchestrationConfig has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsOrchestrationConfig} instance + * including unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (moduleConfigs != null) declaredFields.put("moduleConfigs", moduleConfigs); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsOrchestrationConfig} 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 EmbeddingsOrchestrationConfig embeddingsOrchestrationConfig = + (EmbeddingsOrchestrationConfig) o; + return Objects.equals( + this.cloudSdkCustomFields, embeddingsOrchestrationConfig.cloudSdkCustomFields) + && Objects.equals(this.moduleConfigs, embeddingsOrchestrationConfig.moduleConfigs); + } + + @Override + public int hashCode() { + return Objects.hash(moduleConfigs, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsOrchestrationConfig {\n"); + sb.append(" moduleConfigs: ").append(toIndentedString(moduleConfigs)).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 + * EmbeddingsOrchestrationConfig} instance with all required arguments. + */ + public static Builder create() { + return (moduleConfigs) -> new EmbeddingsOrchestrationConfig().moduleConfigs(moduleConfigs); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the moduleConfigs of this {@link EmbeddingsOrchestrationConfig} instance. + * + * @param moduleConfigs The moduleConfigs of this {@link EmbeddingsOrchestrationConfig} + * @return The EmbeddingsOrchestrationConfig instance. + */ + EmbeddingsOrchestrationConfig moduleConfigs( + @Nonnull final EmbeddingsModuleConfigs moduleConfigs); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsPostRequest.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsPostRequest.java new file mode 100644 index 000000000..850108088 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsPostRequest.java @@ -0,0 +1,241 @@ +/* + * 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; + +/** EmbeddingsPostRequest */ +// CHECKSTYLE:OFF +public class EmbeddingsPostRequest +// CHECKSTYLE:ON +{ + @JsonProperty("orchestration_config") + private EmbeddingsOrchestrationConfig orchestrationConfig; + + @JsonProperty("input") + private EmbeddingsInput input; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsPostRequest. */ + protected EmbeddingsPostRequest() {} + + /** + * Set the orchestrationConfig of this {@link EmbeddingsPostRequest} instance and return the same + * instance. + * + * @param orchestrationConfig The orchestrationConfig of this {@link EmbeddingsPostRequest} + * @return The same instance of this {@link EmbeddingsPostRequest} class + */ + @Nonnull + public EmbeddingsPostRequest orchestrationConfig( + @Nonnull final EmbeddingsOrchestrationConfig orchestrationConfig) { + this.orchestrationConfig = orchestrationConfig; + return this; + } + + /** + * Get orchestrationConfig + * + * @return orchestrationConfig The orchestrationConfig of this {@link EmbeddingsPostRequest} + * instance. + */ + @Nonnull + public EmbeddingsOrchestrationConfig getOrchestrationConfig() { + return orchestrationConfig; + } + + /** + * Set the orchestrationConfig of this {@link EmbeddingsPostRequest} instance. + * + * @param orchestrationConfig The orchestrationConfig of this {@link EmbeddingsPostRequest} + */ + public void setOrchestrationConfig( + @Nonnull final EmbeddingsOrchestrationConfig orchestrationConfig) { + this.orchestrationConfig = orchestrationConfig; + } + + /** + * Set the input of this {@link EmbeddingsPostRequest} instance and return the same instance. + * + * @param input The input of this {@link EmbeddingsPostRequest} + * @return The same instance of this {@link EmbeddingsPostRequest} class + */ + @Nonnull + public EmbeddingsPostRequest input(@Nonnull final EmbeddingsInput input) { + this.input = input; + return this; + } + + /** + * Get input + * + * @return input The input of this {@link EmbeddingsPostRequest} instance. + */ + @Nonnull + public EmbeddingsInput getInput() { + return input; + } + + /** + * Set the input of this {@link EmbeddingsPostRequest} instance. + * + * @param input The input of this {@link EmbeddingsPostRequest} + */ + public void setInput(@Nonnull final EmbeddingsInput input) { + this.input = input; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsPostRequest}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsPostRequest} 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( + "EmbeddingsPostRequest has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsPostRequest} instance including + * unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (orchestrationConfig != null) declaredFields.put("orchestrationConfig", orchestrationConfig); + if (input != null) declaredFields.put("input", input); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsPostRequest} 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 EmbeddingsPostRequest embeddingsPostRequest = (EmbeddingsPostRequest) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsPostRequest.cloudSdkCustomFields) + && Objects.equals(this.orchestrationConfig, embeddingsPostRequest.orchestrationConfig) + && Objects.equals(this.input, embeddingsPostRequest.input); + } + + @Override + public int hashCode() { + return Objects.hash(orchestrationConfig, input, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsPostRequest {\n"); + sb.append(" orchestrationConfig: ") + .append(toIndentedString(orchestrationConfig)) + .append("\n"); + sb.append(" input: ").append(toIndentedString(input)).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 EmbeddingsPostRequest} + * instance with all required arguments. + */ + public static Builder create() { + return (orchestrationConfig) -> + (input) -> + new EmbeddingsPostRequest().orchestrationConfig(orchestrationConfig).input(input); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the orchestrationConfig of this {@link EmbeddingsPostRequest} instance. + * + * @param orchestrationConfig The orchestrationConfig of this {@link EmbeddingsPostRequest} + * @return The EmbeddingsPostRequest builder. + */ + Builder1 orchestrationConfig(@Nonnull final EmbeddingsOrchestrationConfig orchestrationConfig); + } + + /** Builder helper class. */ + public interface Builder1 { + /** + * Set the input of this {@link EmbeddingsPostRequest} instance. + * + * @param input The input of this {@link EmbeddingsPostRequest} + * @return The EmbeddingsPostRequest instance. + */ + EmbeddingsPostRequest input(@Nonnull final EmbeddingsInput input); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsPostResponse.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsPostResponse.java new file mode 100644 index 000000000..7ef0372d2 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsPostResponse.java @@ -0,0 +1,265 @@ +/* + * 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; + +/** EmbeddingsPostResponse */ +// CHECKSTYLE:OFF +public class EmbeddingsPostResponse +// CHECKSTYLE:ON +{ + @JsonProperty("request_id") + private String requestId; + + @JsonProperty("module_results") + private ModuleResultsBase moduleResults; + + @JsonProperty("orchestration_result") + private EmbeddingsResponse orchestrationResult; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsPostResponse. */ + protected EmbeddingsPostResponse() {} + + /** + * Set the requestId of this {@link EmbeddingsPostResponse} instance and return the same instance. + * + * @param requestId The requestId of this {@link EmbeddingsPostResponse} + * @return The same instance of this {@link EmbeddingsPostResponse} class + */ + @Nonnull + public EmbeddingsPostResponse requestId(@Nonnull final String requestId) { + this.requestId = requestId; + return this; + } + + /** + * Get requestId + * + * @return requestId The requestId of this {@link EmbeddingsPostResponse} instance. + */ + @Nonnull + public String getRequestId() { + return requestId; + } + + /** + * Set the requestId of this {@link EmbeddingsPostResponse} instance. + * + * @param requestId The requestId of this {@link EmbeddingsPostResponse} + */ + public void setRequestId(@Nonnull final String requestId) { + this.requestId = requestId; + } + + /** + * Set the moduleResults of this {@link EmbeddingsPostResponse} instance and return the same + * instance. + * + * @param moduleResults The moduleResults of this {@link EmbeddingsPostResponse} + * @return The same instance of this {@link EmbeddingsPostResponse} class + */ + @Nonnull + public EmbeddingsPostResponse moduleResults(@Nullable final ModuleResultsBase moduleResults) { + this.moduleResults = moduleResults; + return this; + } + + /** + * Get moduleResults + * + * @return moduleResults The moduleResults of this {@link EmbeddingsPostResponse} instance. + */ + @Nonnull + public ModuleResultsBase getModuleResults() { + return moduleResults; + } + + /** + * Set the moduleResults of this {@link EmbeddingsPostResponse} instance. + * + * @param moduleResults The moduleResults of this {@link EmbeddingsPostResponse} + */ + public void setModuleResults(@Nullable final ModuleResultsBase moduleResults) { + this.moduleResults = moduleResults; + } + + /** + * Set the orchestrationResult of this {@link EmbeddingsPostResponse} instance and return the same + * instance. + * + * @param orchestrationResult The orchestrationResult of this {@link EmbeddingsPostResponse} + * @return The same instance of this {@link EmbeddingsPostResponse} class + */ + @Nonnull + public EmbeddingsPostResponse orchestrationResult( + @Nullable final EmbeddingsResponse orchestrationResult) { + this.orchestrationResult = orchestrationResult; + return this; + } + + /** + * Get orchestrationResult + * + * @return orchestrationResult The orchestrationResult of this {@link EmbeddingsPostResponse} + * instance. + */ + @Nonnull + public EmbeddingsResponse getOrchestrationResult() { + return orchestrationResult; + } + + /** + * Set the orchestrationResult of this {@link EmbeddingsPostResponse} instance. + * + * @param orchestrationResult The orchestrationResult of this {@link EmbeddingsPostResponse} + */ + public void setOrchestrationResult(@Nullable final EmbeddingsResponse orchestrationResult) { + this.orchestrationResult = orchestrationResult; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsPostResponse}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsPostResponse} 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( + "EmbeddingsPostResponse has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsPostResponse} 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 (moduleResults != null) declaredFields.put("moduleResults", moduleResults); + if (orchestrationResult != null) declaredFields.put("orchestrationResult", orchestrationResult); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsPostResponse} 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 EmbeddingsPostResponse embeddingsPostResponse = (EmbeddingsPostResponse) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsPostResponse.cloudSdkCustomFields) + && Objects.equals(this.requestId, embeddingsPostResponse.requestId) + && Objects.equals(this.moduleResults, embeddingsPostResponse.moduleResults) + && Objects.equals(this.orchestrationResult, embeddingsPostResponse.orchestrationResult); + } + + @Override + public int hashCode() { + return Objects.hash(requestId, moduleResults, orchestrationResult, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsPostResponse {\n"); + sb.append(" requestId: ").append(toIndentedString(requestId)).append("\n"); + sb.append(" moduleResults: ").append(toIndentedString(moduleResults)).append("\n"); + sb.append(" orchestrationResult: ") + .append(toIndentedString(orchestrationResult)) + .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 EmbeddingsPostResponse} + * instance with all required arguments. + */ + public static Builder create() { + return (requestId) -> new EmbeddingsPostResponse().requestId(requestId); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the requestId of this {@link EmbeddingsPostResponse} instance. + * + * @param requestId The requestId of this {@link EmbeddingsPostResponse} + * @return The EmbeddingsPostResponse instance. + */ + EmbeddingsPostResponse requestId(@Nonnull final String requestId); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsResponse.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsResponse.java new file mode 100644 index 000000000..7cd0f3140 --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsResponse.java @@ -0,0 +1,416 @@ +/* + * 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.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +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; + +/** EmbeddingsResponse */ +// CHECKSTYLE:OFF +public class EmbeddingsResponse +// CHECKSTYLE:ON +{ + /** The object type, which is always \"list\". */ + public enum ObjectEnum { + /** The LIST option of this EmbeddingsResponse */ + LIST("list"), + + /** The UNKNOWN_DEFAULT_OPEN_API option of this EmbeddingsResponse */ + UNKNOWN_DEFAULT_OPEN_API("unknown_default_open_api"); + + private String value; + + ObjectEnum(String value) { + this.value = value; + } + + /** + * Get the value of the enum + * + * @return The enum value + */ + @JsonValue + @Nonnull + public String getValue() { + return value; + } + + /** + * Get the String value of the enum value. + * + * @return The enum value as String + */ + @Override + @Nonnull + public String toString() { + return String.valueOf(value); + } + + /** + * Get the enum value from a String value + * + * @param value The String value + * @return The enum value of type EmbeddingsResponse + */ + @JsonCreator + @Nonnull + public static ObjectEnum fromValue(@Nonnull final String value) { + for (ObjectEnum b : ObjectEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + return UNKNOWN_DEFAULT_OPEN_API; + } + } + + @JsonProperty("object") + private ObjectEnum _object; + + @JsonProperty("data") + private List data = new ArrayList<>(); + + @JsonProperty("model") + private String model; + + @JsonProperty("usage") + private EmbeddingsUsage usage; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsResponse. */ + protected EmbeddingsResponse() {} + + /** + * Set the _object of this {@link EmbeddingsResponse} instance and return the same instance. + * + * @param _object The object type, which is always \"list\". + * @return The same instance of this {@link EmbeddingsResponse} class + */ + @Nonnull + public EmbeddingsResponse _object(@Nonnull final ObjectEnum _object) { + this._object = _object; + return this; + } + + /** + * The object type, which is always \"list\". + * + * @return _object The _object of this {@link EmbeddingsResponse} instance. + */ + @Nonnull + public ObjectEnum getObject() { + return _object; + } + + /** + * Set the _object of this {@link EmbeddingsResponse} instance. + * + * @param _object The object type, which is always \"list\". + */ + public void setObject(@Nonnull final ObjectEnum _object) { + this._object = _object; + } + + /** + * Set the data of this {@link EmbeddingsResponse} instance and return the same instance. + * + * @param data The list of embeddings generated by the model. + * @return The same instance of this {@link EmbeddingsResponse} class + */ + @Nonnull + public EmbeddingsResponse data(@Nonnull final List data) { + this.data = data; + return this; + } + + /** + * Add one data instance to this {@link EmbeddingsResponse}. + * + * @param dataItem The data that should be added + * @return The same instance of type {@link EmbeddingsResponse} + */ + @Nonnull + public EmbeddingsResponse addDataItem(@Nonnull final EmbeddingResult dataItem) { + if (this.data == null) { + this.data = new ArrayList<>(); + } + this.data.add(dataItem); + return this; + } + + /** + * The list of embeddings generated by the model. + * + * @return data The data of this {@link EmbeddingsResponse} instance. + */ + @Nonnull + public List getData() { + return data; + } + + /** + * Set the data of this {@link EmbeddingsResponse} instance. + * + * @param data The list of embeddings generated by the model. + */ + public void setData(@Nonnull final List data) { + this.data = data; + } + + /** + * Set the model of this {@link EmbeddingsResponse} instance and return the same instance. + * + * @param model The name of the model used to generate the embedding. + * @return The same instance of this {@link EmbeddingsResponse} class + */ + @Nonnull + public EmbeddingsResponse model(@Nonnull final String model) { + this.model = model; + return this; + } + + /** + * The name of the model used to generate the embedding. + * + * @return model The model of this {@link EmbeddingsResponse} instance. + */ + @Nonnull + public String getModel() { + return model; + } + + /** + * Set the model of this {@link EmbeddingsResponse} instance. + * + * @param model The name of the model used to generate the embedding. + */ + public void setModel(@Nonnull final String model) { + this.model = model; + } + + /** + * Set the usage of this {@link EmbeddingsResponse} instance and return the same instance. + * + * @param usage The usage of this {@link EmbeddingsResponse} + * @return The same instance of this {@link EmbeddingsResponse} class + */ + @Nonnull + public EmbeddingsResponse usage(@Nonnull final EmbeddingsUsage usage) { + this.usage = usage; + return this; + } + + /** + * Get usage + * + * @return usage The usage of this {@link EmbeddingsResponse} instance. + */ + @Nonnull + public EmbeddingsUsage getUsage() { + return usage; + } + + /** + * Set the usage of this {@link EmbeddingsResponse} instance. + * + * @param usage The usage of this {@link EmbeddingsResponse} + */ + public void setUsage(@Nonnull final EmbeddingsUsage usage) { + this.usage = usage; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsResponse}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsResponse} 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("EmbeddingsResponse has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsResponse} instance including + * unrecognized properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (_object != null) declaredFields.put("_object", _object); + if (data != null) declaredFields.put("data", data); + if (model != null) declaredFields.put("model", model); + if (usage != null) declaredFields.put("usage", usage); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsResponse} 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 EmbeddingsResponse embeddingsResponse = (EmbeddingsResponse) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsResponse.cloudSdkCustomFields) + && Objects.equals(this._object, embeddingsResponse._object) + && Objects.equals(this.data, embeddingsResponse.data) + && Objects.equals(this.model, embeddingsResponse.model) + && Objects.equals(this.usage, embeddingsResponse.usage); + } + + @Override + public int hashCode() { + return Objects.hash(_object, data, model, usage, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsResponse {\n"); + sb.append(" _object: ").append(toIndentedString(_object)).append("\n"); + sb.append(" data: ").append(toIndentedString(data)).append("\n"); + sb.append(" model: ").append(toIndentedString(model)).append("\n"); + sb.append(" usage: ").append(toIndentedString(usage)).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 EmbeddingsResponse} + * instance with all required arguments. + */ + public static Builder create() { + return (_object) -> + (data) -> + (model) -> + (usage) -> + new EmbeddingsResponse()._object(_object).data(data).model(model).usage(usage); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the _object of this {@link EmbeddingsResponse} instance. + * + * @param _object The object type, which is always \"list\". + * @return The EmbeddingsResponse builder. + */ + Builder1 _object(@Nonnull final ObjectEnum _object); + } + + /** Builder helper class. */ + public interface Builder1 { + /** + * Set the data of this {@link EmbeddingsResponse} instance. + * + * @param data The list of embeddings generated by the model. + * @return The EmbeddingsResponse builder. + */ + Builder2 data(@Nonnull final List data); + + /** + * Set the data of this {@link EmbeddingsResponse} instance. + * + * @param data The list of embeddings generated by the model. + * @return The EmbeddingsResponse builder. + */ + default Builder2 data(@Nonnull final EmbeddingResult... data) { + return data(Arrays.asList(data)); + } + } + + /** Builder helper class. */ + public interface Builder2 { + /** + * Set the model of this {@link EmbeddingsResponse} instance. + * + * @param model The name of the model used to generate the embedding. + * @return The EmbeddingsResponse builder. + */ + Builder3 model(@Nonnull final String model); + } + + /** Builder helper class. */ + public interface Builder3 { + /** + * Set the usage of this {@link EmbeddingsResponse} instance. + * + * @param usage The usage of this {@link EmbeddingsResponse} + * @return The EmbeddingsResponse instance. + */ + EmbeddingsResponse usage(@Nonnull final EmbeddingsUsage usage); + } +} diff --git a/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsUsage.java b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsUsage.java new file mode 100644 index 000000000..1dee2f56b --- /dev/null +++ b/orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/EmbeddingsUsage.java @@ -0,0 +1,233 @@ +/* + * 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; + +/** The usage information for the request. */ +// CHECKSTYLE:OFF +public class EmbeddingsUsage +// CHECKSTYLE:ON +{ + @JsonProperty("prompt_tokens") + private Integer promptTokens; + + @JsonProperty("total_tokens") + private Integer totalTokens; + + @JsonAnySetter @JsonAnyGetter + private final Map cloudSdkCustomFields = new LinkedHashMap<>(); + + /** Default constructor for EmbeddingsUsage. */ + protected EmbeddingsUsage() {} + + /** + * Set the promptTokens of this {@link EmbeddingsUsage} instance and return the same instance. + * + * @param promptTokens The number of tokens used by the prompt. + * @return The same instance of this {@link EmbeddingsUsage} class + */ + @Nonnull + public EmbeddingsUsage promptTokens(@Nonnull final Integer promptTokens) { + this.promptTokens = promptTokens; + return this; + } + + /** + * The number of tokens used by the prompt. + * + * @return promptTokens The promptTokens of this {@link EmbeddingsUsage} instance. + */ + @Nonnull + public Integer getPromptTokens() { + return promptTokens; + } + + /** + * Set the promptTokens of this {@link EmbeddingsUsage} instance. + * + * @param promptTokens The number of tokens used by the prompt. + */ + public void setPromptTokens(@Nonnull final Integer promptTokens) { + this.promptTokens = promptTokens; + } + + /** + * Set the totalTokens of this {@link EmbeddingsUsage} instance and return the same instance. + * + * @param totalTokens The total number of tokens used by the request. + * @return The same instance of this {@link EmbeddingsUsage} class + */ + @Nonnull + public EmbeddingsUsage totalTokens(@Nonnull final Integer totalTokens) { + this.totalTokens = totalTokens; + return this; + } + + /** + * The total number of tokens used by the request. + * + * @return totalTokens The totalTokens of this {@link EmbeddingsUsage} instance. + */ + @Nonnull + public Integer getTotalTokens() { + return totalTokens; + } + + /** + * Set the totalTokens of this {@link EmbeddingsUsage} instance. + * + * @param totalTokens The total number of tokens used by the request. + */ + public void setTotalTokens(@Nonnull final Integer totalTokens) { + this.totalTokens = totalTokens; + } + + /** + * Get the names of the unrecognizable properties of the {@link EmbeddingsUsage}. + * + * @return The set of properties names + */ + @JsonIgnore + @Nonnull + public Set getCustomFieldNames() { + return cloudSdkCustomFields.keySet(); + } + + /** + * Get the value of an unrecognizable property of this {@link EmbeddingsUsage} 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("EmbeddingsUsage has no field with name '" + name + "'."); + } + return cloudSdkCustomFields.get(name); + } + + /** + * Get the value of all properties of this {@link EmbeddingsUsage} instance including unrecognized + * properties. + * + * @return The map of all properties + */ + @JsonIgnore + @Nonnull + public Map toMap() { + final Map declaredFields = new LinkedHashMap<>(cloudSdkCustomFields); + if (promptTokens != null) declaredFields.put("promptTokens", promptTokens); + if (totalTokens != null) declaredFields.put("totalTokens", totalTokens); + return declaredFields; + } + + /** + * Set an unrecognizable property of this {@link EmbeddingsUsage} 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 EmbeddingsUsage embeddingsUsage = (EmbeddingsUsage) o; + return Objects.equals(this.cloudSdkCustomFields, embeddingsUsage.cloudSdkCustomFields) + && Objects.equals(this.promptTokens, embeddingsUsage.promptTokens) + && Objects.equals(this.totalTokens, embeddingsUsage.totalTokens); + } + + @Override + public int hashCode() { + return Objects.hash(promptTokens, totalTokens, cloudSdkCustomFields); + } + + @Override + @Nonnull + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class EmbeddingsUsage {\n"); + sb.append(" promptTokens: ").append(toIndentedString(promptTokens)).append("\n"); + sb.append(" totalTokens: ").append(toIndentedString(totalTokens)).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 EmbeddingsUsage} + * instance with all required arguments. + */ + public static Builder create() { + return (promptTokens) -> + (totalTokens) -> new EmbeddingsUsage().promptTokens(promptTokens).totalTokens(totalTokens); + } + + /** Builder helper class. */ + public interface Builder { + /** + * Set the promptTokens of this {@link EmbeddingsUsage} instance. + * + * @param promptTokens The number of tokens used by the prompt. + * @return The EmbeddingsUsage builder. + */ + Builder1 promptTokens(@Nonnull final Integer promptTokens); + } + + /** Builder helper class. */ + public interface Builder1 { + /** + * Set the totalTokens of this {@link EmbeddingsUsage} instance. + * + * @param totalTokens The total number of tokens used by the request. + * @return The EmbeddingsUsage instance. + */ + EmbeddingsUsage totalTokens(@Nonnull final Integer totalTokens); + } +} diff --git a/orchestration/src/main/resources/spec/orchestration.yaml b/orchestration/src/main/resources/spec/orchestration.yaml index 533e3d7d5..4bddce366 100644 --- a/orchestration/src/main/resources/spec/orchestration.yaml +++ b/orchestration/src/main/resources/spec/orchestration.yaml @@ -9,15 +9,12 @@ info: name: SAP AI Core version: 0.0.1 -servers: - - url: "/v1" - tags: - name: OrchestrationCompletion description: Run an orchestrated completion inference request paths: - /completion: + /v1/completion: post: tags: - OrchestrationCompletion @@ -45,6 +42,34 @@ paths: default: $ref: "#/components/responses/CommonError" + /v2/embeddings: + post: + tags: + - OrchestrationEmbeddings + summary: orchestrated embeddings inference + description: > + Generate embeddings for input strings. + operationId: orchestration.v1.endpoints.create_embeddings + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/EmbeddingsPostRequest" + responses: + "200": + description: "Successful response" + content: + application/json: + schema: + $ref: "#/components/schemas/EmbeddingsPostResponse" + "400": + $ref: "#/components/responses/BadRequest" + default: + $ref: "#/components/responses/CommonError" + + + components: schemas: CompletionPostRequest: @@ -66,6 +91,182 @@ components: allOf: - $ref: "#/components/schemas/ChatMessages" description: History of chat messages. Can be used to provide system and assistant messages to set the context of the conversation. Will be merged with the template message + + # Embedings Schemas + EmbeddingsPostRequest: + type: object + additionalProperties: false + required: + - input + - orchestration_config + properties: + orchestration_config: + $ref: "#/components/schemas/EmbeddingsOrchestrationConfig" + input: + $ref: "#/components/schemas/EmbeddingsInput" + EmbeddingsOrchestrationConfig: + type: object + required: + - module_configs + additionalProperties: false + properties: + module_configs: + $ref: "#/components/schemas/EmbeddingsModuleConfigs" + EmbeddingsInput: + type: object + required: + - text + additionalProperties: false + properties: + text: + $ref: "#/components/schemas/EmbeddingsInputText" + type: + type: string + enum: ["text", "document", "query"] + EmbeddingsInputText: + oneOf: + - type: string + description: The string that will be turned into an embedding. + example: Hello World! + - type: array + description: The array of strings that will be turned into an embedding. + minItems: 1 + items: + type: string + minLength: 1 + example: "['Hello', 'World', '!']" + description: Text input for which embeddings need to be generated + example: ["This is an input string.", "This is another input string."] + EmbeddingsModuleConfigs: + type: object + required: + - embeddings + additionalProperties: false + properties: + embeddings: + $ref: "#/components/schemas/EmbeddingsModelConfig" + masking: + $ref: "#/components/schemas/MaskingModuleConfig" + EmbeddingsModelConfig: + type: object + required: + - model + additionalProperties: false + properties: + model: + $ref: "#/components/schemas/EmbeddingsModelDetails" + EmbeddingsModelDetails: + type: object + required: + - name + additionalProperties: false + properties: + name: + type: string + version: + type: string + default: "latest" + params: + $ref: "#/components/schemas/EmbeddingsModelParams" + EmbeddingsModelParams: + type: object + description: Additional parameters for generating input's embeddings. Default values are used for mandatory parameters. + additionalProperties: true + properties: + dimensions: + type: integer + description: > + The number of dimensions the resulting output embeddings should have. + encoding_format: + type: string + enum: [float, base64, binary] + description: > + OpenAI's spec allows for 'float' and 'base64' encoding formats. + normalize: + type: boolean + + EmbeddingsPostResponse: + type: object + additionalProperties: false + required: + - request_id + properties: + request_id: + type: string + module_results: + $ref: "#/components/schemas/ModuleResultsBase" + description: Results of each module of /embeddings endpoint(e.g. input masking). + orchestration_result: + $ref: "#/components/schemas/EmbeddingsResponse" + description: The response from request to embedding model following OpenAI specification. + EmbeddingsResponse: + type: object + additionalProperties: false + required: + - object + - data + - model + - usage + properties: + object: + type: string + description: The object type, which is always "list". + enum: + - list + data: + type: array + description: The list of embeddings generated by the model. + items: + $ref: "#/components/schemas/EmbeddingResult" + model: + type: string + description: The name of the model used to generate the embedding. + usage: + $ref: "#/components/schemas/EmbeddingsUsage" + EmbeddingsUsage: + type: object + description: The usage information for the request. + additionalProperties: false + required: + - prompt_tokens + - total_tokens + properties: + prompt_tokens: + type: integer + description: The number of tokens used by the prompt. + total_tokens: + type: integer + description: The total number of tokens used by the request. + EmbeddingResult: + type: object + description: | + Represents an embedding vector returned by embedding endpoint. + additionalProperties: false + required: + - object + - embedding + - index + properties: + object: + type: string + description: The object type, which is always "embedding". + enum: + - embedding + embedding: + $ref: "#/components/schemas/Embedding" + index: + type: integer + description: The index of the embedding in the list of embeddings. + Embedding: + oneOf: + - type: array + items: + type: number + description: "An array of numbers representing the embedding." + - type: string + description: "A single base64 string representing the embedding." + + # Chat Completion Schemas ChatMessages: type: array items: 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 d6d41a3e1..8b7ab32bb 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 @@ -12,6 +12,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; import static com.github.tomakehurst.wiremock.client.WireMock.serverError; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static com.sap.ai.sdk.orchestration.AzureFilterThreshold.ALLOW_SAFE; @@ -38,15 +39,29 @@ import com.github.tomakehurst.wiremock.junit5.WireMockTest; import com.github.tomakehurst.wiremock.stubbing.Scenario; import com.sap.ai.sdk.orchestration.model.ChatDelta; +import com.sap.ai.sdk.orchestration.model.DPIConfig; import com.sap.ai.sdk.orchestration.model.DPIEntities; +import com.sap.ai.sdk.orchestration.model.DPIStandardEntity; import com.sap.ai.sdk.orchestration.model.DataRepositoryType; import com.sap.ai.sdk.orchestration.model.DocumentGroundingFilter; +import com.sap.ai.sdk.orchestration.model.Embedding; +import com.sap.ai.sdk.orchestration.model.EmbeddingsInput; +import com.sap.ai.sdk.orchestration.model.EmbeddingsInputText; +import com.sap.ai.sdk.orchestration.model.EmbeddingsModelConfig; +import com.sap.ai.sdk.orchestration.model.EmbeddingsModelDetails; +import com.sap.ai.sdk.orchestration.model.EmbeddingsModelParams; +import com.sap.ai.sdk.orchestration.model.EmbeddingsModuleConfigs; +import com.sap.ai.sdk.orchestration.model.EmbeddingsOrchestrationConfig; +import com.sap.ai.sdk.orchestration.model.EmbeddingsPostRequest; +import com.sap.ai.sdk.orchestration.model.EmbeddingsPostResponse; +import com.sap.ai.sdk.orchestration.model.EmbeddingsResponse; import com.sap.ai.sdk.orchestration.model.GenericModuleResult; 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.KeyValueListPair; import com.sap.ai.sdk.orchestration.model.LlamaGuard38b; +import com.sap.ai.sdk.orchestration.model.MaskingModuleConfig; import com.sap.ai.sdk.orchestration.model.ResponseFormatText; import com.sap.ai.sdk.orchestration.model.SearchDocumentKeyValueListPair; import com.sap.ai.sdk.orchestration.model.SearchSelectOptionEnum; @@ -58,6 +73,7 @@ import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; import java.io.IOException; import java.io.InputStream; +import java.math.BigDecimal; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -1054,4 +1070,155 @@ void testGetAllMessages() { assertThat(messageListTools.get(1)).isInstanceOf(AssistantMessage.class); assertThat(messageListTools.get(2)).isInstanceOf(ToolMessage.class); } + + @Test + void testEmbeddingCallWithMasking() { + + stubFor( + post(urlEqualTo("/v2/embeddings")) + .willReturn( + aResponse() + .withStatus(200) + .withBody( + """ + { + "request_id": "2ee98443-e1ee-9503-b800-e38b5b80fe45", + "module_results": { + "input_masking": { + "message": "Embedding input is masked successfully.", + "data": { + "masked_input": "['Hello', 'MASKED_PERSON', '!']" + } + } + }, + "orchestration_result": { + "object": "list", + "data": [ + { + "object": "embedding", + "embedding": [ + 0.43988228, + -0.82985526, + -0.15936942, + 0.041005015, + 0.30127057 + ], + "index": 0 + } + ], + "model": "text-embedding-3-large", + "usage": { + "prompt_tokens": 10, + "total_tokens": 10 + } + } + } + """))); + + val dpiConfig = + DPIConfig.create() + .type(DPIConfig.TypeEnum.SAP_DATA_PRIVACY_INTEGRATION) + .method(DPIConfig.MethodEnum.ANONYMIZATION) + .entities(List.of(DPIStandardEntity.create().type(DPIEntities.PERSON))); + val maskingConfig = MaskingModuleConfig.create().maskingProviders(List.of(dpiConfig)); + + val modelParams = + EmbeddingsModelParams.create() + .encodingFormat(EmbeddingsModelParams.EncodingFormatEnum.FLOAT) + .dimensions(5) + .normalize(false); + val modelConfig = + EmbeddingsModelConfig.create() + .model( + EmbeddingsModelDetails.create().name("text-embedding-3-large").params(modelParams)); + + val orchestrationConfig = + EmbeddingsOrchestrationConfig.create() + .moduleConfigs( + EmbeddingsModuleConfigs.create().embeddings(modelConfig).masking(maskingConfig)); + + val inputText = + EmbeddingsInput.create().text(EmbeddingsInputText.create("['Hello', 'Müller', '!']")); + + val request = + EmbeddingsPostRequest.create().orchestrationConfig(orchestrationConfig).input(inputText); + + EmbeddingsPostResponse response = client.embed(request); + + assertThat(response).isNotNull(); + assertThat(response.getRequestId()).isEqualTo("2ee98443-e1ee-9503-b800-e38b5b80fe45"); + + val orchestrationResult = response.getOrchestrationResult(); + assertThat(orchestrationResult).isNotNull(); + assertThat(orchestrationResult.getObject()).isEqualTo(EmbeddingsResponse.ObjectEnum.LIST); + assertThat(orchestrationResult.getModel()).isEqualTo("text-embedding-3-large"); + + val data = orchestrationResult.getData(); + assertThat(data).isNotEmpty(); + assertThat(data.get(0).getEmbedding()) + .isEqualTo( + Embedding.create( + List.of( + BigDecimal.valueOf(0.43988228), + BigDecimal.valueOf(-0.82985526), + BigDecimal.valueOf(-0.15936942), + BigDecimal.valueOf(0.041005015), + BigDecimal.valueOf(0.30127057)))); + assertThat(data.get(0).getIndex()).isZero(); + + val usage = orchestrationResult.getUsage(); + assertThat(usage).isNotNull(); + assertThat(usage.getPromptTokens()).isEqualTo(10); + assertThat(usage.getTotalTokens()).isEqualTo(10); + + val moduleResults = response.getModuleResults(); + assertThat(moduleResults).isNotNull(); + assertThat(moduleResults.getInputMasking()).isNotNull(); + assertThat(moduleResults.getInputMasking().getMessage()) + .isEqualTo("Embedding input is masked successfully."); + assertThat(moduleResults.getInputMasking().getData()).isNotNull(); + assertThat(moduleResults.getInputMasking().getData()) + .isEqualTo(Map.of("masked_input", "['Hello', 'MASKED_PERSON', '!']")); + + verify( + postRequestedFor(urlEqualTo("/v2/embeddings")) + .withRequestBody( + equalToJson( + """ + { + "orchestration_config": { + "module_configs": { + "embeddings": { + "model": { + "name": "text-embedding-3-large", + "version": "latest", + "params": { + "encoding_format": "float", + "dimensions": 5, + "normalize": false + } + } + }, + "masking": { + "masking_providers": [ + { + "type": "sap_data_privacy_integration", + "method": "anonymization", + "entities": [ + { + "type": "profile-person" + } + ], + "allowlist" : [ ] + } + ] + } + } + }, + "input": { + "text": "['Hello', 'Müller', '!']" + } + } + """))); + } }