heygpt icon indicating copy to clipboard operation
heygpt copied to clipboard

Default for `model` not applied to command line

Open MalteT opened this issue 1 year ago • 1 comments

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 https://github.com/fuyufjh/heygpt/blob/3be31cb78971380de02f8f370658be931f1c645c/src/main.rs#L33-L35

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!

MalteT avatar Dec 14 '23 09:12 MalteT

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...

fuyufjh avatar Mar 18 '24 15:03 fuyufjh