Spaces:
Sleeping
Sleeping
Create llama.js
Browse files- plugins/llama.js +88 -0
plugins/llama.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const axios = require('axios');
|
| 2 |
+
|
| 3 |
+
const handler = async (req, res) => {
|
| 4 |
+
try {
|
| 5 |
+
const { text, img } = req.query;
|
| 6 |
+
|
| 7 |
+
if (!text) {
|
| 8 |
+
return res.status(400).json({
|
| 9 |
+
success: false,
|
| 10 |
+
error: 'Missing required parameter: text'
|
| 11 |
+
});
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const apiKey = process.env.GROQ;
|
| 15 |
+
|
| 16 |
+
if (!apiKey) {
|
| 17 |
+
return res.status(500).json({
|
| 18 |
+
success: false,
|
| 19 |
+
error: 'GROQ API key not configured in environment'
|
| 20 |
+
});
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
const content = [
|
| 24 |
+
{
|
| 25 |
+
type: "text",
|
| 26 |
+
text: text
|
| 27 |
+
}
|
| 28 |
+
];
|
| 29 |
+
|
| 30 |
+
if (img) {
|
| 31 |
+
content.push({
|
| 32 |
+
type: "image_url",
|
| 33 |
+
image_url: {
|
| 34 |
+
url: img
|
| 35 |
+
}
|
| 36 |
+
});
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
const response = await axios.post(
|
| 40 |
+
'https://api.groq.com/openai/v1/chat/completions',
|
| 41 |
+
{
|
| 42 |
+
messages: [
|
| 43 |
+
{
|
| 44 |
+
role: "user",
|
| 45 |
+
content: img ? content : text
|
| 46 |
+
}
|
| 47 |
+
],
|
| 48 |
+
model: img ? "meta-llama/llama-4-scout-17b-16e-instruct" : "llama-3.1-8b-instant",
|
| 49 |
+
temperature: 1,
|
| 50 |
+
max_completion_tokens: 1024,
|
| 51 |
+
top_p: 1,
|
| 52 |
+
stream: false
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
headers: {
|
| 56 |
+
'Content-Type': 'application/json',
|
| 57 |
+
'Authorization': `Bearer ${apiKey}`
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
const result = response.data.choices[0].message.content;
|
| 63 |
+
|
| 64 |
+
res.json({
|
| 65 |
+
author: "Herza",
|
| 66 |
+
success: true,
|
| 67 |
+
msg: result
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
} catch (error) {
|
| 71 |
+
res.status(500).json({
|
| 72 |
+
success: false,
|
| 73 |
+
error: error.response?.data?.error?.message || error.message
|
| 74 |
+
});
|
| 75 |
+
}
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
module.exports = {
|
| 79 |
+
name: 'LLAMA AI',
|
| 80 |
+
description: 'Generate responses using Groq API with text and image support',
|
| 81 |
+
type: 'GET',
|
| 82 |
+
routes: ['api/AI/groq'],
|
| 83 |
+
tags: ['ai', 'Meta AI', 'llama', 'vision'],
|
| 84 |
+
main: ['AI'],
|
| 85 |
+
parameters: ['text', 'img'],
|
| 86 |
+
enabled: true,
|
| 87 |
+
handler
|
| 88 |
+
};
|