Skip to content

Commit

Permalink
bugfix the flattening
Browse files Browse the repository at this point in the history
  • Loading branch information
laanak08 committed Feb 20, 2025
1 parent 7a20043 commit d76f8b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 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, EvaluationMetric, EvaluationSuiteFactory};
use goose_bench::eval_suites::{BenchAgent, Evaluation, EvaluationMetric, EvaluationSuiteFactory};
use goose_bench::work_dir::WorkDir;

#[async_trait]
Expand All @@ -15,23 +15,31 @@ 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_eval(evaluation: Box<dyn Evaluation>) -> anyhow::Result<Vec<EvaluationMetric>> {
if let Ok(_) = 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
}else{
Ok(vec![])
}
}

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;
if let Ok(_) = WorkDir::work_from(format!("./{}", &suite)) {
if let Ok(_) = WorkDir::work_from(format!("./{}-{}", &current_date, current_time)) {
if let Some(evals) = EvaluationSuiteFactory::create(suite) {
for eval in evals {
run_eval(eval).await?;
}
}
}
}

Ok(())
}

pub async fn run_benchmark(suites: Vec<String>) {
pub async fn run_benchmark(suites: Vec<String>) -> anyhow::Result<()> {
let suites = EvaluationSuiteFactory::available_evaluations()
.into_iter()
.filter(|&s| suites.contains(&s.to_string()))
Expand All @@ -45,8 +53,10 @@ 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();
let _ = WorkDir::work_from(format!("./benchmark-{}", &provider_name))?;
for suite in suites {
run_suite(suite, &current_time, &current_date)?.await;
if let Ok(_) = WorkDir::work_from(format!("./benchmark-{}", &provider_name)) {
for suite in suites {
run_suite(suite, &current_time, &current_date).await?;
}
}
Ok(())
}
2 changes: 1 addition & 1 deletion crates/goose-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async fn main() -> Result<()> {
} else {
suites
};
run_benchmark(suites).await;
let _ = run_benchmark(suites).await;
return Ok(());
}
None => {
Expand Down

0 comments on commit d76f8b4

Please sign in to comment.