shivam-cli-generator 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 (4) hide show
  1. package/.env +1 -0
  2. package/ai.js +54 -18
  3. package/cli.js +1 -1
  4. package/package.json +4 -7
package/.env ADDED
@@ -0,0 +1 @@
1
+ GROQ_API_KEY=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
package/ai.js CHANGED
@@ -1,47 +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
- // ✅ Get API Key from system environment only
6
13
  const apiKey = process.env.GROQ_API_KEY;
7
14
 
8
15
  if (!apiKey) {
9
- console.error("❌ GROQ_API_KEY is missing.\n👉 Set it using:\n\nsetx GROQ_API_KEY \"your_groq_api_key_here\"\n");
16
+ console.error("❌ GROQ_API_KEY is missing.\n👉 Please check your .env file or system environment variables.\n");
10
17
  process.exit(1);
11
18
  }
12
19
 
13
20
  // ✅ Correct Groq client initialization
14
21
  const client = new Groq({ apiKey });
15
22
 
16
- const inputURL = process.argv[2] || readline.question("Enter URL: ");
23
+ // Use the inputURL if provided
24
+ const inputURL = process.argv[2];
25
+
26
+ if (inputURL) {
27
+ console.log("\n🔗 Context URL:", inputURL);
28
+ }
17
29
 
18
- console.log("\n🔗 URL received:", inputURL);
19
30
  console.log("💡 Ask anything to AI. Type 'exit' to quit.\n");
20
31
 
21
32
  async function main() {
22
33
  while (true) {
23
34
  const question = readline.question("AI > ");
24
35
 
25
- if (question.toLowerCase() === "exit") break;
36
+ if (question.toLowerCase() === "exit") {
37
+ console.log("👋 Goodbye!");
38
+ break;
39
+ }
26
40
 
27
41
  console.log("⏳ Generating...");
28
42
 
29
- const response = await client.chat.completions.create({
30
- model: "llama-3.1-8b-instant",
31
- messages: [
32
- { role: "system", content: "You generate clean code. Only code or required output." },
33
- { role: "user", content: question }
34
- ]
35
- });
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();
36
60
 
37
- const output = response.choices[0].message.content.trim();
61
+ if (output) {
62
+ if (!fs.existsSync("generated")) fs.mkdirSync("generated");
38
63
 
39
- if (!fs.existsSync("generated")) fs.mkdirSync("generated");
64
+ const fileName = `generated/output_${Date.now()}.txt`;
65
+ fs.writeFileSync(fileName, output);
40
66
 
41
- const fileName = `generated/output_${Date.now()}.txt`;
42
- fs.writeFileSync(fileName, output);
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
+ }
43
74
 
44
- console.log(`\n✅ File generated: ${fileName}\n`);
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
+ }
45
81
  }
46
82
  }
47
83
 
package/cli.js CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import './ai.js';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "shivam-cli-generator",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "ai.js",
6
6
  "type": "module",
7
- "bin": {
8
- "shivam-ai": "./cli.js"
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
  }