use std::{
fmt::{self, Display},
str::FromStr,
};
use clap::{command, Parser, Subcommand};
pub const DEFAULT_LLM: Model = Model::Gpt4o;
pub const DEFAULT_QUERY: &str =
"Here is the program output. If there was an error, concisely explain how it can be fixed.
If there was no error, concisely summarize the output.";
pub const NEW_COMMAND_MSG: &str = "<<<wtg:cmd-end>>>";
#[derive(Debug, Clone, Copy)]
pub enum Model {
Gpt4o,
Gpt4oMini,
O3Mini,
}
impl Model {
pub fn all_models() -> Vec<String> {
[Model::Gpt4o, Model::Gpt4oMini, Model::O3Mini]
.iter()
.map(|m| m.to_string())
.collect()
}
}
impl FromStr for Model {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"gpt-4o" => Ok(Model::Gpt4o),
"gpt4o" => Ok(Model::Gpt4o),
"gpt-4o-mini" => Ok(Model::Gpt4oMini),
"gpt4o-mini" => Ok(Model::Gpt4oMini),
"o3-mini" => Ok(Model::O3Mini),
"o3mini" => Ok(Model::O3Mini),
_ => Err(format!(
"Invalid model: {}. Choose from: gpt-4o, gpt-4o-mini, o3-mini.",
s
)),
}
}
}
impl Display for Model {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Model::Gpt4o => write!(f, "gpt-4o"),
Model::Gpt4oMini => write!(f, "gpt-4o-mini"),
Model::O3Mini => write!(f, "o3-mini"),
}
}
}
#[derive(Debug, Parser)]
#[command(author, version, about)]
pub struct Args {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Debug, Subcommand)]
pub enum Commands {
#[command(alias = "s")]
Start { logfile: String },
#[command(alias = "q")]
Query {
#[arg(short, long)]
logfile: Option<String>,
#[arg(short, long)]
prompt: Option<String>,
#[arg(short, long)]
model: Option<Model>,
},
#[command(alias = "c")]
Chat {
#[arg(short, long)]
logfile: Option<String>,
#[arg(short, long)]
model: Option<Model>,
},
}