Jean Poudroux
08/20/2024, 8:27 AMbentoml==1.11.* to 1.3 and running into some issues when defining the input_spec when using pydantic models on the service.
On bentoml=1.11.* :
@svc.api(input=create_input_spec(), output=JSON())
def predict(data: ModelInput) -> dict[str, Any]:
where create_input_spec :
from <http://bentoml.io|bentoml.io> import JSON
def create_input_spec():
input_spec = JSON.from_sample(
ModelInput(....) )
return input_spec
while on bentoml==1.3
@bentoml.service
class MyService:
@bentoml.api(input_spec=ModelInput, output_spec=ModelOutput)
def predict(self, data: ModelInput):
and when invoking bentoml.build I get this:
@bentoml.api(input=JSON(), output=JSON())
2024-08-20 09:59:28.225
^^^^
2024-08-20 09:59:28.225
NameError: name 'JSON' is not defined
🤷♂️ - would be great with some migration guides on these releasesJean Poudroux
08/20/2024, 8:28 AMJSON.from_sample was quite beneficial as that added a some test data users could try out the api withJean Poudroux
08/20/2024, 8:36 AMinput=JSON() I have no idea -thats not whats defined in the serviceManoj Ravi
08/21/2024, 2:17 PMJian Shen Yap
08/22/2024, 8:01 AMpydantic.Field with default to provide an example value!
https://docs.bentoml.com/en/latest/guides/iotypes.html#pydanticManoj Ravi
08/22/2024, 9:58 AMJian Shen Yap
08/22/2024, 12:57 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
...Manoj Ravi
08/22/2024, 1:48 PM