协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
serving-and-clients【开发与工程】Serve BentoML services locally over HTTP or gRPC and call endpoints with Python clients, curl/OpenAPI, streaming, websocket clients, and operational serve flags.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the user needs to run a BentoML service locally, choose HTTP versus gRPC serving, call service endpoints from Python or curl, inspect endpoint schemas, or debug client/serve failures. For defining @bentoml.service and @bentoml.api, use ../service-authoring/SKILL.md. For bentoml build, containerization, and Bento packaging, use ../packaging-and-containerization/SKILL.md. For metrics, logs, tracing, scaling, and runtime resource configuration, use ../observability-and-operations/SKILL.md. For BentoCloud deployments and cloud endpoints, use ../cli-and-cloud/SKILL.md.
bentoml serve SERVICE_TARGET, where SERVICE_TARGET is an import target such as service.py:Summarization, a local Bento tag such as fraud_detector:latest, or a Bento directory.bentoml serve service.py:ServiceClass --working-dir . --development --reload --port 3000.--development for local iteration because it uses one API worker and, with --reload, restarts on code/model-store changes.--working-dir whenever the service module is not in the current shell directory; this prevents import target failures caused by the wrong sys.path.--host, --port, --api-workers, --backlog, --timeout, and SSL flags for local server behavior; environment variables BENTOML_HOST, BENTOML_PORT, BENTOML_API_WORKERS, and BENTOML_TIMEOUT can also supply values.bentoml serve-grpc SERVICE_TARGET only when the caller needs gRPC; it is hidden in the CLI but implemented, supports reflection/channelz flags, and may require installing BentoML with gRPC dependencies.See references/cli-reference.md and the bundled dry-run helper scripts/serve_command_builder.py for safe command construction.
bentoml.SyncHTTPClient(url, token=None, timeout=30, server_ready_timeout=None) for blocking Python calls and bentoml.AsyncHTTPClient(...) for async code.with bentoml.SyncHTTPClient("http://localhost:3000") as client: or async with bentoml.AsyncHTTPClient("http://localhost:3000") as client:./schema.json; call client.<endpoint>(...) when the endpoint name is a valid Python attribute or client.call("endpoint_name", ...) when it is dynamic.client.summarize(text="..."); root-input APIs require exactly one positional argument.server_ready_timeout when connecting while a server is booting, and use client.is_ready() to check /readyz before sending expensive calls.token="..."; if omitted, the client reads BENTO_CLOUD_API_KEY and sends Authorization: Bearer <token> when available.See references/client-reference.md and scripts/inspect_service_client.py for schema inspection without starting a server.
/schema.json, readiness is at /readyz, and OpenAPI JSON is exposed under the docs route as docs.json.POST /<route> with Content-Type: application/json; the hello-world endpoint shape is curl -X POST http://localhost:3000/summarize -H 'Content-Type: application/json' -d '{"text":"..."}'./schema.json first; API method names, custom route=... values, and visible HTTP paths can differ.for chunk in client.generate(prompt="..."): or async for chunk in await client.generate(prompt="..."): depending on the async method’s return.@bentoml.asgi_app(app, path="/chat"); the BentoML Python HTTP clients do not support WebSockets.websockets and connect to the mounted path plus websocket route, for example ws://localhost:3000/chat/ws.../service-authoring/SKILL.md; this sub-skill focuses on calling and debugging the running server.bentoml serve-grpc SERVICE_TARGET --port 3000 --host 0.0.0.0 for local gRPC serving when the environment includes gRPC support.grpc.health.v1.Health/Check and generated BentoML stubs.--enable-reflection, --enable-channelz, --max-concurrent-streams, --protocol-version v1|v1alpha1, --api-workers, --backlog, and SSL cert/key/CA options.SO_REUSEPORT; use --development for local testing or containerize on Linux for production-like behavior.scripts/serve_command_builder.py builds shell-safe bentoml serve or bentoml serve-grpc commands and never starts a server unless a user copies the output.scripts/inspect_service_client.py requires an explicit URL, checks /readyz and /schema.json, and prints endpoint routes, input/output schemas, streaming flags, and task flags.module.py:ClassName or module:svc, pass --working-dir, and confirm the module imports from that directory.--port, clear the process occupying the port, or use a separate HTTP and gRPC port.server_ready_timeout, check /readyz, and verify expensive model loading or startup hooks are not failing./schema.json, then call the route’s name with client.call(name, ...) or the generated method.token= explicitly or set BENTO_CLOUD_API_KEY; verify the endpoint actually expects BentoCloud-style bearer auth.serve-grpc or generated gRPC clients.async with bentoml.AsyncHTTPClient(...) or call await client.close().For deeper failure mapping, see references/troubleshooting.md.