Skip to content

Commit

Permalink
examples: Add a client example to quickstart (#3752)
Browse files Browse the repository at this point in the history
* new server API

* update server code

* add server test

* format

* format2

* better error messages for server

* miscellaneous test fixes

* add context test and better tests for everything

* Update tests/e2e/bento_server_http/tests/test_serve.py

Co-authored-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>

* examples: Add a client example to quickstart

* Update client.py

* Update client.py

* Fix style.

---------

Co-authored-by: Sauyon Lee <git@sjle.co>
Co-authored-by: Sauyon Lee <2347889+sauyon@users.noreply.github.com>
Co-authored-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com>
  • Loading branch information
4 people authored Apr 13, 2023
1 parent 5139dea commit 52f7863
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/quickstart/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import logging

import numpy as np

from bentoml import HTTPServer
from bentoml.client import Client

logging.basicConfig(level=logging.WARN)

if __name__ == "__main__":
server = HTTPServer("iris_classifier:latest", production=True, port=3000)

# Start the server in a separate process and connect to it using a client
with server.start() as client:
res = client.classify(np.array([[4.9, 3.0, 1.4, 0.2]]))
print(f"Successfully received results, {res}")

# Alternatively, you can use Client.from_url to connect to an already running server
client = Client.from_url("http://localhost:3000")
res = client.classify(np.array([[4.9, 3.0, 1.4, 0.2]]))
print(f"Successfully received results, {res}")

0 comments on commit 52f7863

Please sign in to comment.