客户端 API¶
您可以创建一个 BentoML 客户端 来与您的 BentoML 服务进行交互。
bentoml.SyncHTTPClient¶
- class bentoml.SyncHTTPClient(url: str, *, token: str | None = None, timeout: float = 30, server_ready_timeout: float | None = None)[source]¶
BentoML 服务的同步客户端。
- 参数:
示例
with SyncHTTPClient("https://:3000") as client: resp = client.call("classify", input_series=[[1,2,3,4]]) assert resp == [0] # Or using named method directly resp = client.classify(input_series=[[1,2,3,4]]) assert resp == [0]
- client_cls¶
别名
Client
bentoml.AsyncHTTPClient¶
- class bentoml.AsyncHTTPClient(url: str, *, token: str | None = None, timeout: float = 30, server_ready_timeout: float | None = None)[source]¶
BentoML 服务的异步客户端。
- 参数:
示例
async with AsyncHTTPClient("https://:3000") as client: resp = await client.call("classify", input_series=[[1,2,3,4]]) assert resp == [0] # Or using named method directly resp = await client.classify(input_series=[[1,2,3,4]]) assert resp == [0] # Streaming resp = client.stream(prompt="hello") async for data in resp: print(data)
- client_cls¶
别名
AsyncClient