Skip to content

Commit ff5b081

Browse files
feat: add starkling workflow and script
1 parent b9cba42 commit ff5b081

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const fs = require('fs');
2+
const { execSync } = require('child_process');
3+
4+
function parseInfoToml(infoPath) {
5+
const fs = require('fs');
6+
const content = fs.readFileSync(infoPath, 'utf8');
7+
8+
const exercises = [];
9+
const lines = content.split('\n');
10+
11+
let currentExercise = null;
12+
13+
for (const line of lines) {
14+
const cleanLine = line.trim();
15+
16+
if (cleanLine.startsWith('[[exercises]]')) {
17+
if (currentExercise) exercises.push(currentExercise);
18+
currentExercise = {};
19+
} else if (cleanLine.startsWith('name = ')) {
20+
currentExercise.name = cleanLine.match(/name = "(.+)"/)[1];
21+
} else if (cleanLine.startsWith('path = ')) {
22+
currentExercise.path = cleanLine.match(/path = "(.+)"/)[1];
23+
} else if (cleanLine.startsWith('mode = ')) {
24+
currentExercise.mode = cleanLine.match(/mode = "(.+)"/)[1];
25+
}
26+
}
27+
28+
if (currentExercice) exercises.push(currentExercise);
29+
return exercises;
30+
}
31+
32+
async function callCairoCoderAPI(exerciseContent) {
33+
const response = await fetch('http://localhost:3001/v1/chat/completions', {
34+
method: 'POST',
35+
headers: {
36+
'Content-Type': 'application/json'
37+
},
38+
body: JSON.stringify({
39+
model: 'cairo-coder',
40+
messages: [
41+
{
42+
role: 'user',
43+
content: `Complete this Cairo exercise by fixing the code. Remove the "// I AM NOT DONE" comment and fix any compilation errors:\n\n${exerciseContent}`
44+
}
45+
]
46+
})
47+
});
48+
49+
const data = await response.json();
50+
return data.choices[0].message.content;
51+
}
52+
53+
async function main() {
54+
// 1. Parser info.toml pour lister tous les exercices
55+
const exercises = parseInfoToml('./starklings/info.toml');
56+
57+
let passed = 0;
58+
let total = exercises.length;
59+
60+
for (const exercise of exercises) {
61+
console.log(`Testing ${exercise.name}...`);
62+
const exerciseContent = fs.readFileSync(`./starklings/${exercise.path}`, 'utf8');
63+
const response = await callCairoCoderAPI(exerciseContent);
64+
fs.writeFileSync(`./starklings/${exercise.path}`, response);
65+
66+
// Tester avec starklings
67+
try {
68+
execSync(`cd starklings && cargo run -r --bin starklings run ${exercise.name}`, { stdio: 'pipe' });
69+
console.log(`✅ ${exercise.name}`);
70+
passed++;
71+
} catch (error) {
72+
console.log(`❌ ${exercise.name}`);
73+
}
74+
}
75+
76+
console.log(`\nResults: ${passed}/${total} exercises passed (${(passed/total*100).toFixed(1)}%)`);
77+
78+
// Fail CI si moins de 80% de réussite
79+
if (passed/total < 0.8) {
80+
process.exit(1);
81+
}
82+
}
83+
84+
main().catch(console.error);

.github/workflows/starklings.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Starklings Benchmark
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
starklings-benchmark:
11+
name: Starklings Benchmark
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '20'
21+
22+
- name: Setup Rust
23+
uses: actions-rs/toolchain@v1
24+
with:
25+
toolchain: stable
26+
override: true
27+
28+
- name: Install pnpm
29+
uses: pnpm/action-setup@v3
30+
with:
31+
version: 9
32+
33+
- name: Clone Starklings
34+
run: git clone https://github.com/starknet-edu/starklings.git
35+
36+
- name: Install dependencies
37+
run: pnpm install
38+
39+
- name: Build Cairo Coder
40+
run: pnpm build
41+
42+
- name: Start Cairo Coder (background)
43+
run: |
44+
pnpm start &
45+
sleep 30 # Attendre que le serveur démarre
46+
47+
- name: Run Starklings Evaluation
48+
run: node scripts/evaluate-with-starklings.js

0 commit comments

Comments
 (0)