[2/2] [feature] support openai like classification api in router (#11670)

This commit is contained in:
ybyang
2025-10-19 10:31:08 +08:00
committed by GitHub
parent a7ae61ed77
commit d513ee93ef
14 changed files with 257 additions and 45 deletions

View File

@@ -37,6 +37,7 @@ use crate::{
policies::PolicyRegistry,
protocols::{
chat::ChatCompletionRequest,
classify::ClassifyRequest,
completion::CompletionRequest,
embedding::EmbeddingRequest,
generate::GenerateRequest,
@@ -270,6 +271,17 @@ async fn v1_embeddings(
.await
}
async fn v1_classify(
State(state): State<Arc<AppState>>,
headers: http::HeaderMap,
Json(body): Json<ClassifyRequest>,
) -> Response {
state
.router
.route_classify(Some(&headers), &body, None)
.await
}
async fn v1_responses_get(
State(state): State<Arc<AppState>>,
Path(response_id): Path<String>,
@@ -534,13 +546,7 @@ async fn get_loads(State(state): State<Arc<AppState>>, _req: Request) -> Respons
})
.collect();
(
StatusCode::OK,
Json(json!({
"workers": loads
})),
)
.into_response()
(StatusCode::OK, Json(json!({ "workers": loads }))).into_response()
}
async fn create_worker(
@@ -707,6 +713,7 @@ pub fn build_app(
.route("/v1/rerank", post(v1_rerank))
.route("/v1/responses", post(v1_responses))
.route("/v1/embeddings", post(v1_embeddings))
.route("/v1/classify", post(v1_classify))
.route("/v1/responses/{response_id}", get(v1_responses_get))
.route(
"/v1/responses/{response_id}/cancel",