Inference Endpoints (dedicated) 文档
请求的序列化与反序列化
加入 Hugging Face 社区
并获取增强的文档体验
开始使用
请求的序列化与反序列化
Hugging Face Inference Endpoint 配备了一个默认的 serving 容器,该容器用于所有支持的 Transformers 和 Sentence-Transformers 任务以及自定义推理处理器。serving 容器负责基于请求的 content-type
和 accept
标头对请求和响应负载进行序列化和反序列化。这意味着当您发送带有 JSON 正文和 content-type: application/json
标头的请求时,serving 容器将 JSON 负载反序列化为 Python 字典并将其传递给推理处理器;如果您发送带有 accept: image/png
标头的请求,serving 容器将来自任务/自定义处理器的响应序列化为图像。
以下是受支持的 content-types
列表以及传递给推理处理器的反序列化负载。
Content-Type | 负载 |
---|---|
application/json | dict |
text/csv | raw |
text/plain | raw |
image/png | binary |
image/jpeg | binary |
image/jpg | binary |
image/tiff | binary |
image/bmp | binary |
image/gif | binary |
image/webp | binary |
image/x-image | binary |
audio/x-flac | {"inputs": bytes(body)} |
audio/flac | {"inputs": bytes(body)} |
audio/mpeg | {"inputs": bytes(body)} |
audio/x-mpeg-3 | {"inputs": bytes(body)} |
audio/wave | {"inputs": bytes(body)} |
audio/wav | {"inputs": bytes(body)} |
audio/x-wav | {"inputs": bytes(body)} |
audio/ogg | {"inputs": bytes(body)} |
audio/x-audio | {"inputs": bytes(body)} |
audio/webm | {"inputs": bytes(body)} |
audio/webm;codecs=opus | {"inputs": bytes(body)} |
audio/AMR | {"inputs": bytes(body)} |
audio/amr | {"inputs": bytes(body)} |
audio/AMR-WB | {"inputs": bytes(body)} |
audio/AMR-WB+ | {"inputs": bytes(body)} |
audio/m4a | {"inputs": bytes(body)} |
audio/x-m4a | {"inputs": bytes(body)} |
以下是受支持的 accept
标头列表以及返回的序列化负载。
Accept | 负载 |
---|---|
application/json | JSON |
text/csv | raw |
text/plain | raw |
image/png | binary |
image/jpeg | binary |
image/jpg | binary |
image/tiff | binary |
image/bmp | binary |
image/gif | binary |
image/webp | binary |
image/x-image | binary |