Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add client code examples without context manager #4512

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/source/guides/clients.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ After you start the ``Summarization`` Service, you can create the following clie

.. tab-item:: Synchronous

To directly instantiate a synchronous client:

.. code-block:: python

client = bentoml.SyncHTTPClient('http://localhost:3000')
response = client.summarize(text="Your long text to summarize")
print(response)

# Close the client to release resources
client.close()

To create a synchronous client with a context manager:

.. code-block:: python

with bentoml.SyncHTTPClient('http://localhost:3000') as client:
Expand All @@ -47,6 +60,24 @@ After you start the ``Summarization`` Service, you can create the following clie

.. tab-item:: Asynchronous

To directly instantiate an asynchronous client:

.. code-block:: python

import asyncio

async def async_client_operation():
client = bentoml.AsyncHTTPClient('http://localhost:3000')
response = await client.summarize(text="Your long text to summarize")
print(response)

# Close the client to release resources
await client.close()

asyncio.run(async_client_operation())

To create an asynchronous client with a context manager:

.. code-block:: python

async with bentoml.AsyncHTTPClient('http://localhost:3000') as client:
Expand Down