@yamzzdev/aiyamz 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/bin/aiyamz.js ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { Command } = require('commander');
4
+ const chalk = require('chalk');
5
+ const inquirer = require('inquirer');
6
+ const ora = require('ora');
7
+ const figlet = require('figlet');
8
+ const AIYamz = require('../lib/index');
9
+ require('dotenv').config();
10
+
11
+ const program = new Command();
12
+
13
+ // Show banner
14
+ console.log(chalk.cyan(figlet.textSync('AIYamz', { font: 'Small' })));
15
+ console.log(chalk.gray('by yamzzdev - AI Chat Package (FREE)\n'));
16
+
17
+ program
18
+ .version('1.0.0')
19
+ .description('AI Chat CLI by yamzzdev - Powered by Google Gemini (FREE)');
20
+
21
+ program
22
+ .command('chat')
23
+ .description('Start interactive chat with AI')
24
+ .option('-k, --key <key>', 'Gemini API key')
25
+ .action(async (options) => {
26
+ const apiKey = options.key || process.env.GEMINI_API_KEY;
27
+
28
+ if (!apiKey) {
29
+ console.log(chalk.red('āŒ No API key found!'));
30
+ console.log(chalk.yellow('Get your free API key: https://aistudio.google.com/apikey'));
31
+ console.log(chalk.gray('Then run: export GEMINI_API_KEY=your_key_here\n'));
32
+ return;
33
+ }
34
+
35
+ const ai = new AIYamz(apiKey);
36
+
37
+ console.log(chalk.green('āœ… AI Ready! Type your message (type "exit" to quit)\n'));
38
+
39
+ while (true) {
40
+ const { message } = await inquirer.prompt([
41
+ {
42
+ type: 'input',
43
+ name: 'message',
44
+ message: chalk.cyan('You:'),
45
+ prefix: ''
46
+ }
47
+ ]);
48
+
49
+ if (message.toLowerCase() === 'exit') {
50
+ console.log(chalk.yellow('\nšŸ‘‹ Bye!'));
51
+ break;
52
+ }
53
+
54
+ if (message.toLowerCase() === 'clear') {
55
+ ai.clearHistory();
56
+ console.log(chalk.green('āœ… History cleared!\n'));
57
+ continue;
58
+ }
59
+
60
+ const spinner = ora(chalk.gray('AI is thinking...')).start();
61
+ const response = await ai.chat(message);
62
+ spinner.stop();
63
+
64
+ console.log(chalk.magenta('\nšŸ¤– AI:'), response, '\n');
65
+ }
66
+ });
67
+
68
+ program
69
+ .command('ask <question>')
70
+ .description('Ask a single question')
71
+ .option('-k, --key <key>', 'Gemini API key')
72
+ .action(async (question, options) => {
73
+ const apiKey = options.key || process.env.GEMINI_API_KEY;
74
+
75
+ if (!apiKey) {
76
+ console.log(chalk.red('āŒ No API key found!'));
77
+ return;
78
+ }
79
+
80
+ const ai = new AIYamz(apiKey);
81
+ const spinner = ora(chalk.gray('Thinking...')).start();
82
+ const response = await ai.chat(question);
83
+ spinner.stop();
84
+
85
+ console.log(chalk.magenta('\nšŸ¤– Answer:'), response);
86
+ });
87
+
88
+ program
89
+ .command('config')
90
+ .description('Setup API key')
91
+ .action(async () => {
92
+ const { apiKey } = await inquirer.prompt([
93
+ {
94
+ type: 'input',
95
+ name: 'apiKey',
96
+ message: 'Enter your Gemini API key:',
97
+ validate: (input) => input.length > 0 || 'API key is required'
98
+ }
99
+ ]);
100
+
101
+ const envPath = process.env.HOME + '/.aiyamz.env';
102
+ const envContent = `GEMINI_API_KEY=${apiKey}`;
103
+
104
+ require('fs').writeFileSync(envPath, envContent);
105
+ console.log(chalk.green(`āœ… API key saved to ${envPath}`));
106
+ console.log(chalk.gray('Add this to your shell config: export GEMINI_API_KEY=your_key'));
107
+ });
108
+
109
+ program.parse(process.argv);
110
+
111
+ if (!process.argv.slice(2).length) {
112
+ program.outputHelp();
113
+ }
package/lib/index.js ADDED
@@ -0,0 +1,74 @@
1
+ const GeminiProvider = require('./providers/gemini');
2
+ const chalk = require('chalk');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ class AIYamz {
7
+ constructor(apiKey) {
8
+ this.apiKey = apiKey || process.env.GEMINI_API_KEY;
9
+ if (!this.apiKey) {
10
+ console.log(chalk.yellow('āš ļø No API key found!'));
11
+ console.log(chalk.cyan('Get your free API key at: https://aistudio.google.com/apikey'));
12
+ console.log(chalk.gray('Then set it: export GEMINI_API_KEY=your_key_here\n'));
13
+ }
14
+ this.provider = new GeminiProvider(this.apiKey);
15
+ this.history = [];
16
+ }
17
+
18
+ async chat(message, options = {}) {
19
+ if (!this.apiKey) {
20
+ return 'āŒ No API key configured. Please set GEMINI_API_KEY environment variable.';
21
+ }
22
+
23
+ try {
24
+ const response = await this.provider.chat(message, options);
25
+
26
+ // Save to history
27
+ this.history.push({
28
+ role: 'user',
29
+ content: message,
30
+ timestamp: new Date().toISOString()
31
+ });
32
+ this.history.push({
33
+ role: 'ai',
34
+ content: response,
35
+ timestamp: new Date().toISOString()
36
+ });
37
+
38
+ return response;
39
+ } catch (error) {
40
+ return `āŒ Error: ${error.message}`;
41
+ }
42
+ }
43
+
44
+ async stream(message, callback) {
45
+ if (!this.apiKey) {
46
+ callback('āŒ No API key configured.');
47
+ return;
48
+ }
49
+
50
+ try {
51
+ await this.provider.streamChat(message, (chunk) => {
52
+ if (callback) callback(chunk);
53
+ });
54
+ } catch (error) {
55
+ callback(`āŒ Error: ${error.message}`);
56
+ }
57
+ }
58
+
59
+ getHistory() {
60
+ return this.history;
61
+ }
62
+
63
+ clearHistory() {
64
+ this.history = [];
65
+ return 'History cleared!';
66
+ }
67
+
68
+ async askQuestion(question) {
69
+ const response = await this.chat(question);
70
+ return response;
71
+ }
72
+ }
73
+
74
+ module.exports = AIYamz;
@@ -0,0 +1,40 @@
1
+ const { GoogleGenerativeAI } = require('@google/generative-ai');
2
+ const chalk = require('chalk');
3
+
4
+ class GeminiProvider {
5
+ constructor(apiKey) {
6
+ if (!apiKey) {
7
+ throw new Error('API Key is required! Get your API key at: https://aistudio.google.com/apikey');
8
+ }
9
+ this.genAI = new GoogleGenerativeAI(apiKey);
10
+ this.model = this.genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
11
+ }
12
+
13
+ async chat(message, options = {}) {
14
+ try {
15
+ const prompt = options.systemPrompt
16
+ ? `${options.systemPrompt}\n\nUser: ${message}`
17
+ : message;
18
+
19
+ const result = await this.model.generateContent(prompt);
20
+ const response = await result.response;
21
+ return response.text();
22
+ } catch (error) {
23
+ throw new Error(`Gemini API Error: ${error.message}`);
24
+ }
25
+ }
26
+
27
+ async streamChat(message, onChunk) {
28
+ try {
29
+ const result = await this.model.generateContentStream(message);
30
+ for await (const chunk of result.stream) {
31
+ const chunkText = chunk.text();
32
+ if (onChunk) onChunk(chunkText);
33
+ }
34
+ } catch (error) {
35
+ throw new Error(`Stream error: ${error.message}`);
36
+ }
37
+ }
38
+ }
39
+
40
+ module.exports = GeminiProvider;
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@yamzzdev/aiyamz",
3
+ "version": "1.0.0",
4
+ "description": "AI chat package by yamzzdev - powered by Google Gemini (FREE)",
5
+ "main": "lib/index.js",
6
+ "bin": {
7
+ "aiyamz": "./bin/aiyamz.js"
8
+ },
9
+ "keywords": ["ai", "chat", "gemini", "yamzzdev", "gabut"],
10
+ "author": "yamzzdev",
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "@google/generative-ai": "^0.21.0",
14
+ "chalk": "^4.1.2",
15
+ "commander": "^12.1.0",
16
+ "inquirer": "^8.2.6",
17
+ "ora": "^5.4.1",
18
+ "figlet": "^1.7.0",
19
+ "dotenv": "^16.4.5"
20
+ }
21
+ }