ask-my-llm 1.0.2 → 1.0.4
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 +5 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -28,9 +28,11 @@ function ask(prompt) {
|
|
|
28
28
|
const url = baseUrl + '/chat/completions';
|
|
29
29
|
|
|
30
30
|
const args = [
|
|
31
|
-
'-s', '-X', 'POST',
|
|
31
|
+
'-s', '-S', '-X', 'POST',
|
|
32
32
|
'-H', 'Content-Type: application/json',
|
|
33
33
|
'-H', config.apiKey ? `Authorization: Bearer ${config.apiKey}` : '',
|
|
34
|
+
'-H', 'HTTP-Referer: https://www.npmjs.com/package/ask-my-llm',
|
|
35
|
+
'-H', 'X-OpenRouter-Title: ask-my-llm',
|
|
34
36
|
'-d', postData,
|
|
35
37
|
url
|
|
36
38
|
];
|
|
@@ -38,13 +40,13 @@ function ask(prompt) {
|
|
|
38
40
|
const result = spawnSync('curl', args, { encoding: 'utf8' });
|
|
39
41
|
|
|
40
42
|
if (result.error) throw result.error;
|
|
41
|
-
if (result.status !== 0) throw new Error('curl failed: ' + result.stderr);
|
|
43
|
+
if (result.status !== 0) throw new Error('curl failed: ' + (result.stderr || result.stdout));
|
|
42
44
|
|
|
43
45
|
const parsed = JSON.parse(result.stdout);
|
|
44
46
|
if (parsed.choices && parsed.choices[0]) {
|
|
45
47
|
return parsed.choices[0].message.content;
|
|
46
48
|
} else {
|
|
47
|
-
throw new Error('
|
|
49
|
+
throw new Error('API Error: ' + result.stdout);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
|