调用部署端点

本文档解释了如何通过调用其端点 URL 与部署交互。

获取端点 URL

选择以下方法之一来获取端点 URL。

安装 jq,然后运行以下命令。

bentoml deployment get <your_deployment_name> -o json | jq ."endpoint_urls"
import bentoml

deployment_info = bentoml.deployment.get('your_deployment_name')
print(deployment_info.get_endpoint_urls())
  1. 导航到部署页面。

  2. 单击所需的部署。

  3. 在详情页面上,您可以在部署名称下方找到端点 URL。

    Screenshot of BentoCloud deployment details page highlighting where to find the endpoint URL

与部署交互

选择以下方法之一使用端点 URL 访问您的部署。以下示例展示了如何与Summarization Deployment交互。您可以在特定部署的详情页面的Playground选项卡上找到相应的 Python 代码和 CURL 命令。

curl -X 'POST' \
    'https://<deployment_endpoint_url>/summarize' \
    -H 'accept: text/plain' \
    -H 'Content-Type: application/json' \
    -d '{
    "text": "Your long text to summarize"
    }'

将端点 URL 包含在您的客户端中,如下所示。有关更多信息,请参见调用 API 端点

import bentoml

client = bentoml.SyncHTTPClient(url='<deployment_endpoint_url>')
result: str = client.summarize(text="Your long text to summarize")
print(result)

您可以通过使用 get_clientget_async_client 来检索客户端的信息(如果您启用了授权,请设置 token 参数),然后调用其可用端点向您的部署发起 HTTP 请求。

import bentoml

dep = bentoml.deployment.get(name="deploy-1")
# Get synchronous HTTP client for Deployment:
client = dep.get_client()
# Get asynchronous HTTP client for Deployment:
async_client = dep.get_async_client()
# Call the client's endpoint to interact
result = client.summarize(text="Your long text to summarize")

直接访问部署端点 URL。Swagger UI 根据 OpenAPI 规范动态生成文档和用户界面。

Screenshot of Swagger UI interface for a BentoML deployment showing API documentation and interactive testing capabilities

与受保护的端点交互

如果您在创建部署时为其启用了授权,则其端点 URL 将受到保护。您需要创建一个具有受保护端点访问权限的 API 令牌,然后使用此令牌访问它