ask-my-llm 1.0.0 → 1.0.2

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 +13 -3
  2. package/index.js +6 -3
  3. package/package.json +1 -1
package/bin/ask-ai CHANGED
@@ -6,25 +6,35 @@ const path = require('path');
6
6
 
7
7
  const CONFIG_PATH = path.join(process.env.HOME || process.env.USERPROFILE, '.askairc');
8
8
 
9
+ function loadConfig() {
10
+ try {
11
+ return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
12
+ } catch (e) {
13
+ return { baseApi: 'https://api.openai.com/v1', apiKey: '', model: 'gpt-3.5-turbo' };
14
+ }
15
+ }
16
+
9
17
  async function setup() {
18
+ const existing = loadConfig();
19
+
10
20
  const answers = await inquirer.prompt([
11
21
  {
12
22
  type: 'input',
13
23
  name: 'baseApi',
14
24
  message: 'Base API URL (e.g., https://api.openai.com/v1):',
15
- default: 'https://api.openai.com/v1'
25
+ default: existing.baseApi
16
26
  },
17
27
  {
18
28
  type: 'input',
19
29
  name: 'apiKey',
20
30
  message: 'API Key (leave empty for none):',
21
- default: ''
31
+ default: existing.apiKey || ''
22
32
  },
23
33
  {
24
34
  type: 'input',
25
35
  name: 'model',
26
36
  message: 'Model (e.g., gpt-3.5-turbo):',
27
- default: 'gpt-3.5-turbo'
37
+ default: existing.model
28
38
  }
29
39
  ]);
30
40
 
package/index.js CHANGED
@@ -21,15 +21,18 @@ function ask(prompt) {
21
21
  temperature: 0.7
22
22
  });
23
23
 
24
- const url = new URL('/v1/chat/completions', config.baseApi);
25
- const isHttps = url.protocol === 'https:';
24
+ let baseUrl = config.baseApi.replace(/\/$/, '');
25
+ if (!baseUrl.endsWith('/v1')) {
26
+ baseUrl += '/v1';
27
+ }
28
+ const url = baseUrl + '/chat/completions';
26
29
 
27
30
  const args = [
28
31
  '-s', '-X', 'POST',
29
32
  '-H', 'Content-Type: application/json',
30
33
  '-H', config.apiKey ? `Authorization: Bearer ${config.apiKey}` : '',
31
34
  '-d', postData,
32
- `${url.protocol}//${url.host}${url.pathname}`
35
+ url
33
36
  ];
34
37
 
35
38
  const result = spawnSync('curl', args, { encoding: 'utf8' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ask-my-llm",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Oversimplified AI usage npm module",
5
5
  "main": "index.js",
6
6
  "bin": {