From f491dfd2431812402528e7777e95e02328992325 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Sun, 15 Mar 2026 21:34:23 +0100 Subject: [PATCH] refactor: use plain string model names --- src/cli.rs | 5 +++-- src/main.rs | 42 ++++++++++-------------------------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 8c1ecbd..b9f6804 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -29,7 +29,7 @@ pub fn clap() -> clap::Command { .env("OPENAI_KEY") .hide_env_values(true) .required(true) - .value_parser(clap::value_parser!(String)) + .value_parser(value_parser!(String)) .num_args(1), ) .arg( @@ -38,7 +38,8 @@ pub fn clap() -> clap::Command { .long("model") .help("which LLM to use") .env("PLEASE_MODEL") - .value_parser(value_parser!(super::Model)), + .default_value("gpt-5") + .value_parser(value_parser!(String)), ) .arg( Arg::new("temp") diff --git a/src/main.rs b/src/main.rs index b475b58..0c3797a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::error::Error; use std::io::{stdout, Read, Write}; use anyhow::anyhow; -use clap::{ArgMatches, ValueEnum}; +use clap::ArgMatches; use openai::{ chat::{ChatCompletion, ChatCompletionDelta, ChatCompletionMessage, ChatCompletionMessageRole}, @@ -13,23 +13,6 @@ use tokio::sync::mpsc::Receiver; mod cli; -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Default)] -pub(crate) enum Model { - /// Use gpt-3.5-turbo - #[default] - #[clap(name = "gpt-3.5-turbo", alias = "gpt-3")] - GPT3_5, - /// Use gpt-4 - #[clap(name = "gpt-4")] - GPT4, - /// Use gpt-4o - #[clap(name = "gpt-4o")] - GPT4o, - /// Use gpt-4o-mini - #[clap(name = "gpt-4o-mini")] - GPT4oMini, -} - #[tokio::main] async fn main() { let matches = cli::clap().get_matches(); @@ -51,9 +34,7 @@ async fn main() { } async fn handle_task(matches: &ArgMatches) -> Result<(), Box> { - let model: Model = matches - .get_one::("model") - .map_or_else(Model::default, |m| *m); + let model = matches.get_one::("model").unwrap(); let task: Vec = matches .get_many("task") @@ -69,7 +50,7 @@ async fn handle_task(matches: &ArgMatches) -> Result<(), Box> { return Err(anyhow!("running on tty, no task given").into()); } prompt = "You are an assistant returning Linux shell commands that accomplish the following task. Don't add explanations or notes.".to_string(); - openai_request(model, &prompt, &task, temperature).await?; + openai_request(&model, &prompt, &task, temperature).await?; } else { if task.is_empty() { task.push_str("Please fix this."); @@ -81,14 +62,14 @@ async fn handle_task(matches: &ArgMatches) -> Result<(), Box> { std::io::stdin().read_to_string(&mut buffer).unwrap(); - openai_request(model, &prompt, &buffer, temperature).await?; + openai_request(&model, &prompt, &buffer, temperature).await?; } Ok(()) } async fn openai_request( - model: Model, + model: &str, prompt: &str, task: &str, temperature: f32, @@ -113,14 +94,11 @@ async fn openai_request( tool_calls: Some(Vec::new()), }); - let chat_stream = ChatCompletionDelta::builder( - model.to_possible_value().unwrap().get_name(), - messages.clone(), - ) - .credentials(credentials) - .temperature(temperature) - .create_stream() - .await?; + let chat_stream = ChatCompletionDelta::builder(model, messages.clone()) + .credentials(credentials) + .temperature(temperature) + .create_stream() + .await?; listen_for_tokens(chat_stream).await; Ok(())