Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pipeline/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<suppress files="[/\\]core[/\\]client[/\\]" checks=".*"/>
<suppress files="[/\\]core[/\\]model[/\\]" checks=".*"/>
<suppress files="[/\\]openai[/\\]generated[/\\]model[/\\]" checks=".*"/>
<suppress files="[/\\]rpt[/\\]generated[/\\]" checks=".*"/>
<suppress files="[/\\]orchestration[/\\]model[/\\]" checks=".*"/>
<suppress files="[/\\]grounding[/\\]client[/\\]" checks=".*"/>
<suppress files="[/\\]grounding[/\\]model[/\\]" checks=".*"/>
Expand Down
153 changes: 153 additions & 0 deletions foundation-models/sap-rpt/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>sdk-parent</artifactId>
<version>1.16.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<groupId>com.sap.ai.sdk.foundationmodels</groupId>
<artifactId>sap-rpt</artifactId>
<name>SAP RPT Model Client</name>
<description>SAP Cloud SDK for AI is the official Software Development Kit (SDK) for SAP AI Core, SAP Generative AI Hub, and Orchestration Service. This is the client for consuming SAP RPT model for in-context learning predictions on tabular data.</description>
<url>https://github.com/SAP/ai-sdk-java?tab=readme-ov-file#documentation</url>
<organization>
<name>SAP SE</name>
<url>https://www.sap.com</url>
</organization>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>SAP</name>
<email>cloudsdk@sap.com</email>
<organization>SAP SE</organization>
<organizationUrl>https://www.sap.com</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/SAP/ai-sdk-java.git</connection>
<developerConnection>scm:git:ssh://github.com:SAP/ai-sdk-java.git</developerConnection>
<url>https://github.com/SAP/ai-sdk-java/tree/main</url>
</scm>
<properties>
<project.rootdir>${project.basedir}/../../</project.rootdir>
<coverage.complexity>83%</coverage.complexity>
<coverage.line>77%</coverage.line>
<coverage.instruction>82%</coverage.instruction>
<coverage.branch>100%</coverage.branch>
<coverage.method>83%</coverage.method>
</properties>

<dependencies>
<dependency>
<groupId>com.sap.ai.sdk</groupId>
<artifactId>core</artifactId>
</dependency>
<dependency>
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
<artifactId>cloudplatform-connectivity</artifactId>
</dependency>
<dependency>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>openapi-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<!-- scope "provided" -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- scope "test" -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sap.cloud.sdk.cloudplatform</groupId>
<artifactId>connectivity-apache-httpclient5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>generate</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>generate</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<configuration>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<enableOneOfAnyOfGeneration>true</enableOneOfAnyOfGeneration>
<compileScope>COMPILE</compileScope>
<deleteOutputDirectory>true</deleteOutputDirectory>
</configuration>
<executions>
<execution>
<id>sap-rpt</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/spec/sap-rpt-1_openapi.json</inputSpec>
<modelPackage>com.sap.ai.sdk.foundationmodels.rpt.generated.model</modelPackage>
<apiPackage>com.sap.ai.sdk.foundationmodels.rpt.generated.client</apiPackage>
<generateApis>true</generateApis>
<additionalProperties>
<library>apache-httpclient</library>
<pojoBuilderMethodName>create</pojoBuilderMethodName>
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
<useOneOfInterfaces>true</useOneOfInterfaces>
<useOneOfCreators>true</useOneOfCreators>
<useFloatArrays>true</useFloatArrays>
<excludePaths>/predict_parquet</excludePaths>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.sap.ai.sdk.foundationmodels.rpt;

import static com.sap.ai.sdk.core.JacksonConfiguration.getDefaultObjectMapper;

import com.sap.ai.sdk.core.AiCoreService;
import com.sap.ai.sdk.core.DeploymentResolutionException;
import com.sap.ai.sdk.foundationmodels.rpt.generated.client.DefaultApi;
import com.sap.ai.sdk.foundationmodels.rpt.generated.model.PredictRequestPayload;
import com.sap.ai.sdk.foundationmodels.rpt.generated.model.PredictResponsePayload;
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
import com.sap.cloud.sdk.services.openapi.apache.ApiClient;
import javax.annotation.Nonnull;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

