This message was deleted.
# ask-for-help
s
This message was deleted.
🏁 1
m
@Jiang If you can please help
j
When you started a debug server by using bentoml serve, you can access the API page directly. It should give out the curl example and also how to construct the http request.
m
Can I use input of type Form() ?
@Jiang
j
Sorry. I'm not sure what is "From" here. Do you mean HTML form here?
m
Multi Part form
Since our current infrastructure runs with Multi Part Form data.
Through fast api.
j
Yeah it is the same
m
In fast api, we define at route that it is of Form type
j
The arg name is the form input name
m
Yes but that's the issue. Its not mapping the name properly. It uses the exact positioning to map the values.
input_spec = Multipart(model_name=Text(), model_version=Text(), prompt=Text(), numImages= Text(), height = Text(), width = Text())
@svc.api(input=input_spec, output=Image())
def txt2img(model_name : str, model_version: str, prompt: str, numImages: str, height : str, width : str):
inputData = InputConfig(
model_id = model_name,
model_version=model_version,
prompt = prompt,
numImages=int(numImages),
height = int(height),
width=int(width)
)
Consider this is the service.py file When I generate curl file from postman it gives me this curl --location '129.159.39.39:3001/txt2img' \ --form 'model_id="29"' \ --form 'model_versionadasdascxas="1"' \ --form 'num_images="RAW, analog style, A stunning portrait of a beautiful woman, plain white background, nbdy-scarlet-sd15, ((highly detailed skin, skin details)), sharp focus, paisley shirt, 8k UHD, DSLR, high quality, film grain, Fujifilm XT3, <"' \ --form 'prompt="30"' \ --form 'height="512"' \ --form 'width="512"' It works but it does not do key mapping. If you write "model_id" or "asdsa" as first element it will always map to model_id and the position of the arguments cannot be changed
And this is the way Fast Api takes inputs and work perfectly fine with postman, python multipart or anything @app.post("/model/{avc}/") async def model_abc(model_name: str, model_version: str = Form(), prompt: str = Form(), numImages: Union[int, None] = Form(None), height: Union[int, None] = Form(None), width: Union[int, None] = Form(None), initImage: Union[UploadFile,
j
but you wrote model_name rather than model_id?
m
Yes But it still maps to the same model_name
And even I write anything in the first field it still maps it to model_name
j
If the requested form contains name that not defined, it will fallback to the positional
If all names are defined, it will perform name mapping.
m
That worked
Thanks
j
Great!
🍻
m
How can I define the optional values to get ? @Jiang Currently I am getting this error missing 4 required positional arguments: 'quality', 'steps', 'cfg', and 'seed' Since I want these values to pass as optional
@Tim Liu
t
Thanks @Muhammad Abdullah Rafique! @Xipeng Guan Could you followup?
m
@Jiang @Xipeng Guan If you can please answer
j
Copy code
def txt2img(model_name : str, model_version: str, quality=0, steps=2, cfg=None, seed=0)
@Muhammad Abdullah Rafique Hi. You can define optional values like normal Python function does. You just need to maintain them after all other args without default values.
m
Sure let me try