@o-lang/llm-groq 1.0.1 → 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 +12 -5
- 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
|
}
|
|
@@ -33,11 +42,9 @@ async function summarize(prompt, context) {
|
|
|
33
42
|
|
|
34
43
|
module.exports = async (action, context) => {
|
|
35
44
|
if (action.startsWith('Ask ')) {
|
|
36
|
-
//
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
|
|
40
|
-
const prompt = quoteMatch[1].replace(/\\n/g, '\n');
|
|
45
|
+
// Flexible: take everything after "Ask ..." as prompt
|
|
46
|
+
const prompt = action.replace(/^Ask\s+\S*\s*/i, '').trim();
|
|
47
|
+
if (!prompt) return null;
|
|
41
48
|
return await summarize(prompt, context);
|
|
42
49
|
}
|
|
43
50
|
return null;
|