ask-my-llm 1.1.1 → 1.1.3

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 (2) hide show
  1. package/index.js +37 -10
  2. package/package.json +1 -1
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,
@@ -120,4 +135,16 @@ function parseResponse(stdout) {
120
135
  }
121
136
  }
122
137
 
123
- module.exports = { ask, askAsync };
138
+ /**
139
+ * Returns the model name from the current configuration.
140
+ * Synchronous.
141
+ * @param {Object|string} [options] - Same as in ask() / askAsync().
142
+ * @returns {string} Model identifier, e.g. "google/gemma-3-4b-it"
143
+ * @throws {Error} If configuration is missing or invalid.
144
+ */
145
+ function getModel(options) {
146
+ const config = loadConfig(options);
147
+ return config.model;
148
+ }
149
+
150
+ module.exports = { ask, askAsync, getModel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ask-my-llm",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Oversimplified AI usage npm module",
5
5
  "main": "index.js",
6
6
  "bin": {