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

Mleap Spring Boot Swagger Documentation Seems Incorrect #861

Open
habib27 opened this issue Jul 19, 2023 · 4 comments
Open

Mleap Spring Boot Swagger Documentation Seems Incorrect #861

habib27 opened this issue Jul 19, 2023 · 4 comments

Comments

@habib27
Copy link

habib27 commented Jul 19, 2023

Hi,

I have been exploring the mleap-spring-boot project. The swagger documentation seems to be off for the transform endpoint.

In the swagger for the endpoint --> /models/{modelName}/transform
It mentions that the body is supposed to be the following:

{
"schema": {
"fields": [
{
"name": "string",
"dataType": {
"base": "BOOLEAN",
"shape": {
"base": "SCALAR",
"isNullable": true,
"tensorShape": [
{
"size": 0,
"name": "string"
}
]
}
}
}
]
},
"rows": [
[
{}
]
]
}

However, when you use that body there is an error --> "error": "NoSuchElementException: key not found: type",

Seems like a type field is required. Am i missing something? Also what are valid values for type.

Thank you for help, much appreciated.

@ltrottier-yelp
Copy link
Contributor

ltrottier-yelp commented Jul 19, 2023

Hello @habib27,

Are you following the tutorial here ?

To transform a frame, you need to format it as mleap expects it. Here is an example for airbnb leap frame:

{
    "schema": {
      "fields": [{
        "name": "state",
        "type": "string"
      }, {
        "name": "bathrooms",
        "type": "double"
      }, {
        "name": "square_feet",
        "type": "double"
      }, {
        "name": "bedrooms",
        "type": "double"
      }, {
        "name": "security_deposit",
        "type": "double"
      }, {
        "name": "cleaning_fee",
        "type": "double"
      }, {
        "name": "extra_people",
        "type": "double"
      }, {
        "name": "number_of_reviews",
        "type": "double"
      }, {
        "name": "review_scores_rating",
        "type": "double"
      }, {
        "name": "room_type",
        "type": "string"
      }, {
        "name": "host_is_superhost",
        "type": "string"
      }, {
        "name": "cancellation_policy",
        "type": "string"
      }, {
        "name": "instant_bookable",
        "type": "string"
      }]
    },
    "rows": [["NY", 2.0, 1250.0, 3.0, 50.0, 30.0, 2.0, 56.0, 90.0, "Entire home/apt", "1.0", "strict", "1.0"]]
  }

Reference for leap frame: https://github.com/combust/mleap/blob/master/mleap-executor-testkit/src/main/resources/leap_frame/frame.airbnb.json

Then, to query the model simply do:

body=$(cat frame.airbnb.json)
curl --header "Content-Type: application/json" \
  --header "timeout: 1000" \
  --request POST \
  --data "$body" http://localhost:8080/models/AirBnBLR/transform

@habib27
Copy link
Author

habib27 commented Jul 19, 2023

Hey @ltrottier-yelp ,

Thank you for the reply.

Yes I followed that tutorial. The link to the airbnb frame does not work for me, says all access is disabled. But that payload I was able to find somewhere and use and it does work.

However, the issue is you see that type field that is being used there in the example, it's not in the swagger and I don't know what are the possible values for it. For example if I have a model where the value is double but the base is "Tensor", what type do I pass in to make it work?

I get this error :

"status": "STATUS_ERROR",
"error": "IllegalArgumentException: Cannot cast ScalarType(double,true) to TensorType(double,Some(WrappedArray(75)),true)

Is there anywhere I can find what the valid values are for this type field?

@ltrottier-yelp
Copy link
Contributor

I'm taking a look at the swagger file, because it looks outdated. I'll try to update it soon.

The frame that you pass to the server is the same as a leap frame that you create in scala. It is simply its json representation. So you have two choices:

  1. Create it via scala code and save it to json using the provided json FrameWriter. See here for a tutorial.

  2. Create it yourself. Since the swagger is outdated, for now you can look at this file:

    implicit val MleapTensorTypeFormat: JsonFormat[TensorType] = lazyFormat(new JsonFormat[TensorType] {
    . This is where we define the parsing rules for json to create the leap frame. So for a tensor of type double, you need to define the type, base and dimensions.

@habib27
Copy link
Author

habib27 commented Jul 20, 2023

Hey @ltrottier-yelp ,

Thank you very much for your help and prompt response. I appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants