Set Up Pipeline

A Wyvern pipeline is the API route that defines the logistics of your ML application pipeline and it defines the API endpoint of yours. There are a couple of inputs:

  • REQUEST_SCHEMA_CLASS: the class of the request schema. This is used to validate the request data.
  • RESPONSE_SCHEMA_CLASS: the class of the response schema. This is used to validate the response data.
  • PATH: the path of the API. This is used in the API routing.
  • (Optional) API_VERSION: the version of the API. This is used in the API routing. The default value is “v1”. As a result, the final url of your pipeline will be /api/v1/{your PATH}
  • (Optional) API_NAME: the name of the API. This is used in the API routing. If not provided, the name of the pipeline component class will be used by default.

Now let’s define a PipelineComponent under pipelines/product_ranking/ranking_pipeline.py:

pipelines/product_ranking/ranking_pipeline.py
from wyvern import (
    ModelComponent,
    RankingPipeline,
    RankingResponse,
)

from pipelines.product_ranking.models import RankingModel
from pipelines.product_ranking.schemas import MyRankingRequest, Product


class MyRankingPipeline(RankingPipeline[Product]):
    REQUEST_SCHEMA_CLASS = MyRankingRequest
    RESPONSE_SCHEMA_CLASS = RankingResponse
    PATH = "/my-ranking"
    API_VERSION = "/v1"

    def get_model(self) -> ModelComponent:
        return RankingModel()

With this example, MyRankingRequest is the request schema and RankingResponse is the response schema. And the API url is /api/v1/my-ranking

Register Pipelines

Similar to registering realtime features, register the pipeline with the Wyvern service in pipelines/main.py:

pipelines/main.py
from wyvern import WyvernService

from pipelines.product_ranking.ranking_pipeline import MyRankingPipeline
from pipelines.product_ranking.realtime_features import (
    RealtimeProductFeature,
    RealtimeProductQueryFeature,
)

app = WyvernService.generate_app(
    route_components=[MyRankingPipeline],
    realtime_feature_components=[RealtimeProductFeature, RealtimeProductQueryFeature],
)

To register the pipeline, pass the the route_components as a list, containing your pipelines, to WyvernService.generate_app. This basically register the /api/v1/ranking route in the Wyvern service.

Now if you do wyvern run, your ranking endpoint is ready to serve a request.