Skip to content

Commit 4f35c8c

Browse files
committed
Output eval results as a csv
1 parent 74b4b5b commit 4f35c8c

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

packages/evals/component_retrieval/evaluator.mjs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import "dotenv/config";
44
import fs from "fs/promises";
55
import path from "path";
66
import { diff } from "json-diff";
7+
import { json2csv } from "json-2-csv";
78

89
const GREEN_CHECK = "\x1b[32m✔\x1b[0m";
910
const RED_CROSS = "\x1b[31m✖\x1b[0m";
1011

1112
let totalEvals = 0;
1213
let totalSuccesses = 0;
14+
let apiResults = []
1315

1416
const apiHost = process.env.API_BASE_URL || "https://api.pipedream.com";
1517

@@ -41,7 +43,23 @@ function customDiff(original, updated, oldLabel = "expected", newLabel = "actual
4143
return replaceLabels(result);
4244
}
4345

46+
async function exportToCsv(filePath, limit, threshold) {
47+
const csvData = json2csv(apiResults, {
48+
fields: ["query", "evalTriggers", "apiTriggers", "evalActions", "apiActions", "success"]
49+
});
50+
const parts = filePath.split("/")
51+
const path = parts[parts.length -1].split(".json")[0]
52+
await fs.writeFile(`./csv/${path}-${limit}-${threshold}.csv`, csvData);
53+
}
54+
55+
function arrayToString(items) {
56+
if (items) return items.join(",")
57+
return ""
58+
}
59+
4460
async function processEvalFile(filePath) {
61+
const limit = 3
62+
const threshold = 0.65
4563
try {
4664
const content = await fs.readFile(filePath, "utf-8");
4765
const evalData = JSON.parse(content);
@@ -53,7 +71,7 @@ async function processEvalFile(filePath) {
5371
} = evalTest;
5472

5573
const encodedQuery = encodeURIComponent(query);
56-
const apiUrl = `${apiHost}/v1/components/search?query=${encodedQuery}`;
74+
const apiUrl = `${apiHost}/v1/components/search?query=${encodedQuery}&similarity_threshold=${threshold}&limit=${limit}`;
5775

5876
const response = await fetch(apiUrl, {
5977
headers: {
@@ -63,16 +81,20 @@ async function processEvalFile(filePath) {
6381
});
6482
const apiData = await response.json();
6583

84+
6685
// Compare actual and expected
6786
const apiTriggers = apiData?.triggers ?? [];
6887
const apiActions = apiData?.actions ?? [];
88+
6989
const triggersMatch =
7090
JSON.stringify(apiTriggers.sort()) === JSON.stringify(triggers.sort());
7191
const actionsMatch =
7292
JSON.stringify(apiActions.sort()) === JSON.stringify(actions.sort());
7393

94+
let success = false
7495
if (triggersMatch && actionsMatch) {
7596
totalSuccesses++;
97+
success = true
7698
console.log(`${GREEN_CHECK} Success for query: "${query}"`);
7799
} else {
78100
console.log(`${RED_CROSS} Failure for query: "${query}"`);
@@ -82,10 +104,21 @@ async function processEvalFile(filePath) {
82104
actions,
83105
}, apiData));
84106
}
107+
108+
const record = {
109+
query: query.replace("\"", ""),
110+
apiTriggers: arrayToString(apiTriggers),
111+
apiActions: arrayToString(apiActions),
112+
evalTriggers: arrayToString(triggers),
113+
evalActions: arrayToString(actions),
114+
success: success
115+
};
116+
apiResults.push(record)
85117
}
86118
} catch (error) {
87119
console.error(`Error processing file ${filePath}:`, error.message);
88120
}
121+
await exportToCsv(filePath, limit, threshold)
89122
}
90123

91124
async function main() {

packages/evals/component_retrieval/package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/evals/component_retrieval/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "evaluator.mjs",
66
"dependencies": {
77
"dotenv": "^16.4.5",
8+
"json-2-csv": "^5.5.6",
89
"json-diff": "^1.0.6"
910
}
1011
}

0 commit comments

Comments
 (0)