-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathseed.js
More file actions
58 lines (52 loc) · 1.67 KB
/
seed.js
File metadata and controls
58 lines (52 loc) · 1.67 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
const mongoose = require('mongoose');
const Faq = require('../models/Faq.js'); // Use `.js` for ES modules
const { getEmbedding } = require('../backend/embedding.js');
const MONGO_URI = process.env.MONGO_URI;
const guildId = '1377306965872611388';
const faqs = [
{
question: "Is coffee provided in the hackathon?",
answer: "Yes, coffee will be available throughout the event."
},
{
question: "Will there be Wi-Fi at the venue?",
answer: "Yes, high-speed Wi-Fi will be provided to all participants."
},
{
question: "Are there resting areas at the hackathon?",
answer: "Yes, there will be designated rest zones with bean bags and beds."
},
{
question: "Are goodies provided in the hackathon?",
answer: "Yes, participants will receive goodies during the event."
},
{
question: "Will we receive goodies?",
answer: "Yes, each participant receives a goodie bag."
}
];
export default async function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Only POST method allowed' });
}
try {
await mongoose.connect(MONGO_URI);
await Faq.deleteMany({ guildId });
for (const item of faqs) {
const embedding = await getEmbedding(item.question);
await Faq.create({
guildId,
question: item.question,
answer: item.answer,
embedding
});
console.log(`✅ Seeded: ${item.question}`);
}
return res.status(200).json({ success: true, message: 'Seeding done' });
} catch (error) {
console.error('Error seeding DB:', error);
return res.status(500).json({ error: 'Seeding failed' });
} finally {
mongoose.connection.close();
}
}