-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.ts
92 lines (86 loc) · 2.45 KB
/
report.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { BaseEngine } from "./llm-engine/BaseEngine.ts";
import { Language, TestData } from "./types.ts";
import { Paths } from "./paths.ts";
enum STATUS {
GOOD = "✅",
BAD = "❌",
WARNING = "⚠️",
INFO = "ℹ️",
QUESTION = "❓",
SKIP = "⏩",
}
export async function report(
language: Language,
test: TestData,
model: BaseEngine,
): Promise<{ score: number; max: number }> {
let score = 0;
let max = 0;
// Report Results
const code = await checkIfExistsAndHasContent(
Paths.srcCode(language, test, model),
false,
);
const metadata = await checkIfExistsAndHasContent(
Paths.srcMetadata(language, test, model),
false,
);
const execute = await checkIfExistsAndHasContent(
Paths.executeOutput(language, test, model),
true,
);
console.log(` [Language] ${language}`);
console.log(` ${code[0]} Code ${code[1]}`);
console.log(` ${metadata[0]} Metadata ${metadata[1]}`);
console.log(` ${execute[0]} Execute ${execute[1]}`);
console.log(
` Path Source Code ${Paths.finalSrcCode(language, test, model)}`,
);
console.log(` [Done] ${test.code} @ ${model.path}`);
if (code[0] === STATUS.GOOD) score += 1;
if (metadata[0] === STATUS.GOOD) score += 1;
if (execute[0] === STATUS.GOOD) score += 3;
max += 5;
if (test.check) {
const multiplier = 3;
max += multiplier;
if (execute[0] === STATUS.GOOD) {
const check = test.check(
await Deno.readTextFile(
Paths.executeOutput(language, test, model),
),
);
score += check * multiplier;
let status = STATUS.BAD;
if (check >= 1) status = STATUS.GOOD;
else if (check > 0) status = STATUS.WARNING;
console.log(` ${status} Check [0-1] ${check}`);
} else {
console.log(
` ${STATUS.BAD} Check [0-1] (cannot check failed execution)`,
);
}
}
return { score, max };
}
async function checkIfExistsAndHasContent(
path: string,
showContent: boolean = false,
): Promise<[STATUS, string]> {
try {
await Deno.stat(path);
const content = await Deno.readTextFile(path);
if (content.trim().length > 0) {
if (content.startsWith("::ERROR::")) {
return [STATUS.BAD, content.substring(0, 100).replace(/\n/g, " ")];
}
return [
STATUS.GOOD,
showContent ? content.substring(0, 100).replace(/\n/g, " ") : "",
];
}
return [STATUS.WARNING, ""];
} catch (_) {
return [STATUS.QUESTION, ""];
}
}