Skip to content

Commit

Permalink
fix: the command arctl gen_test_dataset recursively reads files
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy committed Jan 23, 2024
1 parent c51099f commit e82f83c
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions pkg/arctl/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/csv"
"fmt"
"io"
"io/fs"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -142,19 +143,20 @@ func EvalGenTestDataset(home *string, namespace *string, appName *string) *cobra
}

// read files from input directory
files, err := os.ReadDir(inputDir)
if err != nil {
log.Fatal(err)
}
for _, file := range files {
if file.IsDir() || filepath.Ext(file.Name()) != ".csv" || strings.HasPrefix(file.Name(), "ragas-") {
continue
err = filepath.WalkDir(inputDir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
log.Fatal(err)
return err
}
if d.IsDir() || filepath.Ext(d.Name()) != ".csv" || strings.HasPrefix(d.Name(), "ragas-") {
return nil
}
var output evaluation.Output
switch outputMethod {
case "csv":
outputCSVFile, err := os.Create(filepath.Join(inputDir, fmt.Sprintf("ragas-%s", file.Name())))
outputCSVFile, err := os.Create(strings.Replace(path, d.Name(), fmt.Sprintf("ragas-%s", d.Name()), 1))
if err != nil {
log.Fatal(err)
return err
}
defer outputCSVFile.Close()
Expand All @@ -168,14 +170,21 @@ func EvalGenTestDataset(home *string, namespace *string, appName *string) *cobra
}
// read file from dataset
err = GenDatasetOnSingleFile(ctx, kubeClient, app,
filepath.Join(inputDir, file.Name()),
path,
evaluation.WithQuestionColumn(questionColumn),
evaluation.WithGroundTruthsColumn(groundTruthsColumn),
evaluation.WithOutput(output),
)
if err != nil {
log.Fatal(err)
return err
}
return nil
})

if err != nil {
log.Fatal(err)
return err
}

return nil
Expand Down

0 comments on commit e82f83c

Please sign in to comment.