ask-my-llm 1.1.0 → 1.1.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 +18 -1
  2. package/index.js +24 -9
  3. package/package.json +1 -1
package/bin/ask-ai CHANGED
@@ -3,6 +3,7 @@
3
3
  const inquirer = require('inquirer');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
+ const { ask } = require('../index.js');
6
7
 
7
8
  const CONFIG_PATH = path.join(process.env.HOME || process.env.USERPROFILE, '.askairc');
8
9
 
@@ -18,6 +19,20 @@ function saveConfig(config) {
18
19
  fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
19
20
  }
20
21
 
22
+ async function testConfig(config) {
23
+ const { prompt } = await inquirer.prompt([{
24
+ type: 'input',
25
+ name: 'prompt',
26
+ message: 'Enter prompt:'
27
+ }]);
28
+
29
+ try {
30
+ console.log('Response:', ask(prompt));
31
+ } catch (e) {
32
+ console.log('Error:', e.message);
33
+ }
34
+ }
35
+
21
36
  async function mainMenu() {
22
37
  let config = loadConfig();
23
38
 
@@ -27,7 +42,7 @@ async function mainMenu() {
27
42
  return;
28
43
  }
29
44
 
30
- const choices = ['Add new config', 'Select config', 'Edit config', 'Remove config'];
45
+ const choices = ['Add new config', 'Select config', 'Edit config', 'Remove config', 'Test config'];
31
46
 
32
47
  const { action } = await inquirer.prompt([{
33
48
  type: 'list',
@@ -44,6 +59,8 @@ async function mainMenu() {
44
59
  await editConfig(config);
45
60
  } else if (action === 'Remove config') {
46
61
  await removeConfig(config);
62
+ } else if (action === 'Test config') {
63
+ await testConfig(config);
47
64
  }
48
65
  }
49
66
 
package/index.js CHANGED
@@ -2,11 +2,26 @@ const { spawnSync, spawn } = require('child_process');
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
4
 
5
- const CONFIG_PATH = path.join(process.env.HOME || process.env.USERPROFILE, '.askairc');
5
+ function getDefaultConfigPath() {
6
+ return path.join(process.env.HOME || process.env.USERPROFILE, '.askairc');
7
+ }
6
8
 
7
- function loadConfig() {
9
+ function loadConfig(options) {
10
+ let configPath;
11
+ let configName;
12
+
13
+ if (typeof options === 'string') {
14
+ // String is config file path
15
+ configPath = options;
16
+ } else if (options && typeof options === 'object') {
17
+ configPath = options.configPath || getDefaultConfigPath();
18
+ configName = options.configName;
19
+ } else {
20
+ configPath = getDefaultConfigPath();
21
+ }
22
+
8
23
  try {
9
- const data = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
24
+ const data = JSON.parse(fs.readFileSync(configPath, 'utf8'));
10
25
 
11
26
  // Old format: direct baseApi, apiKey, model
12
27
  if (!data.configs) {
@@ -14,9 +29,9 @@ function loadConfig() {
14
29
  }
15
30
 
16
31
  // New format with configs
17
- const current = data.current || Object.keys(data.configs)[0];
32
+ const current = configName || data.current || Object.keys(data.configs)[0];
18
33
  if (!data.configs[current]) {
19
- throw new Error('No config found. Run `npx ask-my-llm` first.');
34
+ throw new Error(`Config '${current}' not found.`);
20
35
  }
21
36
  return data.configs[current];
22
37
  } catch (e) {
@@ -24,8 +39,8 @@ function loadConfig() {
24
39
  }
25
40
  }
26
41
 
27
- function ask(prompt) {
28
- const config = loadConfig();
42
+ function ask(prompt, options) {
43
+ const config = loadConfig(options);
29
44
 
30
45
  const postData = JSON.stringify({
31
46
  model: config.model,
@@ -63,9 +78,9 @@ function ask(prompt) {
63
78
  return parseResponse(result.stdout);
64
79
  }
65
80
 
66
- function askAsync(prompt) {
81
+ function askAsync(prompt, options) {
67
82
  return new Promise((resolve, reject) => {
68
- const config = loadConfig();
83
+ const config = loadConfig(options);
69
84
 
70
85
  const postData = JSON.stringify({
71
86
  model: config.model,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ask-my-llm",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Oversimplified AI usage npm module",
5
5
  "main": "index.js",
6
6
  "bin": {