我有一个使用变压器的工作模型pipeline
我想将它与 FastAPI 一起使用来发送post
请求并获得答复。
该模型的工作原理如下:
#Loading the model
classifier = pipeline(path_to_model)
#Making predictions:
classifier(txt)
输出是一个list
of dicts
.
我的代码是:
app = FastAPI()
@app.post("/predictions")
def extract_predictions(text):
text = text.lower()
out=classifier(text)
return {
"text_message": text,
"predictions": out
}
如果我使用我可以获得预测localhost:8000/docs
,但是当我使用邮递员或失眠和身体(JSON)时{"text":"any string"}
I get "field_required"
该模型采用字符串作为输入,我的邮递员请求使用 JSON 正文。如何更新模型以获取 JSON 格式的输入?
The text
当前定义的属性预计是query
范围,not body
(JSON) 参数。因此,您可以将其作为query
参数时POST
荷兰国际集团您的请求,或定义它使用Body字段(例如,text: str = Body(..., embed=True)
),因此请求正文中的预期内容为JSON
。请看一下答案here and here更多细节。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)