@autobe/benchmark 0.30.3 → 0.30.4-dev.20260324

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,176 +1,176 @@
1
- import {
2
- AutoBeExampleProject,
3
- AutoBePhase,
4
- IAutoBePlaygroundBenchmark,
5
- IAutoBePlaygroundReplay,
6
- } from "@autobe/interface";
7
- import { StringUtil } from "@autobe/utils";
8
-
9
- import { AutoBeExampleStorage } from "../example/AutoBeExampleStorage";
10
-
11
- export namespace AutoBeReplayDocumentation {
12
- export const readme = (experiments: IAutoBePlaygroundBenchmark[]): string => {
13
- return StringUtil.trim`
14
- # AutoBe Generated Examples
15
-
16
- ## Benchmark
17
-
18
- AI Model | Success | Score | FCSR | Status
19
- :--------|---------|------:|-----:|:------:
20
- ${experiments
21
- .map((e) =>
22
- [
23
- `[\`${AutoBeExampleStorage.slugModel(
24
- e.vendor,
25
- false,
26
- )}\`](#${AutoBeExampleStorage.slugModel(e.vendor, false)
27
- .replaceAll("/", "")
28
- .replaceAll(".", "")})`,
29
- e.replays.filter((r) => r.realize?.success === true).length,
30
- e.score.aggregate,
31
- (() => {
32
- const [x, y] = e.replays
33
- .map((r) => r.aggregates.total.metric)
34
- .map((m) => [m.success, m.attempt])
35
- .reduce((a, b) => [a[0] + b[0], a[1] + b[1]], [0, 0]);
36
- return y === 0 ? "0%" : Math.floor((x / y) * 100) + "%";
37
- })(),
38
- e.emoji,
39
- ].join(" | "),
40
- )
41
- .join("\n")}
42
-
43
- - FCSR: Function Calling Success Rate
44
- - Status:
45
- - 🟢: All projects completed successfully
46
- - 🟡: Some projects failed
47
- - ❌: All projects failed or not executed
48
-
49
- ${experiments.map(vendor).join("\n\n\n")}
50
- `;
51
- };
52
-
53
- const vendor = (exp: IAutoBePlaygroundBenchmark): string => {
54
- const row = (project: AutoBeExampleProject): string => {
55
- const found = exp.replays.find((r) => r.project === project);
56
- if (found === undefined)
57
- return `\`${project}\` | 0 | ❌ | ❌ | ❌ | ❌ | ❌`;
58
- const phase = (
59
- state: IAutoBePlaygroundReplay.IPhaseState | null,
60
- ): string => {
61
- if (state === null) return "❌";
62
- else if (state.success === false) return "🟡";
63
- else return "🟢";
64
- };
65
- return [
66
- `[\`${found.project}\`](./${exp.vendor}/${found.project}/)`,
67
- // biome-ignore lint: intended
68
- (exp.score as any)[project],
69
- phase(found.analyze),
70
- phase(found.database),
71
- phase(found.interface),
72
- phase(found.test),
73
- phase(found.realize),
74
- ].join(" | ");
75
- };
76
- return StringUtil.trim`
77
- ## \`${exp.vendor}\`
78
-
79
- Project | Score | Analyze | Prisma | Interface | Test | Realize
80
- :-------|------:|:-------:|:------:|:----------|:----:|:-------:
81
- ${row("todo")}
82
- ${row("bbs")}
83
- ${row("reddit")}
84
- ${row("shopping")}
85
-
86
- ${exp.replays
87
- .map((r) =>
88
- project({
89
- replay: r,
90
- // biome-ignore lint: intended
91
- score: (exp.score as any)[r.project],
92
- }),
93
- )
94
- .join("\n\n\n")}
95
- `;
96
- };
97
-
98
- const project = (props: {
99
- replay: IAutoBePlaygroundReplay.ISummary;
100
- score: number;
101
- }): string => {
102
- const phase = (key: AutoBePhase): string => {
103
- const title: string = key.charAt(0).toUpperCase() + key.slice(1);
104
- const state: IAutoBePlaygroundReplay.IPhaseState | null =
105
- props.replay[key];
106
- if (state === null) return [`⚪ ${title}`, "", "", "", ""].join(" | ");
107
- return [
108
- `${state.success === true ? "🟢" : Object.keys(state.commodity).length ? "🟡" : "🔴"} ${title}`,
109
- Object.entries(state.commodity)
110
- .map(([key, value]) => `\`${key}\`: ${value}`)
111
- .join(", "),
112
- formatTokens(state.aggregates.total.tokenUsage.total),
113
- formatElapsedTime(state.elapsed),
114
- Math.floor(
115
- (state.aggregates.total.metric.success /
116
- state.aggregates.total.metric.attempt) *
117
- 100,
118
- ) + "%",
119
- ].join(" | ");
120
- };
121
- return StringUtil.trim`
122
- ### \`${props.replay.vendor}\` - \`${props.replay.project}\`
123
-
124
- - Source Code: ${`[\`${AutoBeExampleStorage.slugModel(
125
- props.replay.vendor,
126
- false,
127
- )}/${props.replay.project}\`](./${AutoBeExampleStorage.slugModel(
128
- props.replay.vendor,
129
- false,
130
- )}/${props.replay.project}/)`}
131
- - Score: ${props.score}
132
- - Elapsed Time: ${formatElapsedTime(props.replay.elapsed)}
133
- - Token Usage: ${formatTokens(
134
- props.replay.aggregates.total.tokenUsage.total,
135
- )}
136
- - Function Calling Success Rate: ${(
137
- (props.replay.aggregates.total.metric.success /
138
- props.replay.aggregates.total.metric.attempt) *
139
- 100
140
- ).toFixed(2)}%
141
-
142
- Phase | Generated | Token Usage | Elapsed Time | FCSR
143
- :-----|:----------|------------:|-------------:|------:
144
- ${(["analyze", "database", "interface", "test", "realize"] as const)
145
- .map((key) => phase(key))
146
- .join("\n")}
147
- `;
148
- };
149
- }
150
-
151
- function formatElapsedTime(ms: number): string {
152
- const seconds = Math.floor(ms / 1000);
153
- const minutes = Math.floor(seconds / 60);
154
- const hours = Math.floor(minutes / 60);
155
-
156
- const s = seconds % 60;
157
- const m = minutes % 60;
158
- const h = hours;
159
-
160
- if (h > 0) {
161
- return `${h}h ${m}m ${s}s`;
162
- } else if (m > 0) {
163
- return `${m}m ${s}s`;
164
- } else {
165
- return `${s}s`;
166
- }
167
- }
168
-
169
- function formatTokens(num: number): string {
170
- if (num >= 1000000) {
171
- return `${(num / 1000000).toFixed(2)}M`;
172
- } else if (num >= 1000) {
173
- return `${(num / 1000).toFixed(1)}K`;
174
- }
175
- return num.toString();
176
- }
1
+ import {
2
+ AutoBeExampleProject,
3
+ AutoBePhase,
4
+ IAutoBePlaygroundBenchmark,
5
+ IAutoBePlaygroundReplay,
6
+ } from "@autobe/interface";
7
+ import { StringUtil } from "@autobe/utils";
8
+
9
+ import { AutoBeExampleStorage } from "../example/AutoBeExampleStorage";
10
+
11
+ export namespace AutoBeReplayDocumentation {
12
+ export const readme = (experiments: IAutoBePlaygroundBenchmark[]): string => {
13
+ return StringUtil.trim`
14
+ # AutoBe Generated Examples
15
+
16
+ ## Benchmark
17
+
18
+ AI Model | Success | Score | FCSR | Status
19
+ :--------|---------|------:|-----:|:------:
20
+ ${experiments
21
+ .map((e) =>
22
+ [
23
+ `[\`${AutoBeExampleStorage.slugModel(
24
+ e.vendor,
25
+ false,
26
+ )}\`](#${AutoBeExampleStorage.slugModel(e.vendor, false)
27
+ .replaceAll("/", "")
28
+ .replaceAll(".", "")})`,
29
+ e.replays.filter((r) => r.realize?.success === true).length,
30
+ e.score.aggregate,
31
+ (() => {
32
+ const [x, y] = e.replays
33
+ .map((r) => r.aggregates.total.metric)
34
+ .map((m) => [m.success, m.attempt])
35
+ .reduce((a, b) => [a[0] + b[0], a[1] + b[1]], [0, 0]);
36
+ return y === 0 ? "0%" : Math.floor((x / y) * 100) + "%";
37
+ })(),
38
+ e.emoji,
39
+ ].join(" | "),
40
+ )
41
+ .join("\n")}
42
+
43
+ - FCSR: Function Calling Success Rate
44
+ - Status:
45
+ - 🟢: All projects completed successfully
46
+ - 🟡: Some projects failed
47
+ - ❌: All projects failed or not executed
48
+
49
+ ${experiments.map(vendor).join("\n\n\n")}
50
+ `;
51
+ };
52
+
53
+ const vendor = (exp: IAutoBePlaygroundBenchmark): string => {
54
+ const row = (project: AutoBeExampleProject): string => {
55
+ const found = exp.replays.find((r) => r.project === project);
56
+ if (found === undefined)
57
+ return `\`${project}\` | 0 | ❌ | ❌ | ❌ | ❌ | ❌`;
58
+ const phase = (
59
+ state: IAutoBePlaygroundReplay.IPhaseState | null,
60
+ ): string => {
61
+ if (state === null) return "❌";
62
+ else if (state.success === false) return "🟡";
63
+ else return "🟢";
64
+ };
65
+ return [
66
+ `[\`${found.project}\`](./${exp.vendor}/${found.project}/)`,
67
+ // biome-ignore lint: intended
68
+ (exp.score as any)[project],
69
+ phase(found.analyze),
70
+ phase(found.database),
71
+ phase(found.interface),
72
+ phase(found.test),
73
+ phase(found.realize),
74
+ ].join(" | ");
75
+ };
76
+ return StringUtil.trim`
77
+ ## \`${exp.vendor}\`
78
+
79
+ Project | Score | Analyze | Prisma | Interface | Test | Realize
80
+ :-------|------:|:-------:|:------:|:----------|:----:|:-------:
81
+ ${row("todo")}
82
+ ${row("reddit")}
83
+ ${row("shopping")}
84
+ ${row("erp")}
85
+
86
+ ${exp.replays
87
+ .map((r) =>
88
+ project({
89
+ replay: r,
90
+ // biome-ignore lint: intended
91
+ score: (exp.score as any)[r.project],
92
+ }),
93
+ )
94
+ .join("\n\n\n")}
95
+ `;
96
+ };
97
+
98
+ const project = (props: {
99
+ replay: IAutoBePlaygroundReplay.ISummary;
100
+ score: number;
101
+ }): string => {
102
+ const phase = (key: AutoBePhase): string => {
103
+ const title: string = key.charAt(0).toUpperCase() + key.slice(1);
104
+ const state: IAutoBePlaygroundReplay.IPhaseState | null =
105
+ props.replay[key];
106
+ if (state === null) return [`⚪ ${title}`, "", "", "", ""].join(" | ");
107
+ return [
108
+ `${state.success === true ? "🟢" : Object.keys(state.commodity).length ? "🟡" : "🔴"} ${title}`,
109
+ Object.entries(state.commodity)
110
+ .map(([key, value]) => `\`${key}\`: ${value}`)
111
+ .join(", "),
112
+ formatTokens(state.aggregates.total.tokenUsage.total),
113
+ formatElapsedTime(state.elapsed),
114
+ Math.floor(
115
+ (state.aggregates.total.metric.success /
116
+ state.aggregates.total.metric.attempt) *
117
+ 100,
118
+ ) + "%",
119
+ ].join(" | ");
120
+ };
121
+ return StringUtil.trim`
122
+ ### \`${props.replay.vendor}\` - \`${props.replay.project}\`
123
+
124
+ - Source Code: ${`[\`${AutoBeExampleStorage.slugModel(
125
+ props.replay.vendor,
126
+ false,
127
+ )}/${props.replay.project}\`](./${AutoBeExampleStorage.slugModel(
128
+ props.replay.vendor,
129
+ false,
130
+ )}/${props.replay.project}/)`}
131
+ - Score: ${props.score}
132
+ - Elapsed Time: ${formatElapsedTime(props.replay.elapsed)}
133
+ - Token Usage: ${formatTokens(
134
+ props.replay.aggregates.total.tokenUsage.total,
135
+ )}
136
+ - Function Calling Success Rate: ${(
137
+ (props.replay.aggregates.total.metric.success /
138
+ props.replay.aggregates.total.metric.attempt) *
139
+ 100
140
+ ).toFixed(2)}%
141
+
142
+ Phase | Generated | Token Usage | Elapsed Time | FCSR
143
+ :-----|:----------|------------:|-------------:|------:
144
+ ${(["analyze", "database", "interface", "test", "realize"] as const)
145
+ .map((key) => phase(key))
146
+ .join("\n")}
147
+ `;
148
+ };
149
+ }
150
+
151
+ function formatElapsedTime(ms: number): string {
152
+ const seconds = Math.floor(ms / 1000);
153
+ const minutes = Math.floor(seconds / 60);
154
+ const hours = Math.floor(minutes / 60);
155
+
156
+ const s = seconds % 60;
157
+ const m = minutes % 60;
158
+ const h = hours;
159
+
160
+ if (h > 0) {
161
+ return `${h}h ${m}m ${s}s`;
162
+ } else if (m > 0) {
163
+ return `${m}m ${s}s`;
164
+ } else {
165
+ return `${s}s`;
166
+ }
167
+ }
168
+
169
+ function formatTokens(num: number): string {
170
+ if (num >= 1000000) {
171
+ return `${(num / 1000000).toFixed(2)}M`;
172
+ } else if (num >= 1000) {
173
+ return `${(num / 1000).toFixed(1)}K`;
174
+ }
175
+ return num.toString();
176
+ }