ask-my-llm 1.0.7 → 1.0.9
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/ask-ai +124 -8
- package/index.js +7 -2
- package/package.json +2 -2
package/bin/ask-ai
CHANGED
|
@@ -10,18 +10,111 @@ function loadConfig() {
|
|
|
10
10
|
try {
|
|
11
11
|
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
|
|
12
12
|
} catch (e) {
|
|
13
|
-
return
|
|
13
|
+
return null;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
function saveConfig(config) {
|
|
18
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function mainMenu() {
|
|
22
|
+
let config = loadConfig();
|
|
19
23
|
|
|
24
|
+
if (!config || !config.configs || Object.keys(config.configs).length === 0) {
|
|
25
|
+
console.log('No configs found. Creating first one...');
|
|
26
|
+
await addConfig({ current: null, configs: {} });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const choices = ['Add new config', 'Select config', 'Edit config', 'Remove config'];
|
|
31
|
+
|
|
32
|
+
const { action } = await inquirer.prompt([{
|
|
33
|
+
type: 'list',
|
|
34
|
+
name: 'action',
|
|
35
|
+
message: `Current: ${config.current}`,
|
|
36
|
+
choices
|
|
37
|
+
}]);
|
|
38
|
+
|
|
39
|
+
if (action === 'Add new config') {
|
|
40
|
+
await addConfig(config);
|
|
41
|
+
} else if (action === 'Select config') {
|
|
42
|
+
await selectConfig(config);
|
|
43
|
+
} else if (action === 'Edit config') {
|
|
44
|
+
await editConfig(config);
|
|
45
|
+
} else if (action === 'Remove config') {
|
|
46
|
+
await removeConfig(config);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function addConfig(config) {
|
|
51
|
+
const { name } = await inquirer.prompt([{
|
|
52
|
+
type: 'input',
|
|
53
|
+
name: 'name',
|
|
54
|
+
message: 'Config name:'
|
|
55
|
+
}]);
|
|
56
|
+
|
|
57
|
+
if (config.configs[name]) {
|
|
58
|
+
console.log('Config already exists. Edit it instead.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const answers = await inquirer.prompt([
|
|
63
|
+
{
|
|
64
|
+
type: 'input',
|
|
65
|
+
name: 'baseApi',
|
|
66
|
+
message: 'Base API URL:',
|
|
67
|
+
default: 'https://api.openai.com/v1'
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'input',
|
|
71
|
+
name: 'apiKey',
|
|
72
|
+
message: 'API Key (leave empty for none):',
|
|
73
|
+
default: ''
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: 'input',
|
|
77
|
+
name: 'model',
|
|
78
|
+
message: 'Model:',
|
|
79
|
+
default: 'gpt-3.5-turbo'
|
|
80
|
+
}
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
config.configs[name] = answers;
|
|
84
|
+
config.current = name;
|
|
85
|
+
saveConfig(config);
|
|
86
|
+
console.log(`Config '${name}' saved.`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function selectConfig(config) {
|
|
90
|
+
const names = Object.keys(config.configs);
|
|
91
|
+
const { name } = await inquirer.prompt([{
|
|
92
|
+
type: 'list',
|
|
93
|
+
name: 'name',
|
|
94
|
+
message: 'Select config:',
|
|
95
|
+
choices: names
|
|
96
|
+
}]);
|
|
97
|
+
|
|
98
|
+
config.current = name;
|
|
99
|
+
saveConfig(config);
|
|
100
|
+
console.log(`Using '${name}'.`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function editConfig(config) {
|
|
104
|
+
const names = Object.keys(config.configs);
|
|
105
|
+
const { name } = await inquirer.prompt([{
|
|
106
|
+
type: 'list',
|
|
107
|
+
name: 'name',
|
|
108
|
+
message: 'Edit config:',
|
|
109
|
+
choices: names
|
|
110
|
+
}]);
|
|
111
|
+
|
|
112
|
+
const existing = config.configs[name];
|
|
20
113
|
const answers = await inquirer.prompt([
|
|
21
114
|
{
|
|
22
115
|
type: 'input',
|
|
23
116
|
name: 'baseApi',
|
|
24
|
-
message: 'Base API URL
|
|
117
|
+
message: 'Base API URL:',
|
|
25
118
|
default: existing.baseApi
|
|
26
119
|
},
|
|
27
120
|
{
|
|
@@ -33,13 +126,36 @@ async function setup() {
|
|
|
33
126
|
{
|
|
34
127
|
type: 'input',
|
|
35
128
|
name: 'model',
|
|
36
|
-
message: 'Model
|
|
129
|
+
message: 'Model:',
|
|
37
130
|
default: existing.model
|
|
38
131
|
}
|
|
39
132
|
]);
|
|
40
133
|
|
|
41
|
-
|
|
42
|
-
|
|
134
|
+
config.configs[name] = answers;
|
|
135
|
+
saveConfig(config);
|
|
136
|
+
console.log(`Config '${name}' updated.`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function removeConfig(config) {
|
|
140
|
+
const names = Object.keys(config.configs);
|
|
141
|
+
if (names.length <= 1) {
|
|
142
|
+
console.log('Cannot remove last config.');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const { name } = await inquirer.prompt([{
|
|
147
|
+
type: 'list',
|
|
148
|
+
name: 'name',
|
|
149
|
+
message: 'Remove config:',
|
|
150
|
+
choices: names
|
|
151
|
+
}]);
|
|
152
|
+
|
|
153
|
+
delete config.configs[name];
|
|
154
|
+
if (config.current === name) {
|
|
155
|
+
config.current = Object.keys(config.configs)[0];
|
|
156
|
+
}
|
|
157
|
+
saveConfig(config);
|
|
158
|
+
console.log(`Config '${name}' removed.`);
|
|
43
159
|
}
|
|
44
160
|
|
|
45
|
-
|
|
161
|
+
mainMenu();
|
package/index.js
CHANGED
|
@@ -6,9 +6,14 @@ const CONFIG_PATH = path.join(process.env.HOME || process.env.USERPROFILE, '.ask
|
|
|
6
6
|
|
|
7
7
|
function loadConfig() {
|
|
8
8
|
try {
|
|
9
|
-
|
|
9
|
+
const data = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
|
|
10
|
+
const current = data.current || 'default';
|
|
11
|
+
if (!data.configs || !data.configs[current]) {
|
|
12
|
+
throw new Error('No config found. Run `npx ask-my-llm` first.');
|
|
13
|
+
}
|
|
14
|
+
return data.configs[current];
|
|
10
15
|
} catch (e) {
|
|
11
|
-
throw new Error('Not configured. Run `npx ask-
|
|
16
|
+
throw new Error('Not configured. Run `npx ask-my-llm` first.');
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ask-my-llm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Oversimplified AI usage npm module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"ask-
|
|
7
|
+
"ask-my-llm": "./bin/ask-ai"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|