forked from surajyog/nanomides
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-bots.js
More file actions
111 lines (88 loc) · 3.3 KB
/
Copy pathgenerate-bots.js
File metadata and controls
111 lines (88 loc) · 3.3 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { GoogleGenAI } from '@google/genai';
import { CONFIG, ROLES } from './config.js';
import { writeFileSync } from 'fs';
async function generateWorldBrain(ai, topic) {
const prompt = `Create global rules and environment for a virtual world simulation.
Topic: ${topic}
Roles: ${ROLES.join(', ')}
Output a JSON object with:
- project description
- interaction rules
- communication norms
- knowledge domains per role
Output ONLY valid JSON, no markdown.`;
const response = await ai.models.generateContent({
model: CONFIG.MODEL,
contents: [{ role: 'user', parts: [{ text: prompt }] }],
config: {
thinkingConfig: { thinkingLevel: CONFIG.THINKING_LEVEL },
temperature: CONFIG.TEMPERATURE,
maxOutputTokens: 4096,
}
});
const text = response.candidates[0].content.parts[0].text;
return JSON.parse(text.replace(/```json\n?/g, '').replace(/```\n?/g, ''));
}
async function generateRoleCluster(ai, role, count, topic, worldRules) {
const prompt = `Generate ${count} independent ${role} bots for a virtual world simulation.
Topic: ${topic}
World Rules: ${JSON.stringify(worldRules)}
Each bot must have:
- id (number)
- role (string)
- name (unique)
- knowledge (array of expertise areas)
- personality (string: analytical/creative/critical/optimistic/detail-oriented)
- bias (string: what they focus on)
- confidence (0-1)
Output ONLY a valid JSON array of ${count} bot objects, no markdown.`;
const response = await ai.models.generateContent({
model: CONFIG.MODEL,
contents: [{ role: 'user', parts: [{ text: prompt }] }],
config: {
thinkingConfig: { thinkingLevel: CONFIG.THINKING_LEVEL },
temperature: 0.4,
maxOutputTokens: CONFIG.MAX_OUTPUT_TOKENS,
}
});
const text = response.candidates[0].content.parts[0].text;
return JSON.parse(text.replace(/```json\n?/g, '').replace(/```\n?/g, ''));
}
async function generateBots(totalBots, topic) {
const apiKey = process.env.GEMINI_API_KEY;
if (!apiKey) throw new Error('GEMINI_API_KEY not set');
const ai = new GoogleGenAI({ apiKey });
console.log('🌍 Generating World Brain...');
const worldBrain = await generateWorldBrain(ai, topic);
console.log('✅ World Brain created\n');
const botsPerRole = Math.ceil(totalBots / ROLES.length);
const allBots = [];
let botIdCounter = 1;
for (const role of ROLES) {
console.log(`🤖 Generating ${botsPerRole} ${role} bots...`);
const bots = await generateRoleCluster(ai, role, botsPerRole, topic, worldBrain);
bots.forEach(bot => {
bot.id = botIdCounter++;
allBots.push(bot);
});
console.log(`✅ ${role} bots created`);
await new Promise(resolve => setTimeout(resolve, 2000));
}
const finalBots = allBots.slice(0, totalBots);
const output = {
worldBrain,
bots: finalBots,
metadata: {
totalBots: finalBots.length,
topic,
generatedAt: new Date().toISOString()
}
};
writeFileSync('bots.json', JSON.stringify(output, null, 2));
console.log(`\n✅ Generated ${finalBots.length} bots → saved to bots.json`);
return output;
}
const totalBots = parseInt(process.argv[2]) || 100;
const topic = process.argv[3] || 'AI Virtual World Development';
console.log(`\n🚀 Generating ${totalBots} bots for topic: "${topic}"\n`);
generateBots(totalBots, topic).catch(console.error);