eval-genius
Version:
eval-genius enables evals of arbitrary async code. It is generally intended for making multiple assertions on outputs which are generated nondeterministically. These assertions can be used to score algorithms on their effectiveness.
60 lines (59 loc) • 2.11 kB
JavaScript
import { JWT as l } from "google-auth-library";
import { GoogleSpreadsheet as E } from "google-spreadsheet";
import { drive as A } from "@googleapis/drive";
const m = () => {
const r = new l({
// env var values here are copied from service account credentials generated by google
// see "Authentication" section in docs for more info
email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
key: process.env.GOOGLE_PRIVATE_KEY?.replace(/\\n/g, `
`),
subject: process.env.MY_GOOGLE_ACCOUNT_EMAIL,
scopes: [
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive.file"
]
}), d = async ({ title: e, folderId: t }) => {
const s = await E.createNewSpreadsheetDocument(r, {
title: e
});
return t && await A({ version: "v3", auth: r }).files.update({
fileId: s.spreadsheetId,
addParents: t
}), s;
}, c = ({ spreadsheetId: e }) => new E(e, r), h = (e) => process.env.EVAL_SPREADSHEET_ID ? { spreadsheetId: process.env.EVAL_SPREADSHEET_ID } : e, w = async (e) => {
const t = h(e), s = await ("spreadsheetId" in t ? c(t) : d(t));
return process.env.EVAL_SPREADSHEET_ID = s.spreadsheetId, s;
}, S = async () => {
const e = process.env.EVAL_SPREADSHEET_ID;
if (!e)
throw new Error("process.env.EVAL_SPREADSHEET_ID was not found");
const t = c({ spreadsheetId: e });
return await t.loadInfo(), t;
};
let o = [];
return {
init: w,
start: async ({ title: e, fields: t }) => {
const s = await S(), i = s.sheetsByTitle[e] || await s.addSheet({ title: e, headerValues: t });
s.sheetsByTitle.Sheet1?.delete();
const p = async () => {
if (!o.length) return;
const n = o;
o = [], await i.addRows(n);
};
return {
report: async ({ result: n }) => {
const _ = Object.fromEntries(
Object.entries(n).map((a) => a).map(([a, u]) => [a, u ?? ""])
);
o.push(_), o.length >= 100 && await p();
},
flush: p
};
}
};
};
export {
m as GoogleSheetsExporter
};