DashX / plugins /llama.js
HerzaJ's picture
Update plugins/llama.js
7acb769 verified
const axios = require('axios');
const handler = async (req, res) => {
try {
const { text, img } = req.query;
if (!text) {
return res.status(400).json({
success: false,
error: 'Missing required parameter: text'
});
}
const apiKey = process.env.GROQ;
if (!apiKey) {
return res.status(500).json({
success: false,
error: 'GROQ API key not configured in environment'
});
}
const content = [
{
type: "text",
text: text
}
];
if (img) {
content.push({
type: "image_url",
image_url: {
url: img
}
});
}
const response = await axios.post(
'https://api.groq.com/openai/v1/chat/completions',
{
messages: [
{
role: "user",
content: img ? content : text
}
],
model: img ? "meta-llama/llama-4-scout-17b-16e-instruct" : "llama-3.1-8b-instant",
temperature: 1,
max_completion_tokens: 1024,
top_p: 1,
stream: false
},
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
}
}
);
const result = response.data.choices[0].message.content;
res.json({
author: "Herza",
success: true,
msg: result
});
} catch (error) {
res.status(500).json({
success: false,
error: error.response?.data?.error?.message || error.message
});
}
};
module.exports = {
name: 'LLAMA AI',
description: 'Generate responses using Groq API with text and image support',
type: 'GET',
routes: ['api/AI/llama'],
tags: ['ai', 'Meta AI', 'llama', 'vision'],
main: ['AI'],
parameters: ['text', 'img', 'key'],
enabled: true,
limit: 8,
handler
};