encoderfile 0.6.2

Distribute and run transformer encoders with a single file.
Documentation
use crate::services::{Inference, Metadata};

use axum::{Json, extract::State, response::IntoResponse};

pub const HEALTH_ENDPOINT: &str = "/health";
pub const MODEL_METADATA_ENDPOINT: &str = "/model";
pub const PREDICT_ENDPOINT: &str = "/predict";
pub const OPENAPI_ENDPOINT: &str = "/openapi.json";

#[utoipa::path(
    get,
    path = HEALTH_ENDPOINT,
    responses(
        (status = 200, description = "Successful")
    )
)]
pub async fn health() -> impl IntoResponse {
    Json("OK!")
}

#[utoipa::path(
    get,
    path = MODEL_METADATA_ENDPOINT,
    responses(
        (status = 200, response = crate::common::GetModelMetadataResponse)
    ),
)]
pub async fn get_model_metadata<S: Metadata>(State(state): State<S>) -> impl IntoResponse {
    Json(state.metadata())
}

pub async fn predict<S: Inference>(
    State(state): State<S>,
    Json(req): Json<S::Input>,
) -> impl IntoResponse {
    state
        .inference(req)
        .map(Json)
        .map_err(|e| e.to_axum_status())
}