@o-lang/llm-groq 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +27 -12
- package/package.json +11 -3
package/index.js
CHANGED
|
@@ -5,11 +5,24 @@ const Groq = require('groq-sdk');
|
|
|
5
5
|
const GROQ_API_KEY = process.env.GROQ_API_KEY;
|
|
6
6
|
const groq = GROQ_API_KEY ? new Groq({ apiKey: GROQ_API_KEY }) : null;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Summarize / analyze the prompt using Groq LLM
|
|
10
|
+
*/
|
|
11
|
+
async function summarize(prompt, context) {
|
|
9
12
|
if (!groq) {
|
|
10
13
|
throw new Error('GROQ_API_KEY is required but not set');
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
// Replace any leftover {placeholders} in prompt
|
|
17
|
+
prompt = prompt.replace(/\{([^\}]+)\}/g, (_, k) => {
|
|
18
|
+
const v = context[k.trim()];
|
|
19
|
+
return v !== undefined ? v : `{${k}}`;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (context?.__verbose) {
|
|
23
|
+
console.log('📨 [GroqLLM] Sending prompt:\n', prompt);
|
|
24
|
+
}
|
|
25
|
+
|
|
13
26
|
const response = await groq.chat.completions.create({
|
|
14
27
|
messages: [{ role: 'user', content: prompt }],
|
|
15
28
|
model: 'llama-3.1-8b-instant',
|
|
@@ -17,20 +30,22 @@ async function summarize(prompt) {
|
|
|
17
30
|
max_tokens: 250,
|
|
18
31
|
top_p: 0.9
|
|
19
32
|
});
|
|
20
|
-
|
|
33
|
+
|
|
34
|
+
const output = response.choices[0].message.content.trim();
|
|
35
|
+
|
|
36
|
+
if (context?.__verbose) {
|
|
37
|
+
console.log('📬 [GroqLLM] Response:\n', output);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return output;
|
|
21
41
|
}
|
|
22
42
|
|
|
23
43
|
module.exports = async (action, context) => {
|
|
24
44
|
if (action.startsWith('Ask ')) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const end = action.lastIndexOf('"');
|
|
30
|
-
if (end <= start) return null;
|
|
31
|
-
|
|
32
|
-
let prompt = action.slice(start, end).replace(/\\n/g, '\n');
|
|
33
|
-
return await summarize(prompt);
|
|
45
|
+
// Flexible: take everything after "Ask ..." as prompt
|
|
46
|
+
const prompt = action.replace(/^Ask\s+\S*\s*/i, '').trim();
|
|
47
|
+
if (!prompt) return null;
|
|
48
|
+
return await summarize(prompt, context);
|
|
34
49
|
}
|
|
35
50
|
return null;
|
|
36
|
-
};
|
|
51
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o-lang/llm-groq",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "O-Lang resolver for Groq (Llama 3.1) LLM",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {},
|
|
7
|
-
"keywords": [
|
|
7
|
+
"keywords": [
|
|
8
|
+
"olang",
|
|
9
|
+
"groq",
|
|
10
|
+
"llm",
|
|
11
|
+
"resolver",
|
|
12
|
+
"ai",
|
|
13
|
+
"agent",
|
|
14
|
+
"governance"
|
|
15
|
+
],
|
|
8
16
|
"author": "O-lang team <info@workfily.com.com>",
|
|
9
17
|
"license": "MIT",
|
|
10
18
|
"repository": {
|
|
@@ -15,4 +23,4 @@
|
|
|
15
23
|
"groq-sdk": "^0.5.0",
|
|
16
24
|
"dotenv": "^16.4.5"
|
|
17
25
|
}
|
|
18
|
-
}
|
|
26
|
+
}
|