Comments (10)
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.
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 !
from bentoml.
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.
@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.
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.
Hi @frostming that does not work, the swagger ui can not be opened and the predict call also failed
from bentoml.
@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.
@frostming I am afraid the workaround not work
from bentoml.
@cceasy Make sure you are using the latest patch release. It is working on my side.
from bentoml.
Hi @frostming Awesome, after upgrade from 1.2.4 to 1.2.9. it works.
Thank you !
from bentoml.
Related Issues (20)
- bug: Dataframes not serializing correctly in the new API
- bug: bentoml not support gpu in mlflow? HOT 1
- bug: wrong key 'tracing' under 'api_server' HOT 3
- bug: KeyError: 'name' HOT 3
- bug: KeyError: 'name' HOT 2
- bug: KeyError: 'name' HOT 1
- bug: AssertionError HOT 2
- bug: bentlml containerize groupadd: Permission denied
- bug: bentoml containerize Dockerfile parse error line 34: Unknown flag: mount HOT 1
- bug: Transforms API references a Transformers Guide that doesn't exist
- bug: bentoml pull from yatai does not work HOT 2
- bug: bentoml deployment list fails unexpectedly HOT 1
- feature: Cloud Login without CLI HOT 2
- feature: Allow to use HTTP other Method (GET, PUT, DELETE) to impl kserve predict protocol v2 HOT 1
- bug: non batched request executed in non FIFO manier HOT 1
- bug: Doesn't create API key when enabling Protected EndPointAccess
- bug: Docker creating not working with some python versions HOT 6
- bug: When the container starts, it occupies extremely high memory
- feature: need documentation about bentoml.runner_service() with bentoml.depends() HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bentoml.