ask-my-llm 1.0.8 → 1.1.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.
Files changed (3) hide show
  1. package/bin/ask-ai +47 -8
  2. package/index.js +9 -2
  3. 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 { current: 'default', configs: { default: { baseApi: 'https://api.openai.com/v1', apiKey: '', model: 'gpt-3.5-turbo' } } };
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
- const config = loadConfig();
23
- const choices = ['Add new config', 'Select config', 'Remove config'];
22
+ let config = loadConfig();
24
23
 
25
- if (config.current) {
26
- choices.unshift(`Use current (${config.current})`);
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: 'Manage configs:',
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/index.js CHANGED
@@ -7,8 +7,15 @@ const CONFIG_PATH = path.join(process.env.HOME || process.env.USERPROFILE, '.ask
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]) {
10
+
11
+ // Old format: direct baseApi, apiKey, model
12
+ if (!data.configs) {
13
+ return data;
14
+ }
15
+
16
+ // New format with configs
17
+ const current = data.current || Object.keys(data.configs)[0];
18
+ if (!data.configs[current]) {
12
19
  throw new Error('No config found. Run `npx ask-my-llm` first.');
13
20
  }
14
21
  return data.configs[current];
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "ask-my-llm",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "Oversimplified AI usage npm module",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "ask-ai": "./bin/ask-ai"
7
+ "ask-my-llm": "./bin/ask-ai"
8
8
  },
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1"