Skip to content

Commit

Permalink
add /v2/health/live,ready
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Nov 5, 2024
1 parent 6162249 commit 3fa443f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 58 additions & 1 deletion llgtrt/src/routes/health_check.rs
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
pub async fn route_health_check() {}
use std::sync::Arc;

use axum::{
extract::State,
http::{HeaderMap, StatusCode},
response::{IntoResponse, Response},
Json,
};
use serde_json::{json, Value};

use crate::{
error::AppError,
routes::{completions, openai::CompletionCreateParams},
state::AppState,
};

pub async fn ready_check() {
log::info!("ready_check -> all good");
}

pub async fn live_check(
headers: HeaderMap,
State(app_state): State<Arc<AppState>>,
) -> Result<Response, AppError> {
let req: CompletionCreateParams = serde_json::from_value(json!({
"model": "model",
"prompt": "Hi",
"max_tokens": 2
}))?;
let resp = completions::route_completions(headers, State(app_state), Json(req)).await?;
let status = resp.status();
let body = axum::body::to_bytes(resp.into_body(), 1024 * 1024).await?;
if status == StatusCode::OK {
let body: Value = serde_json::from_slice(&body)?;
log::debug!(
"Liveness check response: {}",
serde_json::to_string_pretty(&body)?
);
if body["choices"][0]["text"].as_str().is_some() {
log::info!("Liveness check complete");
Ok((StatusCode::OK, "Check complete").into_response())
} else {
log::error!(
"Liveness check failed: response body does not contain expected field; body: {}",
serde_json::to_string_pretty(&body)?
);
Ok((StatusCode::INTERNAL_SERVER_ERROR, "Check failed").into_response())
}

} else {
log::error!(
"Liveness check failed with status code: {}; body {}",
status,
String::from_utf8_lossy(&body)
);
Ok((status, body).into_response())
}
}
3 changes: 2 additions & 1 deletion llgtrt/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ pub async fn run_server(mut cli_config: CliConfig) -> anyhow::Result<()> {
let app = Router::new()
.route("/v1/completions", post(routes::route_completions))
.route("/v1/chat/completions", post(routes::route_chat_completions))
.route("/health_check", get(routes::route_health_check))
.route("/v1/health/live", get(routes::live_check))
.route("/v1/health/ready", get(routes::ready_check))
.route("/v1/run", post(routes::route_llguidance))
.route("/guidance", post(routes::route_llguidance))
.with_state(Arc::new(state))
Expand Down
8 changes: 8 additions & 0 deletions scripts/test-infer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ curl -X POST "${TRT_API_BASE}chat/completions" \
"temperature": 0.7
}'
;;

live)
curl -v "${TRT_API_BASE}health/live"
;;

ready)
curl -v "${TRT_API_BASE}health/ready"
;;

exn)
curl -X POST "${TRT_API_BASE}chat/completions" \
Expand Down

0 comments on commit 3fa443f

Please sign in to comment.