diff --git a/Cargo.lock b/Cargo.lock index ee59072..05b11ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -585,6 +585,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.155" @@ -662,6 +668,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -731,6 +747,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.12.3" @@ -823,13 +845,14 @@ dependencies = [ "clap_complete", "futures", "glob", - "log", "rand", "regex", "reqwest", "serde", "serde_json", "tokio", + "tracing", + "tracing-subscriber", "uuid", ] @@ -1116,6 +1139,15 @@ dependencies = [ "serde", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.2" @@ -1218,6 +1250,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -1331,9 +1373,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -1341,6 +1395,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", ] [[package]] @@ -1402,6 +1482,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vcpkg" version = "0.2.15" @@ -1512,6 +1598,28 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index d188a47..d4f5dc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,20 +3,19 @@ name = "puppet" version = "0.3.1" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] +tracing = "0" +tracing-subscriber = "0" clap = { version = "4", features = ["derive"] } clap_complete = "4" serde = { version = "1", features = ["derive", "rc"] } serde_json = "1" -log = "0" tokio = { version = "1", features = ["full"] } reqwest = { version = "0", features = ["stream"] } bytes = "1" +futures = "0" rand = "0" base64 = "0" uuid = { version = "1", features = ["v4"] } regex = "1" glob = "0" -futures = "0" diff --git a/src/azure/chatgpt.rs b/src/azure/chatgpt.rs index ccf53e8..1d9a0b9 100644 --- a/src/azure/chatgpt.rs +++ b/src/azure/chatgpt.rs @@ -11,9 +11,9 @@ use bytes::Bytes; use futures::AsyncBufReadExt; use futures::StreamExt; use futures::TryStreamExt; -use log::info; use reqwest::Response; use tokio::fs; +use tracing::info; use super::chatgpt_api::ChatCompletionChoice; use super::chatgpt_api::ChatResponse; @@ -134,8 +134,8 @@ impl ChatGPT { for result in results { self.add_message(ChatRequestMessage::new_function_response(result.id, json::to_json(&result.value)?)); } - } else if let Some(content) = message.content { - self.add_message(ChatRequestMessage::new_message(Role::Assistant, content)); + } else { + self.add_message(ChatRequestMessage::new_message(Role::Assistant, message.content.unwrap())); return Ok(()); } } @@ -168,7 +168,8 @@ impl ChatGPT { let response = request.send().await?; let status = response.status(); if status != 200 { - info!("body={}", str::from_utf8(&body)?); + let body = str::from_utf8(&body)?; + info!("body={}", body); let response_text = response.text().await?; return Err(Exception::ExternalError(format!( "failed to call azure api, status={status}, response={response_text}" @@ -207,7 +208,6 @@ async fn read_sse_response(http_response: Response) -> Result Result Result<(), Exception> { + tracing_subscriber::fmt().with_thread_ids(true).init(); let cli = Cli::parse(); match cli.command { Command::Chat(command) => command.execute().await, diff --git a/src/tts.rs b/src/tts.rs index bbad84e..b5efb43 100644 --- a/src/tts.rs +++ b/src/tts.rs @@ -1,9 +1,9 @@ use std::collections::HashMap; use std::path::Path; -use log::info; use serde::Deserialize; use tokio::fs; +use tracing::info; use crate::azure::tts::AzureTTS; use crate::gcloud::tts::GCloudTTS;