ask-my-llm 1.0.8 → 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 +47 -8
- package/package.json +2 -2
package/bin/ask-ai
CHANGED
|
@@ -10,7 +10,7 @@ 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
|
|
|
@@ -19,17 +19,20 @@ function saveConfig(config) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
async function mainMenu() {
|
|
22
|
-
|
|
23
|
-
const choices = ['Add new config', 'Select config', 'Remove config'];
|
|
22
|
+
let config = loadConfig();
|
|
24
23
|
|
|
25
|
-
if (config.
|
|
26
|
-
|
|
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;
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
const choices = ['Add new config', 'Select config', 'Edit config', 'Remove config'];
|
|
31
|
+
|
|
29
32
|
const { action } = await inquirer.prompt([{
|
|
30
33
|
type: 'list',
|
|
31
34
|
name: 'action',
|
|
32
|
-
message:
|
|
35
|
+
message: `Current: ${config.current}`,
|
|
33
36
|
choices
|
|
34
37
|
}]);
|
|
35
38
|
|
|
@@ -37,10 +40,10 @@ async function mainMenu() {
|
|
|
37
40
|
await addConfig(config);
|
|
38
41
|
} else if (action === 'Select config') {
|
|
39
42
|
await selectConfig(config);
|
|
43
|
+
} else if (action === 'Edit config') {
|
|
44
|
+
await editConfig(config);
|
|
40
45
|
} else if (action === 'Remove config') {
|
|
41
46
|
await removeConfig(config);
|
|
42
|
-
} else {
|
|
43
|
-
console.log(`Current: ${config.current}`);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
|
|
@@ -97,6 +100,42 @@ async function selectConfig(config) {
|
|
|
97
100
|
console.log(`Using '${name}'.`);
|
|
98
101
|
}
|
|
99
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];
|
|
113
|
+
const answers = await inquirer.prompt([
|
|
114
|
+
{
|
|
115
|
+
type: 'input',
|
|
116
|
+
name: 'baseApi',
|
|
117
|
+
message: 'Base API URL:',
|
|
118
|
+
default: existing.baseApi
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: 'input',
|
|
122
|
+
name: 'apiKey',
|
|
123
|
+
message: 'API Key (leave empty for none):',
|
|
124
|
+
default: existing.apiKey || ''
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: 'input',
|
|
128
|
+
name: 'model',
|
|
129
|
+
message: 'Model:',
|
|
130
|
+
default: existing.model
|
|
131
|
+
}
|
|
132
|
+
]);
|
|
133
|
+
|
|
134
|
+
config.configs[name] = answers;
|
|
135
|
+
saveConfig(config);
|
|
136
|
+
console.log(`Config '${name}' updated.`);
|
|
137
|
+
}
|
|
138
|
+
|
|
100
139
|
async function removeConfig(config) {
|
|
101
140
|
const names = Object.keys(config.configs);
|
|
102
141
|
if (names.length <= 1) {
|
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"
|