Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
import com.sap.cloud.sdk.services.openapi.apache.apiclient.ApiClient;
import java.io.File;
import java.util.Map;
import javax.annotation.Nonnull;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,6 +27,7 @@
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class RptClient {
@Nonnull private final DefaultApi api;
@Nonnull private final DefaultApi apiWithGzipEncoding;

/**
* Creates a new RptClient for the specified foundation model.
Expand All @@ -49,7 +51,8 @@ public static RptClient forModel(@Nonnull final RptModel foundationModel)
*/
static RptClient forDestination(@Nonnull final Destination destination) {
final var apiClient = ApiClient.create(destination).withObjectMapper(getDefaultObjectMapper());
return new RptClient(new DefaultApi(apiClient));
final var api = new DefaultApi(apiClient);
return new RptClient(api, api.withDefaultHeaders(Map.of("Content-Encoding", "gzip")));
}

/**
Expand All @@ -74,7 +77,7 @@ static RptClient forDestination(@Nonnull final Destination destination) {
@Beta
@Nonnull
public PredictResponsePayload tableCompletion(@Nonnull final PredictRequestPayload requestBody) {
return api.predict(requestBody, "gzip");
return apiWithGzipEncoding.predict(requestBody);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,12 @@ public DefaultApi withDefaultHeaders(@Nonnull final Map<String, String> defaultH
*
* <p><b>500</b> - Internal Server Error
*
* @param predictRequestPayload (required) The value for the parameter predictRequestPayload
* @param contentEncoding (optional) Content encoding of the request body. Use &#39;gzip&#39; for
* gzip-compressed payloads.
* @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,
@Nullable final String contentEncoding)
public PredictResponsePayload predict(@Nonnull final PredictRequestPayload predictRequestPayload)
throws OpenApiRequestException {

// verify the required parameter 'predictRequestPayload' is set
Expand All @@ -103,9 +99,6 @@ public PredictResponsePayload predict(
final Map<String, String> localVarHeaderParams = new HashMap<String, String>(defaultHeaders);
final Map<String, Object> localVarFormParams = new HashMap<String, Object>();

if (contentEncoding != null)
localVarHeaderParams.put("Content-Encoding", ApiClient.parameterToString(contentEncoding));

final String[] localVarAccepts = {"application/json"};
final String localVarAccept = ApiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = {"application/json"};
Expand All @@ -128,35 +121,6 @@ public PredictResponsePayload predict(
localVarReturnType);
}

/**
* 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 {
return predict(predictRequestPayload, null);
}

/**
* Make in-context predictions for specified target columns based on provided table data Parquet
* file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@
"summary": "Make in-context predictions for specified target columns based on provided table data JSON (optionally gzip-compressed).",
"description": "Make in-context predictions for specified target columns.\nEither \"rows\" or \"columns\" must be provided and must contain both context and query rows.\nYou can optionally send gzip-compressed JSON payloads and set a \"Content-Encoding: gzip\" header.",
"operationId": "predict",
"parameters": [
{
"name": "Content-Encoding",
"in": "header",
"description": "Content encoding of the request body. Use 'gzip' for gzip-compressed payloads.",
"required": false,
"schema": {
"type": "string",
"enum": ["gzip"]
}
}
],
Comment on lines -22 to -33
Copy link
Copy Markdown
Member

@rpanackal rpanackal Apr 14, 2026

Choose a reason for hiding this comment

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

Currently, we rely on the manual addition to spec for gzip encoding support. We have drafted an alternate (programatic) solution for passing custom headers in the PR below.

Once, the above PR has been merged (done) and Cloud SDK 5.28.0 has been released, we would need to do the following

  1. Remove the manual addition to spec and regenerate
  2. Set a default header Content-Encoding: gzip for predict() calls using withDefaultHeader() api

This PR doesn't need to be merged afterwards if there are no other changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The manual changes has been removed and fix applied

"requestBody": {
"content": {
"application/json": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"request": {
"method": "POST",
"url": "/predict",
"headers": {
"Content-Encoding": {
"equalTo": "gzip"
}
},
"bodyPatterns": [
{
"equalToJson": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"request": {
"method": "POST",
"url": "/predict",
"headers": {
"Content-Encoding": {
"equalTo": "gzip"
}
},
"bodyPatterns": [
{
"equalToJson": {
Expand Down
Loading