nodeclicontribution 1.0.0
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/README.md +30 -0
- package/groq-cli.mjs +62 -0
- package/package.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Groq CLI Extractor
|
|
2
|
+
|
|
3
|
+
This is a lightweight memory-safe information and context extraction tool powered by Groq's inference engine. It streams local images and PDFs, converts them into natively-encoded Base64 without crashing the V8 heap, and extracts their data using Groq's Vision API.
|
|
4
|
+
|
|
5
|
+
## 🚀 Installation
|
|
6
|
+
|
|
7
|
+
Install the package globally via NPM:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g groq-cli-extractor
|
|
11
|
+
|
|
12
|
+
##⚙️ Configuration
|
|
13
|
+
|
|
14
|
+
## Windows(PowerShell)
|
|
15
|
+
$env:GROQ_API_KEY="gsk_your_api_key_here"
|
|
16
|
+
|
|
17
|
+
## macOS/Linux
|
|
18
|
+
export GROQ_API_KEY="gsk_your_api_key_here"
|
|
19
|
+
|
|
20
|
+
## 🛠️ Usage
|
|
21
|
+
Once installed and configured, you can extract data from any file (under 5MB) directly from your terminal:
|
|
22
|
+
groq-extract /path/to/your/image.png
|
|
23
|
+
|
|
24
|
+
## ⚠️ Important Note: Upstream Model Lifecycle
|
|
25
|
+
This CLI currently relies on Groq's Vision models (e.g., meta-llama/llama-4-scout-17b-16e-instruct).
|
|
26
|
+
|
|
27
|
+
Groq frequently updates, deprecates, and decommissions their preview models. If the tool suddenly begins throwing API errors in the future, it is highly likely the targeted model has been decommissioned by Groq.
|
|
28
|
+
|
|
29
|
+
If this happens, you will need to update the model string in the source code to Groq's latest supported Vision model and reinstall the package. Check the Groq Model Documentation for the most up-to-date model IDs.
|
|
30
|
+
|
package/groq-cli.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import path from "path"
|
|
4
|
+
import { Groq } from "groq-sdk"
|
|
5
|
+
|
|
6
|
+
const groq = new Groq({apiKey:process.env.GROQ_API_KEY})
|
|
7
|
+
|
|
8
|
+
const max_size = 5*1024*1024
|
|
9
|
+
const inputFilePath= process.argv[2]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
if(!inputFilePath){
|
|
14
|
+
console.error("no path provided")
|
|
15
|
+
process.exit(1)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const absolutePath = path.resolve(inputFilePath)
|
|
19
|
+
console.log("DEBUG PATH:", absolutePath)
|
|
20
|
+
const stats = fs.statSync(absolutePath)
|
|
21
|
+
const size = stats.size
|
|
22
|
+
|
|
23
|
+
if(size>max_size){
|
|
24
|
+
console.error("Error: File exceeds the 5MB API limit.")
|
|
25
|
+
process.exit(1)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const readStream = fs.createReadStream(absolutePath)
|
|
29
|
+
readStream.setEncoding('base64')
|
|
30
|
+
|
|
31
|
+
let base64String = ''
|
|
32
|
+
|
|
33
|
+
readStream.on('data',(chunk)=>{
|
|
34
|
+
base64String+=chunk
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
readStream.on('end',async ()=>{
|
|
38
|
+
console.log("File processed. Contacting Groq API...");
|
|
39
|
+
try{
|
|
40
|
+
const response = await groq.chat.completions.create({
|
|
41
|
+
model:"meta-llama/llama-4-scout-17b-16e-instruct",
|
|
42
|
+
messages:[
|
|
43
|
+
{
|
|
44
|
+
role:"user",
|
|
45
|
+
content:[
|
|
46
|
+
{type:"text",text:"Extract and describe the contents of this image/document."},
|
|
47
|
+
{type:"image_url",image_url:{url: `data:image/jpeg;base64,${base64String}`}}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
console.log("\n--- EXTRACTION COMPLETE ---");
|
|
53
|
+
console.log(response.choices[0].message.content);
|
|
54
|
+
}catch(apiError){
|
|
55
|
+
console.error("API Error",apiError.message)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
readStream.on('error',(err)=>{
|
|
60
|
+
console.error("error loading data",err.message)
|
|
61
|
+
})
|
|
62
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nodeclicontribution",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"groq-extract":"groq-cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"groq-sdk": "^1.2.0"
|
|
17
|
+
}
|
|
18
|
+
}
|