0Pricing
MLOps Academy · Lekcja

Definiowanie usługi i jej API

Udostępniaj runnery przez endpoint usługi z typami

Definiowanie usługi i jej API to bezpłatna lekcja MLOps Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej MLOps Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs MLOps Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

What a Service Is

In BentoML a Service is the unit you deploy. It wraps your model and exposes one or more API endpoints clients can call. 🛎️

Runners Run the Model

A runner is BentoML's optimized wrapper around a saved model. It handles inference in its own worker so the API stays responsive.

runner = bentoml.sklearn.get("iris_clf:latest").to_runner()

Create the Service

You build a service by naming it and passing its runners. The Service object is what BentoML serves and scales.

svc = bentoml.Service("iris_classifier", runners=[runner])

Add an Endpoint

You expose a function as an API with the @svc.api decorator. That function becomes a callable HTTP route.

@svc.api(input=..., output=...)
def classify(data):
    ...

Declare Input and Output

You set typed IO descriptors so BentoML can validate and serialize. NumpyNdarray tells it to expect and return arrays.

from bentoml.io import NumpyNdarray

Call the Runner Inside

Within the API function you invoke the model through the runner. Using run sends the input to the model worker and returns the result.

result = runner.predict.run(data)
return result

Put It in service.py

BentoML looks for your code in a file by convention. You place the service in service.py at your project root.

Serve It Locally

One command starts a dev server. bentoml serve points at the file and the svc object, then watches for changes.

bentoml serve service:svc --reload

Use JSON for Dicts

Not every API speaks arrays. Swap the descriptor to JSON when your clients send and expect dictionaries instead.

from bentoml.io import JSON

Built-In Swagger Docs

Once it runs, BentoML serves interactive Swagger docs at the root URL so you can test each endpoint in the browser. 🎉

Test with a curl Call

You can hit the live endpoint from your terminal. A quick curl POST sends sample input and shows the prediction it returns.

curl -X POST localhost:3000/classify -d "[[5.1,3.5,1.4,0.2]]"

Quick Check

You want to call your model from inside an API function. What is the right wrapper to use?

Recap

You turned a runner into a Service, exposed an @svc.api endpoint with typed IO, dropped it in service.py, and served it with built-in docs. Live API done! 🙌

Często zadawane pytania

Czy lekcja „Definiowanie usługi i jej API” jest bezpłatna?

Tak — pełny tekst „Definiowanie usługi i jej API” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu MLOps Academy, przejdź na CoddyKit PRO. Kurs MLOps Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Definiowanie usługi i jej API”?

Udostępniaj runnery przez endpoint usługi z typami Ćwiczysz MLOps Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć MLOps Academy?

Nie wymagamy żadnego doświadczenia. MLOps Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Definiowanie usługi i jej API”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji MLOps Academy?

Tak. Każda lekcja MLOps Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Zapisywanie modelu w Bento Store
  2. Definiowanie usługi i jej API
  3. Włączanie adaptacyjnego mikrobatchingu
  4. Budowanie Bento i umieszczanie go w kontenerze
← Powrót do MLOps Academy