@o-lang/llm-groq 1.0.1 → 1.0.3
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 +38 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -5,11 +5,20 @@ 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
|
+
/**
|
|
9
|
+
* Summarize / analyze the prompt using Groq LLM
|
|
10
|
+
*/
|
|
8
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
|
+
|
|
13
22
|
if (context?.__verbose) {
|
|
14
23
|
console.log('📨 [GroqLLM] Sending prompt:\n', prompt);
|
|
15
24
|
}
|
|
@@ -31,14 +40,36 @@ async function summarize(prompt, context) {
|
|
|
31
40
|
return output;
|
|
32
41
|
}
|
|
33
42
|
|
|
43
|
+
// ✅ O-Lang Resolver Interface
|
|
34
44
|
module.exports = async (action, context) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
// Only handle: "Ask llm-groq ..."
|
|
46
|
+
if (action.startsWith('Ask llm-groq ')) {
|
|
47
|
+
// Extract everything after "Ask llm-groq" (including quoted strings)
|
|
48
|
+
const prompt = action.replace(/^Ask\s+llm-groq\s+/i, '').trim();
|
|
49
|
+
|
|
50
|
+
// Remove surrounding quotes if present
|
|
51
|
+
const cleanPrompt = prompt.startsWith('"') && prompt.endsWith('"')
|
|
52
|
+
? prompt.slice(1, -1)
|
|
53
|
+
: prompt;
|
|
54
|
+
|
|
55
|
+
if (!cleanPrompt) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
39
58
|
|
|
40
|
-
|
|
41
|
-
|
|
59
|
+
try {
|
|
60
|
+
return await summarize(cleanPrompt, context);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (context?.__verbose) {
|
|
63
|
+
console.error('💥 [GroqLLM] Error:', error.message);
|
|
64
|
+
}
|
|
65
|
+
// Re-throw to let workflow handle failure
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
42
68
|
}
|
|
43
|
-
|
|
69
|
+
|
|
70
|
+
// ✅ Critical: return undefined, not null
|
|
71
|
+
return undefined;
|
|
44
72
|
};
|
|
73
|
+
|
|
74
|
+
// ✅ Required for O-Lang allowlist policy
|
|
75
|
+
module.exports.resolverName = 'llm-groq';
|