-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
52 lines (45 loc) · 1.54 KB
/
main.js
File metadata and controls
52 lines (45 loc) · 1.54 KB
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
const fs = require('fs');
const { execSync } = require('child_process');
function generateJoke() {
// In a real implementation, this would call an LLM API.
// For this example, we'll just grab a random joke from a file.
const jokes = require('./src/jokes.js');
return jokes[Math.floor(Math.random() * jokes.length)];
}
function integrateJoke(joke) {
const jokes = require('./src/jokes.js');
jokes.push(joke);
const newJokesFile = `module.exports = ${JSON.stringify(jokes, null, 4)};`;
fs.writeFileSync('./src/jokes.js', newJokesFile);
console.log('Joke added successfully!');
}
async function getRating(joke) {
// In a real implementation, this would call an LLM API.
// For this example, we'll generate random ratings.
return {
funniness: Math.floor(Math.random() * 10) + 1,
originality: Math.floor(Math.random() * 10) + 1,
cleverness: Math.floor(Math.random() * 10) + 1,
};
}
async function rateJoke(joke) {
const ratings = JSON.parse(fs.readFileSync('./joke-ratings.json'));
if (!ratings[joke]) {
const rating = await getRating(joke);
ratings[joke] = rating;
fs.writeFileSync('./joke-ratings.json', JSON.stringify(ratings, null, 4));
console.log(`Rated joke: "${joke}"`);
}
}
async function main() {
while (true) {
console.log('--- New Joke Cycle ---');
const joke = generateJoke();
console.log(`Generated joke: "${joke}"`);
integrateJoke(joke);
await rateJoke(joke);
console.log('--- Cycle Complete ---');
await new Promise(resolve => setTimeout(resolve, 5000));
}
}
main();