ask-my-llm 1.1.1 → 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.
- package/index.js +24 -9
- 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
|
-
|
|
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(
|
|
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('
|
|
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,
|