@o-lang/llm-groq 1.0.3 → 1.0.4

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 +12 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,9 +6,9 @@ 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
9
+ * Process any prompt using Groq LLM
10
10
  */
11
- async function summarize(prompt, context) {
11
+ async function processPrompt(prompt, context) {
12
12
  if (!groq) {
13
13
  throw new Error('GROQ_API_KEY is required but not set');
14
14
  }
@@ -16,7 +16,14 @@ async function summarize(prompt, context) {
16
16
  // Replace any leftover {placeholders} in prompt
17
17
  prompt = prompt.replace(/\{([^\}]+)\}/g, (_, k) => {
18
18
  const v = context[k.trim()];
19
- return v !== undefined ? v : `{${k}}`;
19
+ if (v === undefined) {
20
+ return `{${k}}`;
21
+ }
22
+ // ✅ CRITICAL: Convert objects/arrays to JSON strings for proper LLM consumption
23
+ if (typeof v === 'object') {
24
+ return JSON.stringify(v);
25
+ }
26
+ return String(v);
20
27
  });
21
28
 
22
29
  if (context?.__verbose) {
@@ -42,7 +49,7 @@ async function summarize(prompt, context) {
42
49
 
43
50
  // ✅ O-Lang Resolver Interface
44
51
  module.exports = async (action, context) => {
45
- // Only handle: "Ask llm-groq ..."
52
+ // Handle: "Ask llm-groq ..."
46
53
  if (action.startsWith('Ask llm-groq ')) {
47
54
  // Extract everything after "Ask llm-groq" (including quoted strings)
48
55
  const prompt = action.replace(/^Ask\s+llm-groq\s+/i, '').trim();
@@ -57,17 +64,15 @@ module.exports = async (action, context) => {
57
64
  }
58
65
 
59
66
  try {
60
- return await summarize(cleanPrompt, context);
67
+ return await processPrompt(cleanPrompt, context);
61
68
  } catch (error) {
62
69
  if (context?.__verbose) {
63
70
  console.error('💥 [GroqLLM] Error:', error.message);
64
71
  }
65
- // Re-throw to let workflow handle failure
66
72
  throw error;
67
73
  }
68
74
  }
69
75
 
70
- // ✅ Critical: return undefined, not null
71
76
  return undefined;
72
77
  };
73
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o-lang/llm-groq",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "O-Lang resolver for Groq (Llama 3.1) LLM",
5
5
  "main": "index.js",
6
6
  "scripts": {},