@o-lang/llm-groq 1.0.0 → 1.0.1
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 +19 -11
- package/package.json +11 -3
package/index.js
CHANGED
|
@@ -5,11 +5,15 @@ 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
|
-
async function summarize(prompt) {
|
|
8
|
+
async function summarize(prompt, context) {
|
|
9
9
|
if (!groq) {
|
|
10
10
|
throw new Error('GROQ_API_KEY is required but not set');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
if (context?.__verbose) {
|
|
14
|
+
console.log('📨 [GroqLLM] Sending prompt:\n', prompt);
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
const response = await groq.chat.completions.create({
|
|
14
18
|
messages: [{ role: 'user', content: prompt }],
|
|
15
19
|
model: 'llama-3.1-8b-instant',
|
|
@@ -17,20 +21,24 @@ async function summarize(prompt) {
|
|
|
17
21
|
max_tokens: 250,
|
|
18
22
|
top_p: 0.9
|
|
19
23
|
});
|
|
20
|
-
|
|
24
|
+
|
|
25
|
+
const output = response.choices[0].message.content.trim();
|
|
26
|
+
|
|
27
|
+
if (context?.__verbose) {
|
|
28
|
+
console.log('📬 [GroqLLM] Response:\n', output);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return output;
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
module.exports = async (action, context) => {
|
|
24
35
|
if (action.startsWith('Ask ')) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const start = toIndex + 5;
|
|
29
|
-
const end = action.lastIndexOf('"');
|
|
30
|
-
if (end <= start) return null;
|
|
36
|
+
// Extract the first quoted string
|
|
37
|
+
const quoteMatch = action.match(/"(.*)"/s); // /s allows \n inside quotes
|
|
38
|
+
if (!quoteMatch) return null;
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
return await summarize(prompt);
|
|
40
|
+
const prompt = quoteMatch[1].replace(/\\n/g, '\n');
|
|
41
|
+
return await summarize(prompt, context);
|
|
34
42
|
}
|
|
35
43
|
return null;
|
|
36
|
-
};
|
|
44
|
+
};
|
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.1",
|
|
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
|
+
}
|