@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.
Files changed (2) hide show
  1. package/index.js +38 -7
  2. 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
- if (action.startsWith('Ask ')) {
36
- // Extract the first quoted string
37
- const quoteMatch = action.match(/"(.*)"/s); // /s allows \n inside quotes
38
- if (!quoteMatch) return null;
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
- const prompt = quoteMatch[1].replace(/\\n/g, '\n');
41
- return await summarize(prompt, context);
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
- return null;
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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o-lang/llm-groq",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "O-Lang resolver for Groq (Llama 3.1) LLM",
5
5
  "main": "index.js",
6
6
  "scripts": {},