move tracing to serve.main

add-tracing
Meng Zhang 2023-05-27 22:54:49 -07:00
parent afc8455a42
commit bdb8b9447f
4 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,4 @@
use tracing_subscriber;
use clap::{Parser, Subcommand};
#[derive(Parser)]
@ -21,8 +19,6 @@ mod serve;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let cli = Cli::parse();
match &cli.command {
Commands::Serve(args) => {

View File

@ -4,7 +4,7 @@ use ctranslate2_bindings::{
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tracing::{info, span, Level};
use tracing::{trace, span, Level};
use utoipa::ToSchema;
mod languages;
@ -41,10 +41,10 @@ pub async fn completion(
State(state): State<Arc<CompletionState>>,
Json(request): Json<CompletionRequest>,
) -> Json<CompletionResponse> {
let span = span!(Level::INFO, "completion");
let span = span!(Level::TRACE, "completion");
let _enter = span.enter();
info!(language = request.language, prompt = request.prompt);
trace!(language = request.language, prompt = request.prompt);
let options = TextInferenceOptionsBuilder::default()
.max_decoding_length(64)
.sampling_temperature(0.2)
@ -52,7 +52,7 @@ pub async fn completion(
.unwrap();
let text = state.engine.inference(&request.prompt, options);
let filtered_text = languages::remove_stop_words(&request.language, &text);
info!(response = filtered_text);
trace!(response = filtered_text);
Json(CompletionResponse {
id: format!("cmpl-{}", uuid::Uuid::new_v4()),
created: timestamp(),

View File

@ -0,0 +1,3 @@
pub fn init() {
tracing_subscriber::fmt().init()
}

View File

@ -14,6 +14,7 @@ use utoipa_swagger_ui::SwaggerUi;
mod completions;
mod events;
mod logging;
#[derive(OpenApi)]
#[openapi(
@ -84,6 +85,8 @@ pub struct ServeArgs {
}
pub async fn main(args: &ServeArgs) -> Result<(), Error> {
logging::init();
let device = format!("{}", args.device);
let options = TextInferenceEngineCreateOptionsBuilder::default()
.model_path(