@semalt-ai/code 1.4.0 → 1.4.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/README.md +1 -1
- package/index.js +10 -4
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -12,6 +12,8 @@ const { URL } = require('url');
|
|
|
12
12
|
|
|
13
13
|
const PACKAGE_JSON = require('./package.json');
|
|
14
14
|
|
|
15
|
+
const DEFAULT_API_TIMEOUT_MS = 15 * 60 * 1000;
|
|
16
|
+
|
|
15
17
|
// ── Config ────────────────────────────────────────────────────────────────────
|
|
16
18
|
|
|
17
19
|
const DEFAULT_CONFIG = {
|
|
@@ -19,7 +21,7 @@ const DEFAULT_CONFIG = {
|
|
|
19
21
|
api_key: 'any',
|
|
20
22
|
default_model: 'default',
|
|
21
23
|
temperature: 0.7,
|
|
22
|
-
|
|
24
|
+
request_timeout_ms: DEFAULT_API_TIMEOUT_MS,
|
|
23
25
|
stream: true,
|
|
24
26
|
models: [],
|
|
25
27
|
};
|
|
@@ -528,16 +530,20 @@ async function chatStream(messages, { model, temperature, maxTokens } = {}) {
|
|
|
528
530
|
model: model || config.default_model,
|
|
529
531
|
messages,
|
|
530
532
|
temperature: temperature !== undefined ? temperature : config.temperature,
|
|
531
|
-
max_tokens: maxTokens || config.max_tokens,
|
|
532
533
|
stream: true,
|
|
533
534
|
};
|
|
534
535
|
|
|
536
|
+
if (maxTokens !== undefined) {
|
|
537
|
+
payload.max_tokens = maxTokens;
|
|
538
|
+
}
|
|
539
|
+
|
|
535
540
|
const body = JSON.stringify(payload);
|
|
536
541
|
let res;
|
|
537
542
|
|
|
538
543
|
try {
|
|
539
544
|
res = await httpRequest(apiUrl('/v1/chat/completions'), {
|
|
540
545
|
method: 'POST',
|
|
546
|
+
timeout: config.request_timeout_ms,
|
|
541
547
|
headers: {
|
|
542
548
|
'Content-Type': 'application/json',
|
|
543
549
|
'Authorization': `Bearer ${config.api_key}`,
|
|
@@ -629,7 +635,6 @@ async function chatSync(messages, { model } = {}) {
|
|
|
629
635
|
model: model || config.default_model,
|
|
630
636
|
messages,
|
|
631
637
|
temperature: config.temperature,
|
|
632
|
-
max_tokens: config.max_tokens,
|
|
633
638
|
stream: false,
|
|
634
639
|
};
|
|
635
640
|
|
|
@@ -639,6 +644,7 @@ async function chatSync(messages, { model } = {}) {
|
|
|
639
644
|
try {
|
|
640
645
|
res = await httpRequest(apiUrl('/v1/chat/completions'), {
|
|
641
646
|
method: 'POST',
|
|
647
|
+
timeout: config.request_timeout_ms,
|
|
642
648
|
headers: {
|
|
643
649
|
'Content-Type': 'application/json',
|
|
644
650
|
'Authorization': `Bearer ${config.api_key}`,
|
|
@@ -1125,7 +1131,7 @@ function cmdInit(opts) {
|
|
|
1125
1131
|
api_key: opts.apiKey || 'any',
|
|
1126
1132
|
default_model: opts.defaultModel || 'default',
|
|
1127
1133
|
temperature: 0.7,
|
|
1128
|
-
|
|
1134
|
+
request_timeout_ms: DEFAULT_API_TIMEOUT_MS,
|
|
1129
1135
|
stream: true,
|
|
1130
1136
|
models: config.models,
|
|
1131
1137
|
};
|