move tracing to serve.main
parent
afc8455a42
commit
bdb8b9447f
|
|
@ -1,6 +1,4 @@
|
||||||
|
|
||||||
use tracing_subscriber;
|
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|
@ -21,8 +19,6 @@ mod serve;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
tracing_subscriber::fmt::init();
|
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Commands::Serve(args) => {
|
Commands::Serve(args) => {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use ctranslate2_bindings::{
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tracing::{info, span, Level};
|
use tracing::{trace, span, Level};
|
||||||
use utoipa::ToSchema;
|
use utoipa::ToSchema;
|
||||||
|
|
||||||
mod languages;
|
mod languages;
|
||||||
|
|
@ -41,10 +41,10 @@ pub async fn completion(
|
||||||
State(state): State<Arc<CompletionState>>,
|
State(state): State<Arc<CompletionState>>,
|
||||||
Json(request): Json<CompletionRequest>,
|
Json(request): Json<CompletionRequest>,
|
||||||
) -> Json<CompletionResponse> {
|
) -> Json<CompletionResponse> {
|
||||||
let span = span!(Level::INFO, "completion");
|
let span = span!(Level::TRACE, "completion");
|
||||||
let _enter = span.enter();
|
let _enter = span.enter();
|
||||||
|
|
||||||
info!(language = request.language, prompt = request.prompt);
|
trace!(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)
|
||||||
|
|
@ -52,7 +52,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);
|
trace!(response = filtered_text);
|
||||||
Json(CompletionResponse {
|
Json(CompletionResponse {
|
||||||
id: format!("cmpl-{}", uuid::Uuid::new_v4()),
|
id: format!("cmpl-{}", uuid::Uuid::new_v4()),
|
||||||
created: timestamp(),
|
created: timestamp(),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
pub fn init() {
|
||||||
|
tracing_subscriber::fmt().init()
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ use utoipa_swagger_ui::SwaggerUi;
|
||||||
|
|
||||||
mod completions;
|
mod completions;
|
||||||
mod events;
|
mod events;
|
||||||
|
mod logging;
|
||||||
|
|
||||||
#[derive(OpenApi)]
|
#[derive(OpenApi)]
|
||||||
#[openapi(
|
#[openapi(
|
||||||
|
|
@ -84,6 +85,8 @@ pub struct ServeArgs {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn main(args: &ServeArgs) -> Result<(), Error> {
|
pub async fn main(args: &ServeArgs) -> Result<(), Error> {
|
||||||
|
logging::init();
|
||||||
|
|
||||||
let device = format!("{}", args.device);
|
let device = format!("{}", args.device);
|
||||||
let options = TextInferenceEngineCreateOptionsBuilder::default()
|
let options = TextInferenceEngineCreateOptionsBuilder::default()
|
||||||
.model_path(
|
.model_path(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue