0Pricing
MLOps Academy · บทเรียน

กำหนดบริการและ API ของบริการ

เปิดให้เรียกใช้ตัวรันผ่านปลายทางบริการที่ระบุชนิดข้อมูล

กำหนดบริการและ API ของบริการ เป็นบทเรียน MLOps Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน MLOps Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส MLOps Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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! 🙌

คำถามที่พบบ่อย

บทเรียน “กำหนดบริการและ API ของบริการ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “กำหนดบริการและ API ของบริการ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส MLOps Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส MLOps Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “กำหนดบริการและ API ของบริการ”

เปิดให้เรียกใช้ตัวรันผ่านปลายทางบริการที่ระบุชนิดข้อมูล คุณปฏิบัติ MLOps Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน MLOps Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน MLOps Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “กำหนดบริการและ API ของบริการ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน MLOps Academy นี้ได้ไหม

ได้ บทเรียน MLOps Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. บันทึกโมเดลลง Bento Store
  2. กำหนดบริการและ API ของบริการ
  3. เปิดใช้การประมวลผลแบบกลุ่มปรับตามคำขอ
  4. สร้าง Bento และทำให้เป็นคอนเทนเนอร์
← กลับไปที่ MLOps Academy