Skip to content

Commit

Permalink
feat(ai-test): add --no-subscription flag (#413)
Browse files Browse the repository at this point in the history
* feat(ai-test): add --no-subscription flag

* chore(ai-test): document args
  • Loading branch information
caugner authored Feb 22, 2024
1 parent 5a307ca commit e6874e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
7 changes: 4 additions & 3 deletions ai-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ To understand how this tool works, run: `cargo run -p ai-test -- test --help`
Usage: ai-test test [OPTIONS]
Options:
-p, --path <PATH>
-o, --out <OUT>
-h, --help Print help
-p, --path <PATH> Path to YAML file with list of lists (initial question + follow-up questions)
-o, --out <OUT> Path to directory to write the test results as `1.json`, `1.md`, etc
--no-subscription Perform test as free Core user without subscription
-h, --help Print help
```

For example, to request answers for all questions in the [prompts.yaml](./data/prompts.yaml) file, run (from the repository root):
Expand Down
4 changes: 3 additions & 1 deletion ai-test/src/ai_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl Storage {
pub async fn ai_help_all(
path: Option<impl AsRef<Path>>,
out: impl AsRef<Path>,
no_subscription: bool,
) -> Result<(), Error> {
let out = &out;
std::fs::create_dir_all(out)?;
Expand Down Expand Up @@ -96,7 +97,8 @@ pub async fn ai_help_all(
})
.collect();
if let Some(req) =
prepare_ai_help_req(openai_client, supabase_pool, true, messages).await?
prepare_ai_help_req(openai_client, supabase_pool, !no_subscription, messages)
.await?
{
let mut res = openai_client.chat().create(req.req.clone()).await?;
let res = res.choices.pop().map(|res| res.message);
Expand Down
13 changes: 11 additions & 2 deletions ai-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
Test {
/// Path to YAML file with list of lists (initial question + follow-up questions).
#[arg(short, long)]
path: Option<PathBuf>,
/// Path to directory to write the test results as `1.json`, `1.md`, etc.
#[arg(short, long)]
out: Option<PathBuf>,
/// Perform test as free Core user without subscription.
#[arg(long, action)]
no_subscription: bool,
},
}

Expand All @@ -39,9 +44,13 @@ async fn main() -> Result<(), Error> {

let cli = Cli::parse();
match cli.command {
Commands::Test { path, out } => {
Commands::Test {
path,
out,
no_subscription,
} => {
let out = out.unwrap_or_else(|| PathBuf::from("/tmp/test"));
ai_help_all(path, out).await?;
ai_help_all(path, out, no_subscription).await?;
}
}
Ok(())
Expand Down

0 comments on commit e6874e6

Please sign in to comment.