add-tracing
Meng Zhang 2023-05-27 22:36:34 -07:00
parent 73c67b339a
commit 5f5ddbb704
3 changed files with 8 additions and 8 deletions

View File

@ -1,4 +1,4 @@
use tracing::{info, Level};
use tracing_subscriber; use tracing_subscriber;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};

View File

@ -1,10 +1,10 @@
use tracing::{span, info, Level};
use axum::{extract::State, Json}; use axum::{extract::State, Json};
use ctranslate2_bindings::{ use ctranslate2_bindings::{
TextInferenceEngine, TextInferenceEngineCreateOptions, TextInferenceOptionsBuilder, TextInferenceEngine, TextInferenceEngineCreateOptions, TextInferenceOptionsBuilder,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::sync::Arc; use std::sync::Arc;
use tracing::{info, span, Level};
use utoipa::ToSchema; use utoipa::ToSchema;
mod languages; mod languages;
@ -45,7 +45,7 @@ pub async fn completion(
let span = span!(Level::INFO, "completion", completion_id); let span = span!(Level::INFO, "completion", completion_id);
let _enter = span.enter(); let _enter = span.enter();
info!(language=request.language, prompt=request.prompt); info!(language = request.language, prompt = request.prompt);
let options = TextInferenceOptionsBuilder::default() let options = TextInferenceOptionsBuilder::default()
.max_decoding_length(64) .max_decoding_length(64)
.sampling_temperature(0.2) .sampling_temperature(0.2)
@ -53,7 +53,7 @@ pub async fn completion(
.unwrap(); .unwrap();
let text = state.engine.inference(&request.prompt, options); let text = state.engine.inference(&request.prompt, options);
let filtered_text = languages::remove_stop_words(&request.language, &text); let filtered_text = languages::remove_stop_words(&request.language, &text);
info!(response=filtered_text); info!(response = filtered_text);
Json(CompletionResponse { Json(CompletionResponse {
id: completion_id, id: completion_id,

View File

@ -1,7 +1,7 @@
use axum::Json; use axum::Json;
use tracing::{span, info, Level};
use hyper::StatusCode; use hyper::StatusCode;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::{info};
use utoipa::ToSchema; use utoipa::ToSchema;
#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] #[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
@ -19,9 +19,9 @@ pub struct LogEventRequest {
)] )]
pub async fn log_event(Json(request): Json<LogEventRequest>) -> StatusCode { pub async fn log_event(Json(request): Json<LogEventRequest>) -> StatusCode {
info!( info!(
completion_id=request.completion_id, completion_id = request.completion_id,
event_type=request.event_type, event_type = request.event_type,
choice_index=request.choice_index choice_index = request.choice_index
); );
StatusCode::OK StatusCode::OK
} }