/**
* Client for interacting with SAP RPT foundation models.
*
* @since 1.16.0
*/
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class RptClient {
@Nonnull private final DefaultApi api;

/**
* Creates a new RptClient for the specified foundation model.
*
* @param foundationModel The foundation model to use.
* @return A new instance of RptClient.
* @throws DeploymentResolutionException If there is an error resolving the deployment.
*/
@Nonnull
public static RptClient forModel(@Nonnull final RptModel foundationModel)
throws DeploymentResolutionException {
final var destination = new AiCoreService().getInferenceDestination().forModel(foundationModel);
return forDestination(destination);
}

/**
* Creates a new RptClient for the specified destination.
*
* @param destination The destination to use.
* @return A new instance of RptClient.
*/
static RptClient forDestination(@Nonnull final Destination destination) {
final var apiClient = ApiClient.create(destination).withObjectMapper(getDefaultObjectMapper());
return new RptClient(new DefaultApi(apiClient));
}

/**
* Predict targets using SAP RPT model with structured data. *
*
* <p><b>200</b> - Successful response with predictive insights.
*
* <p><b>400</b> - Bad Request - Invalid input.
*
* <p><b>422</b> - Unprocessable Content - Invalid input.
*
* <p><b>500</b> - Internal Server Error.
*
* @param requestBody The prediction request
* @return prediction response from the RPT model
*/
@Nonnull
public PredictResponsePayload tabCompletion(@Nonnull final PredictRequestPayload requestBody) {
return api.predict(requestBody);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sap.ai.sdk.foundationmodels.rpt;

import com.sap.ai.sdk.core.AiModel;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Represents an SAP RPT foundation model.
*
* @param name The name of the model.
* @param version The version of the model (optional).
* @since 1.16.0
*/
public record RptModel(@Nonnull String name, @Nullable String version) implements AiModel {

/** SAP RPT 1 Small model. */
public static final RptModel SAP_RPT_1_SMALL = new RptModel("sap-rpt-1-small", null);

/** SAP RPT 1 Large model. */
public static final RptModel SAP_RPT_1_LARGE = new RptModel("sap-rpt-1-large", null);

/**
* Create a new instance of RptModel with the provided version.
*
* @param version The version of the model.
* @return The new instance of RptModel.
*/
@Nonnull
public RptModel withVersion(@Nonnull final String version) {
return new RptModel(name, version);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.sap.ai.sdk.foundationmodels.rpt.generated.client;

import com.fasterxml.jackson.core.type.TypeReference;
import com.sap.ai.sdk.foundationmodels.rpt.generated.model.PredictRequestPayload;
import com.sap.ai.sdk.foundationmodels.rpt.generated.model.PredictResponsePayload;
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
import com.sap.cloud.sdk.services.openapi.apache.ApiClient;
import com.sap.cloud.sdk.services.openapi.apache.BaseApi;
import com.sap.cloud.sdk.services.openapi.apache.Pair;
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import javax.annotation.Nonnull;

/**
* SAP-RPT-1 Tabular AI in version 0.1.0.
*
* <p>A REST API for in-context learning with the SAP-RPT-1 model.
*/
public class DefaultApi extends BaseApi {

/** Instantiates this API class to invoke operations on the SAP-RPT-1 Tabular AI */
public DefaultApi() {}

/**
* Instantiates this API class to invoke operations on the SAP-RPT-1 Tabular AI.
*
* @param httpDestination The destination that API should be used with
*/
public DefaultApi(@Nonnull final Destination httpDestination) {
super(httpDestination);
}

/**
* Instantiates this API class to invoke operations on the SAP-RPT-1 Tabular AI based on a given
* {@link ApiClient}.
*
* @param apiClient ApiClient to invoke the API on
*/
public DefaultApi(@Nonnull final ApiClient apiClient) {
super(apiClient);
}

/**
* Make in-context predictions for specified target columns based on provided table data JSON
* (optionally gzip-compressed).
*
* <p>Make in-context predictions for specified target columns. Either \&quot;rows\&quot; or
* \&quot;columns\&quot; must be provided and must contain both context and query rows. You can
* optionally send gzip-compressed JSON payloads and set a \&quot;Content-Encoding: gzip\&quot;
* header.
*
* <p><b>200</b> - Successful Prediction
*
* <p><b>400</b> - Bad Request - Invalid input data
*
* <p><b>413</b> - Payload Too Large
*
* <p><b>422</b> - Validation Error
*
* <p><b>500</b> - Internal Server Error
*
* @param predictRequestPayload The value for the parameter predictRequestPayload
* @return PredictResponsePayload
* @throws OpenApiRequestException if an error occurs while attempting to invoke the API
*/
@Nonnull
public PredictResponsePayload predict(@Nonnull final PredictRequestPayload predictRequestPayload)
throws OpenApiRequestException {

// verify the required parameter 'predictRequestPayload' is set
if (predictRequestPayload == null) {
throw new OpenApiRequestException(
"Missing the required parameter 'predictRequestPayload' when calling predict")
.statusCode(400);
}

// create path and map variables
final String localVarPath = "/predict";

final StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
final List<Pair> localVarQueryParams = new ArrayList<Pair>();
final List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
final Map<String, String> localVarHeaderParams = new HashMap<String, String>();
final Map<String, Object> localVarFormParams = new HashMap<String, Object>();

final String[] localVarAccepts = {"application/json"};
final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {"application/json"};
final String localVarContentType = ApiClient.selectHeaderContentType(localVarContentTypes);

final TypeReference<PredictResponsePayload> localVarReturnType =
new TypeReference<PredictResponsePayload>() {};

return apiClient.invokeAPI(
localVarPath,
"POST",
localVarQueryParams,
localVarCollectionQueryParams,
localVarQueryStringJoiner.toString(),
predictRequestPayload,
localVarHeaderParams,
localVarFormParams,
localVarAccept,
localVarContentType,
localVarReturnType);
}
}
Loading
Loading