Git Product home page Git Product logo

Comments (10)

frostming avatar frostming commented on June 18, 2024 1

try if this works for you:

import bentoml

@bentoml.service(
    traffic={"timeout": 10},
)
class Hello:
    @bentoml.api(input_spec=dict)
    def predict(self, **data: Any) -> dict:
        print("data:", data)
        return data

from bentoml.

cceasy avatar cceasy commented on June 18, 2024

From the api_endpoint method of the ServiceAppFactory class, it call the input_spec.from_http_request method with two arguments passed, but in bentoml.io JSON class, the from_http_request method only take 1 argument !
image
image

from bentoml.

frostming avatar frostming commented on June 18, 2024

You are mixing new APIs with legacy ones. Here is the working code:

import bentoml
from bentoml.io import JSON

@bentoml.service(
    traffic={"timeout": 10},
)
class Hello:
    @bentoml.api
    def predict(self, data: dict) -> dict:
        print("data:", data)
        return data

We no longer needs to specify input= and output= since they are moved to the function signature

from bentoml.

cceasy avatar cceasy commented on June 18, 2024

@frostming thanks for quickly reply
But I do not want t wrapper of the request body, I have tried the way you just mentioned, but it requires the request body like this: {"data": {"f1": 1, "f2": 2}}, I do not want a nested data field, I want request body in this way: {"f1": 1, "f2": 2}

from bentoml.

cceasy avatar cceasy commented on June 18, 2024

our model depends on hundreds of features, and it's managed by the company metadata service, the upstream would pass the parameter in the way above, we just hope to replace the model serving part to Bentoml, that's why I need the parameter in the way above.

from bentoml.

cceasy avatar cceasy commented on June 18, 2024

Hi @frostming that does not work, the swagger ui can not be opened and the predict call also failed
image

image

from bentoml.

frostming avatar frostming commented on June 18, 2024

@cceasy needs a little workaround:

import bentoml
from pydantic import RootModel


class Input(RootModel[dict]):
    pass


@bentoml.service(
    traffic={"timeout": 10},
)
class Hello:
    @bentoml.api(input_spec=Input)
    def predict(self, root: dict) -> dict:
        print("data:", root)
        return root

from bentoml.

cceasy avatar cceasy commented on June 18, 2024

@frostming I am afraid the workaround not work
image

from bentoml.

frostming avatar frostming commented on June 18, 2024

@cceasy Make sure you are using the latest patch release. It is working on my side.

from bentoml.

cceasy avatar cceasy commented on June 18, 2024

Hi @frostming Awesome, after upgrade from 1.2.4 to 1.2.9. it works.
Thank you !

from bentoml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.