Skip to content

Commit

Permalink
flatten nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
laanak08 committed Feb 20, 2025
1 parent 0d77f76 commit 7a20043
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions crates/goose-cli/src/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use async_trait::async_trait;
use chrono::Local;
use goose::config::Config;
use goose::message::Message;
use goose_bench::eval_suites::{BenchAgent, EvaluationSuiteFactory};
use goose_bench::eval_suites::{BenchAgent, EvaluationMetric, EvaluationSuiteFactory};
use goose_bench::work_dir::WorkDir;

#[async_trait]
Expand All @@ -15,6 +15,22 @@ impl BenchAgent for Session {
}
}

async fn run_eval(mut evaluation: Box<dyn BenchAgent>) -> anyhow::Result<Vec<EvaluationMetric>> {
let _ = WorkDir::work_from(format!("./{}", &evaluation.name()));
let session = build_session(None, false, Vec::new(), Vec::new()).await;
let report = evaluation.run(Box::new(session))?.await;
report
}

async fn run_suite(suite: &str, current_time: &String, current_date: &String) -> anyhow::Result<()> {
let _ = WorkDir::work_from(format!("./{}", &suite))?;
let _ = WorkDir::work_from(format!("./{}-{}", &current_date, current_time))?;
for Some(evaluation) in EvaluationSuiteFactory::create(suite) {
run_eval(evaluation)?.await;
}
Ok(())
}

pub async fn run_benchmark(suites: Vec<String>) {
let suites = EvaluationSuiteFactory::available_evaluations()
.into_iter()
Expand All @@ -29,25 +45,8 @@ pub async fn run_benchmark(suites: Vec<String>) {

let current_time = Local::now().format("%H:%M:%S").to_string();
let current_date = Local::now().format("%Y-%m-%d").to_string();
if let Ok(_) = WorkDir::work_from(format!("./benchmark-{}", &provider_name)) {
for suite in suites {
if let Ok(_) = WorkDir::work_from(format!("./{}", &suite)) {
let evaluations = match EvaluationSuiteFactory::create(suite) {
Some(evaluations) => evaluations,
None => continue,
};
if let Ok(_) = WorkDir::work_from(format!("./{}-{}", &current_date, current_time)) {
for evaluation in evaluations {
if let Ok(_) = WorkDir::work_from(format!("./{}", &evaluation.name())) {
let session = build_session(None, false, Vec::new(), Vec::new()).await;
let _ = match evaluation.run(Box::new(session)).await {
Ok(report) => report,
_ => continue,
};
}
}
}
}
}
let _ = WorkDir::work_from(format!("./benchmark-{}", &provider_name))?;
for suite in suites {
run_suite(suite, &current_time, &current_date)?.await;
}
}

0 comments on commit 7a20043

Please sign in to comment.