@saltcorn/large-language-model 1.0.1 → 1.0.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/constants.js +17 -2
- package/generate.js +21 -30
- package/index.js +28 -2
- package/package.json +2 -1
- package/tests/configs.js +10 -0
package/constants.js
CHANGED
|
@@ -7,9 +7,10 @@ const OPENAI_MODELS = [
|
|
|
7
7
|
"gpt-5",
|
|
8
8
|
"gpt-5-mini",
|
|
9
9
|
"gpt-5-nano",
|
|
10
|
-
"gpt-5.1",
|
|
10
|
+
"gpt-5.1",
|
|
11
11
|
"gpt-5.2",
|
|
12
12
|
"gpt-5.2-pro",
|
|
13
|
+
"gpt-5.4",
|
|
13
14
|
"o3",
|
|
14
15
|
"o3-mini",
|
|
15
16
|
"o3-pro",
|
|
@@ -21,6 +22,20 @@ const OPENAI_MODELS = [
|
|
|
21
22
|
"gpt-5.1-codex-max",
|
|
22
23
|
];
|
|
23
24
|
|
|
25
|
+
const NO_TEMP_MODELS = [
|
|
26
|
+
"o1",
|
|
27
|
+
"o3",
|
|
28
|
+
"o3-mini",
|
|
29
|
+
"o4-mini",
|
|
30
|
+
"gpt-5",
|
|
31
|
+
"gpt-5-nano",
|
|
32
|
+
"gpt-5-mini",
|
|
33
|
+
"gpt-5.1",
|
|
34
|
+
"gpt-5.1-codex",
|
|
35
|
+
"gpt-5.2",
|
|
36
|
+
"gpt-5.4",
|
|
37
|
+
];
|
|
38
|
+
|
|
24
39
|
// https://github.com/ollama/ollama/blob/main/docs/faq.md#where-are-models-stored
|
|
25
40
|
const OLLAMA_MODELS_PATH = {
|
|
26
41
|
Darwin: `${process.env.HOME}/.ollama/models`,
|
|
@@ -28,4 +43,4 @@ const OLLAMA_MODELS_PATH = {
|
|
|
28
43
|
Windows_NT: "C:\\Users\\%username%\\.ollama\\models.",
|
|
29
44
|
};
|
|
30
45
|
|
|
31
|
-
module.exports = { OPENAI_MODELS, OLLAMA_MODELS_PATH };
|
|
46
|
+
module.exports = { OPENAI_MODELS, OLLAMA_MODELS_PATH, NO_TEMP_MODELS };
|
package/generate.js
CHANGED
|
@@ -23,8 +23,10 @@ const {
|
|
|
23
23
|
experimental_transcribe,
|
|
24
24
|
} = require("ai");
|
|
25
25
|
const { createOpenAI } = require("@ai-sdk/openai");
|
|
26
|
+
const { createAnthropic } = require("@ai-sdk/anthropic");
|
|
26
27
|
const OpenAI = require("openai");
|
|
27
28
|
const { ElevenLabsClient } = require("@elevenlabs/elevenlabs-js");
|
|
29
|
+
const { NO_TEMP_MODELS } = require("./constants");
|
|
28
30
|
|
|
29
31
|
let ollamaMod;
|
|
30
32
|
if (features.esm_plugins) ollamaMod = require("ollama");
|
|
@@ -348,6 +350,7 @@ const getCompletion = async (config, opts) => {
|
|
|
348
350
|
case "AI SDK":
|
|
349
351
|
return await getCompletionAISDK(
|
|
350
352
|
{
|
|
353
|
+
...config,
|
|
351
354
|
provider: config.ai_sdk_provider,
|
|
352
355
|
apiKey: config.api_key,
|
|
353
356
|
model: opts?.model || config.model,
|
|
@@ -420,18 +423,28 @@ const getCompletion = async (config, opts) => {
|
|
|
420
423
|
}
|
|
421
424
|
};
|
|
422
425
|
|
|
423
|
-
const getAiSdkModel = ({
|
|
426
|
+
const getAiSdkModel = ({
|
|
427
|
+
provider,
|
|
428
|
+
api_key,
|
|
429
|
+
model_name,
|
|
430
|
+
anthropic_api_key,
|
|
431
|
+
}) => {
|
|
424
432
|
switch (provider) {
|
|
425
433
|
case "OpenAI":
|
|
426
434
|
const openai = createOpenAI({ apiKey: api_key });
|
|
427
435
|
return openai(model_name);
|
|
436
|
+
case "Anthropic":
|
|
437
|
+
const anthropic = createAnthropic({
|
|
438
|
+
apiKey: anthropic_api_key,
|
|
439
|
+
});
|
|
440
|
+
return anthropic(model_name);
|
|
428
441
|
default:
|
|
429
442
|
throw new Error("Provider not found: " + provider);
|
|
430
443
|
}
|
|
431
444
|
};
|
|
432
445
|
|
|
433
446
|
const getCompletionAISDK = async (
|
|
434
|
-
{ apiKey, model, provider, temperature },
|
|
447
|
+
{ apiKey, model, provider, temperature, anthropic_api_key },
|
|
435
448
|
{
|
|
436
449
|
systemPrompt,
|
|
437
450
|
prompt,
|
|
@@ -449,6 +462,7 @@ const getCompletionAISDK = async (
|
|
|
449
462
|
model_name: use_model_name,
|
|
450
463
|
api_key: api_key || apiKey,
|
|
451
464
|
provider,
|
|
465
|
+
anthropic_api_key,
|
|
452
466
|
});
|
|
453
467
|
const modifyChat = (chat) => {
|
|
454
468
|
const f = (c) => {
|
|
@@ -481,27 +495,15 @@ const getCompletionAISDK = async (
|
|
|
481
495
|
if (appendToChat && chat && prompt) {
|
|
482
496
|
chat.push({ role: "user", content: prompt });
|
|
483
497
|
}
|
|
484
|
-
if (
|
|
498
|
+
if (NO_TEMP_MODELS.includes(use_model_name)) {
|
|
499
|
+
delete body.temperature;
|
|
500
|
+
} else if (rest.temperature || temperature) {
|
|
485
501
|
const str_or_num = rest.temperature || temperature;
|
|
486
502
|
body.temperature = +str_or_num;
|
|
487
503
|
} else if (rest.temperature === null) {
|
|
488
504
|
delete body.temperature;
|
|
489
505
|
} else if (typeof temperature === "undefined") {
|
|
490
|
-
if (
|
|
491
|
-
![
|
|
492
|
-
"o1",
|
|
493
|
-
"o3",
|
|
494
|
-
"o3-mini",
|
|
495
|
-
"o4-mini",
|
|
496
|
-
"gpt-5",
|
|
497
|
-
"gpt-5-nano",
|
|
498
|
-
"gpt-5-mini",
|
|
499
|
-
"gpt-5.1",
|
|
500
|
-
"gpt-5.1-codex",
|
|
501
|
-
"gpt-5.2",
|
|
502
|
-
].includes(use_model_name)
|
|
503
|
-
)
|
|
504
|
-
body.temperature = 0.7;
|
|
506
|
+
if (!NO_TEMP_MODELS.includes(use_model_name)) body.temperature = 0.7;
|
|
505
507
|
}
|
|
506
508
|
if (body.tools) {
|
|
507
509
|
const prevTools = [...body.tools];
|
|
@@ -598,18 +600,7 @@ const getCompletionOpenAICompatible = async (
|
|
|
598
600
|
} else if (rest.temperature === null) {
|
|
599
601
|
delete body.temperature;
|
|
600
602
|
} else if (typeof temperature === "undefined") {
|
|
601
|
-
if (
|
|
602
|
-
![
|
|
603
|
-
"o1",
|
|
604
|
-
"o3",
|
|
605
|
-
"o3-mini",
|
|
606
|
-
"o4-mini",
|
|
607
|
-
"gpt-5",
|
|
608
|
-
"gpt-5-nano",
|
|
609
|
-
"gpt-5-mini",
|
|
610
|
-
].includes(use_model)
|
|
611
|
-
)
|
|
612
|
-
body.temperature = 0.7;
|
|
603
|
+
if (!NO_TEMP_MODELS.includes(use_model)) body.temperature = 0.7;
|
|
613
604
|
}
|
|
614
605
|
if (rest.streamCallback && global.fetch) {
|
|
615
606
|
body.stream = true;
|
package/index.js
CHANGED
|
@@ -82,7 +82,7 @@ ${domReady(`
|
|
|
82
82
|
required: true,
|
|
83
83
|
showIf: { backend: "AI SDK" },
|
|
84
84
|
attributes: {
|
|
85
|
-
options: ["OpenAI"],
|
|
85
|
+
options: ["OpenAI", "Anthropic"],
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
88
|
{
|
|
@@ -93,6 +93,14 @@ ${domReady(`
|
|
|
93
93
|
fieldview: "password",
|
|
94
94
|
showIf: { backend: "AI SDK", ai_sdk_provider: "OpenAI" },
|
|
95
95
|
},
|
|
96
|
+
{
|
|
97
|
+
name: "anthropic_api_key",
|
|
98
|
+
label: "API key",
|
|
99
|
+
type: "String",
|
|
100
|
+
required: true,
|
|
101
|
+
fieldview: "password",
|
|
102
|
+
showIf: { backend: "AI SDK", ai_sdk_provider: "Anthropic" },
|
|
103
|
+
},
|
|
96
104
|
{
|
|
97
105
|
name: "model",
|
|
98
106
|
label: "Model", //gpt-3.5-turbo
|
|
@@ -100,7 +108,17 @@ ${domReady(`
|
|
|
100
108
|
required: true,
|
|
101
109
|
showIf: { backend: "AI SDK" },
|
|
102
110
|
attributes: {
|
|
103
|
-
calcOptions: [
|
|
111
|
+
calcOptions: [
|
|
112
|
+
"ai_sdk_provider",
|
|
113
|
+
{
|
|
114
|
+
OpenAI: OPENAI_MODELS,
|
|
115
|
+
Anthropic: [
|
|
116
|
+
"claude-opus-4-6",
|
|
117
|
+
"claude-sonnet-4-6",
|
|
118
|
+
"claude-haiku-4-5",
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
],
|
|
104
122
|
},
|
|
105
123
|
},
|
|
106
124
|
{
|
|
@@ -118,6 +136,14 @@ ${domReady(`
|
|
|
118
136
|
"text-embedding-3-large",
|
|
119
137
|
"text-embedding-ada-002",
|
|
120
138
|
],
|
|
139
|
+
Anthropic: [
|
|
140
|
+
"voyage-3-large",
|
|
141
|
+
"voyage-3",
|
|
142
|
+
"voyage-3-lite",
|
|
143
|
+
"voyage-code-3",
|
|
144
|
+
"voyage-finance-2",
|
|
145
|
+
"voyage-law-2",
|
|
146
|
+
],
|
|
121
147
|
},
|
|
122
148
|
],
|
|
123
149
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/large-language-model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Large language models and functionality for Saltcorn",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"googleapis": "^144.0.0",
|
|
14
14
|
"ai": "5.0.44",
|
|
15
15
|
"@ai-sdk/openai": "2.0.30",
|
|
16
|
+
"@ai-sdk/anthropic": "2.0.70",
|
|
16
17
|
"openai": "6.16.0",
|
|
17
18
|
"@elevenlabs/elevenlabs-js": "2.31.0"
|
|
18
19
|
},
|
package/tests/configs.js
CHANGED
|
@@ -31,4 +31,14 @@ module.exports = [
|
|
|
31
31
|
temperature: 0.7,
|
|
32
32
|
ai_sdk_provider: "OpenAI",
|
|
33
33
|
},
|
|
34
|
+
{
|
|
35
|
+
name: "AI SDK Anthropic",
|
|
36
|
+
model: "claude-sonnet-4-6",
|
|
37
|
+
api_key: process.env.ANTHROPIC_API_KEY,
|
|
38
|
+
backend: "AI SDK",
|
|
39
|
+
embed_model: "text-embedding-3-small",
|
|
40
|
+
image_model: "gpt-image-1",
|
|
41
|
+
temperature: 0.7,
|
|
42
|
+
ai_sdk_provider: "Anthropic",
|
|
43
|
+
},
|
|
34
44
|
];
|