chore: add metrics for ai (#1184)
This commit is contained in:
parent
5d9efb4243
commit
e990bad68f
|
|
@ -37,6 +37,7 @@ async fn stream_complete_text_handler(
|
||||||
) -> actix_web::Result<HttpResponse> {
|
) -> actix_web::Result<HttpResponse> {
|
||||||
let ai_model = ai_model_from_header(&req);
|
let ai_model = ai_model_from_header(&req);
|
||||||
let params = payload.into_inner();
|
let params = payload.into_inner();
|
||||||
|
state.metrics.ai_metrics.record_total_completion_count(1);
|
||||||
|
|
||||||
match state
|
match state
|
||||||
.ai_client
|
.ai_client
|
||||||
|
|
@ -80,6 +81,7 @@ async fn summarize_row_handler(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.metrics.ai_metrics.record_total_summary_row_count(1);
|
||||||
let ai_model = ai_model_from_header(&req);
|
let ai_model = ai_model_from_header(&req);
|
||||||
let result = state.ai_client.summarize_row(&content, ai_model).await;
|
let result = state.ai_client.summarize_row(&content, ai_model).await;
|
||||||
let resp = match result {
|
let resp = match result {
|
||||||
|
|
@ -105,6 +107,7 @@ async fn translate_row_handler(
|
||||||
) -> actix_web::Result<Json<AppResponse<TranslateRowResponse>>> {
|
) -> actix_web::Result<Json<AppResponse<TranslateRowResponse>>> {
|
||||||
let params = payload.into_inner();
|
let params = payload.into_inner();
|
||||||
let ai_model = ai_model_from_header(&req);
|
let ai_model = ai_model_from_header(&req);
|
||||||
|
state.metrics.ai_metrics.record_total_translate_row_count(1);
|
||||||
match state.ai_client.translate_row(params.data, ai_model).await {
|
match state.ai_client.translate_row(params.data, ai_model).await {
|
||||||
Ok(resp) => Ok(AppResponse::Ok().with_data(resp).into()),
|
Ok(resp) => Ok(AppResponse::Ok().with_data(resp).into()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ pub struct AIMetrics {
|
||||||
total_stream_count: Counter,
|
total_stream_count: Counter,
|
||||||
failed_stream_count: Counter,
|
failed_stream_count: Counter,
|
||||||
stream_image_count: Counter,
|
stream_image_count: Counter,
|
||||||
|
total_completion_count: Counter,
|
||||||
|
total_summary_row_count: Counter,
|
||||||
|
total_translate_row_count: Counter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AIMetrics {
|
impl AIMetrics {
|
||||||
|
|
@ -28,6 +31,21 @@ impl AIMetrics {
|
||||||
"Total count of image streams processed",
|
"Total count of image streams processed",
|
||||||
metrics.stream_image_count.clone(),
|
metrics.stream_image_count.clone(),
|
||||||
);
|
);
|
||||||
|
realtime_registry.register(
|
||||||
|
"total_completion_count",
|
||||||
|
"Total count of completions processed",
|
||||||
|
metrics.total_completion_count.clone(),
|
||||||
|
);
|
||||||
|
realtime_registry.register(
|
||||||
|
"total_summary_row_count",
|
||||||
|
"Total count of summary rows processed",
|
||||||
|
metrics.total_summary_row_count.clone(),
|
||||||
|
);
|
||||||
|
realtime_registry.register(
|
||||||
|
"total_translate_row_count",
|
||||||
|
"Total count of translation rows processed",
|
||||||
|
metrics.total_translate_row_count.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
metrics
|
metrics
|
||||||
}
|
}
|
||||||
|
|
@ -43,4 +61,16 @@ impl AIMetrics {
|
||||||
pub fn record_stream_image_count(&self, count: u64) {
|
pub fn record_stream_image_count(&self, count: u64) {
|
||||||
self.stream_image_count.inc_by(count);
|
self.stream_image_count.inc_by(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn record_total_completion_count(&self, count: u64) {
|
||||||
|
self.total_completion_count.inc_by(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn record_total_summary_row_count(&self, count: u64) {
|
||||||
|
self.total_summary_row_count.inc_by(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn record_total_translate_row_count(&self, count: u64) {
|
||||||
|
self.total_translate_row_count.inc_by(count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue