@o-lang/llm-groq 1.0.2 → 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 +38 -9
  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) {
@@ -40,12 +47,34 @@ async function summarize(prompt, context) {
40
47
  return output;
41
48
  }
42
49
 
50
+ // ✅ O-Lang Resolver Interface
43
51
  module.exports = async (action, context) => {
44
- if (action.startsWith('Ask ')) {
45
- // Flexible: take everything after "Ask ..." as prompt
46
- const prompt = action.replace(/^Ask\s+\S*\s*/i, '').trim();
47
- if (!prompt) return null;
48
- return await summarize(prompt, context);
52
+ // Handle: "Ask llm-groq ..."
53
+ if (action.startsWith('Ask llm-groq ')) {
54
+ // Extract everything after "Ask llm-groq" (including quoted strings)
55
+ const prompt = action.replace(/^Ask\s+llm-groq\s+/i, '').trim();
56
+
57
+ // Remove surrounding quotes if present
58
+ const cleanPrompt = prompt.startsWith('"') && prompt.endsWith('"')
59
+ ? prompt.slice(1, -1)
60
+ : prompt;
61
+
62
+ if (!cleanPrompt) {
63
+ return undefined;
64
+ }
65
+
66
+ try {
67
+ return await processPrompt(cleanPrompt, context);
68
+ } catch (error) {
69
+ if (context?.__verbose) {
70
+ console.error('💥 [GroqLLM] Error:', error.message);
71
+ }
72
+ throw error;
73
+ }
49
74
  }
50
- return null;
75
+
76
+ return undefined;
51
77
  };
78
+
79
+ // ✅ Required for O-Lang allowlist policy
80
+ 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.2",
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": {},