Skip to content

Commit c540ab6

Browse files
committed
fix: flag params in config file not working
1 parent a2bdda4 commit c540ab6

7 files changed

Lines changed: 25 additions & 20 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "terminal-aichat"
33
description = "A terminal AI/LLM chat tool. Extremely simple and easy to use. Using OpenAI-compatible `/v1/chat/completion` API"
44
repository = "https://github.com/slow-groovin/terminal-aichat"
55
license = "MIT"
6-
version = "0.2.4"
6+
version = "0.2.5"
77
edition = "2024"
88

99
[[bin]]

src/chat.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,25 @@ pub async fn completion(
9191
for e in errors {
9292
eprintln!("❌Error in sending openai-api request: {}", e);
9393
}
94-
94+
9595
return Err("failed to send request.".into());
9696
}
97-
renderer.render_tail_bar();
97+
if !pure {
98+
renderer.render_tail_bar();
99+
}
98100
Ok(())
99101
}
100102

101103
fn create_client(model_config: &ModelConfig) -> Client<OpenAIConfig> {
102-
let env_api_key=std::env::var("OPENAI_API_KEY");
103-
let final_api_key=match env_api_key {
104-
Ok(val)=>{
104+
let env_api_key = std::env::var("OPENAI_API_KEY");
105+
let final_api_key = match env_api_key {
106+
Ok(val) => {
105107
log_debug!("use env OPEN_API_KEY to override api-key.");
106108
val
107-
},
108-
Err(_)=>model_config.api_key.clone().unwrap_or(String::new())
109+
}
110+
Err(_) => model_config.api_key.clone().unwrap_or(String::new()),
109111
};
110-
log_debug!("final used api-key: {}",StringUtils::mask_sensitive(&final_api_key));
112+
log_debug!("final used api-key: {}", StringUtils::mask_sensitive(&final_api_key));
111113
Client::with_config(
112114
OpenAIConfig::default()
113115
.with_api_key(final_api_key)

src/cli/cli.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ use utils::logger::{self};
1313
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
1414
let cli = Cli::parse();
1515

16-
if cli.verbose {
17-
set_log_level(logger::LogLevel::Trace);
18-
}
1916
// if !cli.test.is_none() {
2017
// // test();
2118
// // return Ok(());
@@ -26,6 +23,10 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
2623
//if config file not exist, try to init and save;
2724
config_manager.try_initialize_default_configs_and_save()?;
2825

26+
27+
if config_manager.config.verbose.unwrap() {
28+
set_log_level(logger::LogLevel::Trace);
29+
}
2930
// Handle subcommands
3031
match &cli.command {
3132
Some(Commands::Set { config }) => {
@@ -228,9 +229,9 @@ async fn handle_chat_command(cli: &Cli, config_manager: &ConfigManager) -> Resul
228229
&model_config,
229230
prompt_name.to_string(),
230231
&prompt_config,
231-
cli.pure,
232-
cli.disable_stream,
233-
cli.verbose,
232+
config_manager.config.pure.unwrap(),
233+
config_manager.config.disable_stream.unwrap(),
234+
config_manager.config.verbose.unwrap(),
234235
)
235236
.await?;
236237

src/cli/response_render.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ impl ResponseRenderer {
7676
/// 渲染状态栏(固定在status_row)
7777
fn render_status_bar(config: &RenderConfig) {
7878
println!(
79-
"{} model: {}({}) prompt: {} {}",
80-
" > ".on_dark_green(),
79+
"{} {}: {}({}) {}: {} {}",
80+
" > ".on_green(),
81+
"model".dark_green().bold(),
8182
config.model_config_name.as_str().blue().bold(),
8283
config.model_name.as_str().cyan().bold(),
84+
"prompt".dark_green().bold(),
8385
config.prompt_config_name.as_str().blue().bold(),
8486
"".on_dark_green()
8587
);

src/cli/structs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clap::{Parser, Subcommand};
33
#[derive(Parser)]
44
#[command(
55
name = "aichat",
6-
version = "0.2.4",
6+
version = "0.2.5",
77
about = r#"
88
A terminal AI/LLM chat tool
99

src/config/manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{fs, io};
1515

1616
pub struct ConfigManager {
1717
///merged config (file+cli)
18-
config: Config,
18+
pub config: Config,
1919
file_config: Config,
2020
config_path: PathBuf,
2121
crypto_manager: CryptoManager,

0 commit comments

Comments
 (0)