diff --git a/app.js b/app.js index 5053739..009c529 100644 --- a/app.js +++ b/app.js @@ -7,13 +7,44 @@ const port = 3000; const upload = multer({ dest: 'uploads/' }); +const GROQ_API_KEY = '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'; +const model = 'llama3-8b-8192'; + app.use(express.static("static")); +app.use(express.json()); app.get('/', (req, res) => { - res.sendFile(__dirname + '/static/index.html'); + res.sendFile(__dirname + '/static/index.html'); }); +app.post('/completions', async (req, res) => { + try { + const query = req.body.query; + if (!query) { + return res.status(400).json({ error: 'Prompt is required' }); + } + + const data = { + messages: [{ role: 'user', content: query }], + model, + }; + + const config = { + headers: { + Authorization: `Bearer ${GROQ_API_KEY}`, + 'Content-Type': 'application/json', + }, + }; + + const response = await axios.post('https://api.groq.com/openai/v1/chat/completions', data, config); + res.json(response.data); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Error completing prompt' }); + } +}); + app.post('/upload', upload.single('image'), async (req, res) => { try { const image = fs.readFileSync(req.file.path, { encoding: 'base64' }); diff --git a/static/index.html b/static/index.html index 5d78ced..16511a4 100644 --- a/static/index.html +++ b/static/index.html @@ -6,12 +6,19 @@ Upload Image - +

+
+ +