Matěj Šmíd
07/17/2024, 9:04 AM@svc.api(
input=JSON(pydantic_model=S3BucketAndKeys),
output=JSON(pydantic_model=ListOfPoseEstimationResults),
)
def func(s3_objects):
...
accepted raw JSON requests, without any HTML form encoding. I used this for inference:
<http://requests.post|requests.post>(url, headers={'accept': 'application/json'}, data='{....}')
The new class based API:
@bentoml.service()
class Service:
@bentoml.api()
def func(self, s3_objects: S3BucketAndKeys) -> ListOfPoseEstimationResults:
...
expects HTML form encoded inputs. The s3_objects parameter needs to be explicitly named:
<http://requests.post|requests.post>(url, data='{"s3_objects": ...}')
Is it possible to stay compatible with the older API?Chaoyu
07/17/2024, 5:25 PMChaoyu
07/17/2024, 5:25 PMfrom pydantic import BaseModel, Field
import typing as t
import bentoml
class AdsGenerationParams(BaseModel):
prompt: str = Field(description="The prompt text")
industry: str = Field(description="The industry the company belongs to")
target_audience: str = Field(description="Target audience for the advertisement")
temperature: float = Field(default=0.0, description="A sampling temperature between 0 and 2")
@bentoml.service
class AdsWriter:
@bentoml.api(input_spec=AdsGenerationParams)
def generate(self, **params: t.Any) -> str:
# Access parameters from the request
prompt = params['prompt']
industry = params['industry']
target_audience = params['target_audience']
temperature = params['temperature']
# Use the parameters in your Service logic
# Implementation logic
...Matěj Šmíd
07/18/2024, 5:12 PM