@devangkumar/dvai 1.0.0 → 1.0.1
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/package.json +1 -1
- package/src/index.js +40 -13
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GoogleGenerativeAI } from "@google/generative-ai";
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
+
import chalk from "chalk";
|
|
3
4
|
import ora from "ora";
|
|
4
5
|
import inquirer from "inquirer";
|
|
5
6
|
|
|
@@ -12,14 +13,17 @@ const program = new Command();
|
|
|
12
13
|
|
|
13
14
|
program
|
|
14
15
|
.name("myai")
|
|
15
|
-
.description("AI
|
|
16
|
-
.version("1.0.
|
|
16
|
+
.description("A stunning AI assistant in your terminal")
|
|
17
|
+
.version("1.0.1");
|
|
17
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Main AI function to get response
|
|
21
|
+
*/
|
|
18
22
|
async function getAIResponse(prompt, chatHistory = []) {
|
|
19
23
|
const spinner = ora({
|
|
20
|
-
text: "",
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
text: chalk.cyan("AI is thinking..."),
|
|
25
|
+
color: "cyan",
|
|
26
|
+
spinner: "dots"
|
|
23
27
|
}).start();
|
|
24
28
|
|
|
25
29
|
try {
|
|
@@ -37,7 +41,7 @@ async function getAIResponse(prompt, chatHistory = []) {
|
|
|
37
41
|
}
|
|
38
42
|
} catch (error) {
|
|
39
43
|
spinner.stop();
|
|
40
|
-
console.error("Error:", error.message);
|
|
44
|
+
console.error(chalk.red("\n✖ AI Error:"), error.message);
|
|
41
45
|
return null;
|
|
42
46
|
}
|
|
43
47
|
}
|
|
@@ -46,15 +50,18 @@ async function getAIResponse(prompt, chatHistory = []) {
|
|
|
46
50
|
* Handle Single Question
|
|
47
51
|
*/
|
|
48
52
|
program
|
|
49
|
-
.argument("[prompt]", "
|
|
53
|
+
.argument("[prompt]", "The question you want to ask AI")
|
|
50
54
|
.action(async (prompt) => {
|
|
51
55
|
if (!prompt) {
|
|
56
|
+
displayWelcome();
|
|
52
57
|
return;
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
const response = await getAIResponse(prompt);
|
|
56
61
|
if (response) {
|
|
57
|
-
|
|
62
|
+
console.log(chalk.blue.bold("\nAI Response:"));
|
|
63
|
+
console.log(chalk.white(response));
|
|
64
|
+
console.log("\n");
|
|
58
65
|
}
|
|
59
66
|
});
|
|
60
67
|
|
|
@@ -63,8 +70,14 @@ program
|
|
|
63
70
|
*/
|
|
64
71
|
program
|
|
65
72
|
.command("chat")
|
|
66
|
-
.description("Start chat session")
|
|
73
|
+
.description("Start an interactive chat session")
|
|
67
74
|
.action(async () => {
|
|
75
|
+
console.clear();
|
|
76
|
+
console.log(chalk.cyan.bold("╔════════════════════════════════════════════╗"));
|
|
77
|
+
console.log(chalk.cyan.bold("║ WELCOME TO MYAI TERMINAL ║"));
|
|
78
|
+
console.log(chalk.cyan.bold("╚════════════════════════════════════════════╝"));
|
|
79
|
+
console.log(chalk.dim("Type 'exit' or 'quit' to end the session.\n"));
|
|
80
|
+
|
|
68
81
|
let chatHistory = [];
|
|
69
82
|
|
|
70
83
|
while (true) {
|
|
@@ -72,22 +85,36 @@ program
|
|
|
72
85
|
{
|
|
73
86
|
type: "input",
|
|
74
87
|
name: "userInput",
|
|
75
|
-
message: "
|
|
88
|
+
message: chalk.green("? You:"),
|
|
89
|
+
validate: (input) => input.trim() !== "" || "Please enter a prompt."
|
|
76
90
|
}
|
|
77
91
|
]);
|
|
78
92
|
|
|
79
|
-
|
|
80
|
-
|
|
93
|
+
if (userInput.toLowerCase() === "exit" || userInput.toLowerCase() === "quit") {
|
|
94
|
+
console.log(chalk.yellow("\nGoodbye! 👋\n"));
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
81
97
|
|
|
82
98
|
const response = await getAIResponse(userInput, chatHistory);
|
|
83
99
|
|
|
84
100
|
if (response) {
|
|
85
|
-
|
|
101
|
+
console.log(chalk.blue.bold("\nAI:"));
|
|
102
|
+
console.log(chalk.white(response));
|
|
103
|
+
console.log("\n");
|
|
86
104
|
|
|
105
|
+
// Update history
|
|
87
106
|
chatHistory.push({ role: "user", parts: [{ text: userInput }] });
|
|
88
107
|
chatHistory.push({ role: "model", parts: [{ text: response }] });
|
|
89
108
|
}
|
|
90
109
|
}
|
|
91
110
|
});
|
|
92
111
|
|
|
112
|
+
function displayWelcome() {
|
|
113
|
+
console.log(chalk.cyan.bold("\n✨ MyAI Terminal Assistant ✨"));
|
|
114
|
+
console.log(chalk.white("Usage:"));
|
|
115
|
+
console.log(chalk.dim(" myai \"your question\" ") + chalk.white("- Ask a quick question"));
|
|
116
|
+
console.log(chalk.dim(" myai chat ") + chalk.white("- Start interactive session"));
|
|
117
|
+
console.log(chalk.dim(" myai --help ") + chalk.white("- Show help\n"));
|
|
118
|
+
}
|
|
119
|
+
|
|
93
120
|
program.parse();
|