@saltcorn/large-language-model 0.8.7 → 0.8.9
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/constants.js +3 -0
- package/generate.js +31 -3
- package/package.json +1 -1
package/constants.js
CHANGED
package/generate.js
CHANGED
|
@@ -165,7 +165,16 @@ const getCompletion = async (config, opts) => {
|
|
|
165
165
|
|
|
166
166
|
const getCompletionOpenAICompatible = async (
|
|
167
167
|
{ chatCompleteEndpoint, bearer, apiKey, model, responses_api, temperature },
|
|
168
|
-
{
|
|
168
|
+
{
|
|
169
|
+
systemPrompt,
|
|
170
|
+
prompt,
|
|
171
|
+
debugResult,
|
|
172
|
+
debugCollector,
|
|
173
|
+
chat = [],
|
|
174
|
+
api_key,
|
|
175
|
+
endpoint,
|
|
176
|
+
...rest
|
|
177
|
+
}
|
|
169
178
|
) => {
|
|
170
179
|
const headers = {
|
|
171
180
|
"Content-Type": "application/json",
|
|
@@ -173,9 +182,10 @@ const getCompletionOpenAICompatible = async (
|
|
|
173
182
|
};
|
|
174
183
|
if (bearer) headers.Authorization = "Bearer " + bearer;
|
|
175
184
|
if (apiKey) headers["api-key"] = apiKey;
|
|
185
|
+
const use_model = rest.model || model;
|
|
176
186
|
const body = {
|
|
177
187
|
//prompt: "How are you?",
|
|
178
|
-
model:
|
|
188
|
+
model: use_model,
|
|
179
189
|
...rest,
|
|
180
190
|
};
|
|
181
191
|
if (rest.temperature || temperature) {
|
|
@@ -184,7 +194,18 @@ const getCompletionOpenAICompatible = async (
|
|
|
184
194
|
} else if (rest.temperature === null) {
|
|
185
195
|
delete body.temperature;
|
|
186
196
|
} else if (typeof temperature === "undefined") {
|
|
187
|
-
|
|
197
|
+
if (
|
|
198
|
+
![
|
|
199
|
+
"o1",
|
|
200
|
+
"o3",
|
|
201
|
+
"o3-mini",
|
|
202
|
+
"o4-mini",
|
|
203
|
+
"gtp-5",
|
|
204
|
+
"gtp-5-nano",
|
|
205
|
+
"gtp-5-mini",
|
|
206
|
+
].includes(use_model)
|
|
207
|
+
)
|
|
208
|
+
body.temperature = 0.7;
|
|
188
209
|
}
|
|
189
210
|
|
|
190
211
|
if (responses_api) {
|
|
@@ -281,6 +302,8 @@ const getCompletionOpenAICompatible = async (
|
|
|
281
302
|
body
|
|
282
303
|
)} to ${chatCompleteEndpoint} headers ${JSON.stringify(headers)}`
|
|
283
304
|
);
|
|
305
|
+
if (debugCollector) debugCollector.request = body;
|
|
306
|
+
|
|
284
307
|
const rawResponse = await fetch(chatCompleteEndpoint, {
|
|
285
308
|
method: "POST",
|
|
286
309
|
headers,
|
|
@@ -291,6 +314,8 @@ const getCompletionOpenAICompatible = async (
|
|
|
291
314
|
if (debugResult)
|
|
292
315
|
console.log("OpenAI response", JSON.stringify(results, null, 2));
|
|
293
316
|
else getState().log(6, `OpenAI response ${JSON.stringify(results)}`);
|
|
317
|
+
if (debugCollector) debugCollector.response = results;
|
|
318
|
+
|
|
294
319
|
if (results.error) throw new Error(`OpenAI error: ${results.error.message}`);
|
|
295
320
|
if (responses_api) {
|
|
296
321
|
const textOutput = results.output
|
|
@@ -341,6 +366,7 @@ const getImageGenOpenAICompatible = async (
|
|
|
341
366
|
prompt,
|
|
342
367
|
model,
|
|
343
368
|
debugResult,
|
|
369
|
+
debugCollector,
|
|
344
370
|
size,
|
|
345
371
|
quality,
|
|
346
372
|
n,
|
|
@@ -367,6 +393,7 @@ const getImageGenOpenAICompatible = async (
|
|
|
367
393
|
if (response_format) body.response_format = response_format;
|
|
368
394
|
if (n) body.n = n;
|
|
369
395
|
if (debugResult) console.log("OpenAI image request", imageEndpoint, body);
|
|
396
|
+
if (debugCollector) debugCollector.request = body;
|
|
370
397
|
|
|
371
398
|
const rawResponse = await fetch(imageEndpoint, {
|
|
372
399
|
method: "POST",
|
|
@@ -374,6 +401,7 @@ const getImageGenOpenAICompatible = async (
|
|
|
374
401
|
body: JSON.stringify(body),
|
|
375
402
|
});
|
|
376
403
|
const results = await rawResponse.json();
|
|
404
|
+
if (debugCollector) debugCollector.response = results;
|
|
377
405
|
if (debugResult) console.log("OpenAI image response", results);
|
|
378
406
|
if (results.error) throw new Error(`OpenAI error: ${results.error.message}`);
|
|
379
407
|
return results?.data?.[0];
|