Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow non-null but empty Parameters object in inference response #11

Merged
merged 5 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ resources:
- repository: templates
type: github
name: bakdata/bakdata-project-templates
# TODO:
philipp94831 marked this conversation as resolved.
Show resolved Hide resolved
ref: tmp/upload-snapshot
endpoint: bot

jobs:
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {

val junitVersion: String by project
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-api", version = junitVersion)
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter-params", version = junitVersion)
testRuntimeOnly(group = "org.junit.jupiter", name = "junit-jupiter-engine", version = junitVersion)
testImplementation(group = "org.assertj", name = "assertj-core", version = "3.25.1")
testImplementation(group = "com.squareup.okhttp3", name = "mockwebserver", version = okHttpVersion)
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/bakdata/kserve/predictv2/Parameters.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022 bakdata
* Copyright (c) 2024 bakdata GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,15 +24,19 @@

package com.bakdata.kserve.predictv2;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* A class to represent <a href="https://kserve.github.io/website/modelserving/inference_api/#parameters">
* parameters as defined in the v2 prediction protocol</a>.
* A class to represent <a href="https://kserve.github.io/website/modelserving/inference_api/#parameters"> parameters as
* defined in the v2 prediction protocol</a>.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Parameters {
private String contentType;
private Object extra;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* MIT License
*
* Copyright (c) 2024 bakdata GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package com.bakdata.kserve.predictv2;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import java.io.IOException;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

@ExtendWith(SoftAssertionsExtension.class)
public class InferenceResponseTest {
private ObjectMapper objectMapper;

@InjectSoftAssertions
private SoftAssertions softly;

@BeforeEach
void setUpObjectMapper() {
this.objectMapper = new ObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
}

@ParameterizedTest
@ValueSource(strings = {
"json_inference_responses/parameters_null.json",
"json_inference_responses/parameters_empty.json"
})
void shouldDeserialize(String jsonFilePath) throws IOException {
byte[] resourceFileBytes = getClass().getClassLoader().getResourceAsStream(jsonFilePath).readAllBytes();
String jsonInferenceResponse = new String(resourceFileBytes);

this.objectMapper.readValue(jsonInferenceResponse, InferenceResponse.class);
philipp94831 marked this conversation as resolved.
Show resolved Hide resolved
}
}
19 changes: 19 additions & 0 deletions src/test/resources/json_inference_responses/parameters_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"model_name": "fake-model-name",
"model_version": "1.0.0",
"id": "d26ad6e7-0cd7-4f37-b463-0409d9246b43",
"parameters": {},
"outputs": [
{
"name": "fake-output-name",
"shape": [
1
],
"datatype": "object",
"parameters": null,
"data": {
"output": "fake output"
}
}
]
}
19 changes: 19 additions & 0 deletions src/test/resources/json_inference_responses/parameters_null.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"model_name": "fake-model-name",
"model_version": "1.0.0",
"id": "d26ad6e7-0cd7-4f37-b463-0409d9246b43",
"parameters": null,
"outputs": [
{
"name": "fake-output-name",
"shape": [
1
],
"datatype": "object",
"parameters": null,
"data": {
"output": "fake output"
}
}
]
}