Llama-3-70B-DDroidlabs / agentscript.js
dnnsdunca's picture
Create agentscript.js
28b2eff verified
raw
history blame contribute delete
959 Bytes
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
const { MongoClient } = require('mongodb');
const app = express();
app.use(bodyParser.json());
const uri = 'your-mongodb-connection-string';
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
client.connect(err => {
if (err) throw err;
const collection = client.db("code-generation").collection("snippets");
app.post('/generate-code', async (req, res) => {
const { prompt } = req.body;
try {
const response = await axios.post('http://localhost:8000/generate-code', { prompt });
const code = response.data.code;
await collection.insertOne({ prompt, code });
res.json(response.data);
} catch (error) {
res.status(500).json({ error: 'Error generating code' });
}
});
app.listen(5000, () => {
console.log('Server running on port 5000');
});
});