Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default for model not applied to command line #16

Open
MalteT opened this issue Dec 14, 2023 · 1 comment
Open

Default for model not applied to command line #16

MalteT opened this issue Dec 14, 2023 · 1 comment

Comments

@MalteT
Copy link

MalteT commented Dec 14, 2023

When omitting --model from the command line (I have no config file), I get the following error:

error: the following required arguments were not provided:
  --model <MODEL>

Usage: heygpt --model <MODEL> --api-key <API_KEY> --api-base-url <API_BASE_URL> [PROMPT]...

For more information, try '--help'.

despite these

heygpt/src/main.rs

Lines 33 to 35 in 3be31cb

#[default(String::from("gpt-3.5-turbo"))]
#[arg(long)]
pub model: String,

I've never worked with ClapSerde, and it looks like an issue on their part, but the following dublication fixes it for me.

diff --git a/src/main.rs b/src/main.rs
index 7263c4c..f0ba36d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -31,7 +31,7 @@ struct Options {
 
     /// The model to query (default: gpt-3.5-turbo)
     #[default(String::from("gpt-3.5-turbo"))]
-    #[arg(long)]
+    #[arg(long, default_value = "gpt-3.5-turbo")]
     pub model: String,
 
     /// OpenAI API key

Thanks for your work!

@fuyufjh
Copy link
Owner

fuyufjh commented Mar 18, 2024

Right. It's the problem of upstream ClapSerde. However, the changes proposed above may cause another problem - the value of "model" in config file (if exists) will always be overridden by "gpt-3.5-turbo".

To work around the problem, the only solution I can think of is to write lots of boilerplate code to manually parse arguments, such as

let opts_from_file = { ...read opts... }
...
clap::Arg::new("model")
    .long("model")
    .default_value(opts_from_file.model)

That means we can't use the macro to derive clap args anymore.

Even worse, we need to maintain 2 copies of arguments: one as the code above, and one as a struct for serde. It's a bit too heavy just for argument parsing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants