shivam-cli-generator 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.
- package/.env +1 -0
- package/ai.js +60 -18
- package/cli.js +1 -1
- package/package.json +4 -7
package/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GROQ_API_KEY=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
|
package/ai.js
CHANGED
|
@@ -1,41 +1,83 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { dirname, join } from 'path';
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
|
|
8
|
+
// Load .env from the package directory, not the current working directory
|
|
9
|
+
dotenv.config({ path: join(__dirname, '.env') });
|
|
1
10
|
import Groq from "groq-sdk";
|
|
2
11
|
import fs from "fs";
|
|
3
12
|
import readline from "readline-sync";
|
|
4
|
-
|
|
5
|
-
|
|
13
|
+
const apiKey = process.env.GROQ_API_KEY;
|
|
14
|
+
|
|
15
|
+
if (!apiKey) {
|
|
16
|
+
console.error("ā GROQ_API_KEY is missing.\nš Please check your .env file or system environment variables.\n");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
6
19
|
|
|
20
|
+
// ā
Correct Groq client initialization
|
|
21
|
+
const client = new Groq({ apiKey });
|
|
7
22
|
|
|
8
|
-
|
|
23
|
+
// ā
Use the inputURL if provided
|
|
24
|
+
const inputURL = process.argv[2];
|
|
9
25
|
|
|
10
|
-
|
|
26
|
+
if (inputURL) {
|
|
27
|
+
console.log("\nš Context URL:", inputURL);
|
|
28
|
+
}
|
|
11
29
|
|
|
12
|
-
console.log("\nš URL received:", inputURL);
|
|
13
30
|
console.log("š” Ask anything to AI. Type 'exit' to quit.\n");
|
|
14
31
|
|
|
15
32
|
async function main() {
|
|
16
33
|
while (true) {
|
|
17
34
|
const question = readline.question("AI > ");
|
|
18
35
|
|
|
19
|
-
if (question.toLowerCase() === "exit")
|
|
36
|
+
if (question.toLowerCase() === "exit") {
|
|
37
|
+
console.log("š Goodbye!");
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
20
40
|
|
|
21
41
|
console.log("ā³ Generating...");
|
|
22
42
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
try {
|
|
44
|
+
let systemPrompt = "You generate clean code. Only code or required output.";
|
|
45
|
+
let userContent = question;
|
|
46
|
+
|
|
47
|
+
if (inputURL) {
|
|
48
|
+
userContent = `Context URL: ${inputURL}\n\nQuestion: ${question}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const response = await client.chat.completions.create({
|
|
52
|
+
model: "llama-3.1-8b-instant",
|
|
53
|
+
messages: [
|
|
54
|
+
{ role: "system", content: systemPrompt },
|
|
55
|
+
{ role: "user", content: userContent }
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const output = response.choices[0]?.message?.content?.trim();
|
|
30
60
|
|
|
31
|
-
|
|
61
|
+
if (output) {
|
|
62
|
+
if (!fs.existsSync("generated")) fs.mkdirSync("generated");
|
|
32
63
|
|
|
33
|
-
|
|
64
|
+
const fileName = `generated/output_${Date.now()}.txt`;
|
|
65
|
+
fs.writeFileSync(fileName, output);
|
|
34
66
|
|
|
35
|
-
|
|
36
|
-
|
|
67
|
+
console.log(`\nā
File generated: ${fileName}\n`);
|
|
68
|
+
console.log("-----------------------------------");
|
|
69
|
+
console.log(output); // Also print to console for immediate feedback
|
|
70
|
+
console.log("-----------------------------------\n");
|
|
71
|
+
} else {
|
|
72
|
+
console.log("ā ļø No content received from AI.");
|
|
73
|
+
}
|
|
37
74
|
|
|
38
|
-
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error("\nā Error communicating with AI:", error.message);
|
|
77
|
+
if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND') {
|
|
78
|
+
console.error("š Check your internet connection.\n");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
39
81
|
}
|
|
40
82
|
}
|
|
41
83
|
|
package/cli.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shivam-cli-generator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "ai.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
},
|
|
7
|
+
"bin": {
|
|
8
|
+
"shivam-ai": "./cli.js"
|
|
9
|
+
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "node ai.js"
|
|
12
12
|
},
|
|
@@ -16,9 +16,6 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"dotenv": "^17.2.3",
|
|
18
18
|
"groq-sdk": "^0.37.0",
|
|
19
|
-
"openai": "^6.16.0",
|
|
20
19
|
"readline-sync": "^1.4.10"
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
21
|
}
|