@node-llm/core 1.15.2 → 1.16.0
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/dist/aliases.d.ts +315 -26
- package/dist/aliases.d.ts.map +1 -1
- package/dist/aliases.js +334 -45
- package/dist/chat/Chat.d.ts +22 -2
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +45 -3
- package/dist/chat/ChatOptions.d.ts +3 -1
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +8 -2
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +9 -3
- package/dist/chat/ChatStream.d.ts.map +1 -1
- package/dist/chat/ChatStream.js +2 -0
- package/dist/chat/Tool.d.ts.map +1 -1
- package/dist/chat/Tool.js +21 -11
- package/dist/chat/ToolHandler.d.ts.map +1 -1
- package/dist/chat/ToolHandler.js +9 -2
- package/dist/chat/Validation.d.ts +1 -0
- package/dist/chat/Validation.d.ts.map +1 -1
- package/dist/chat/Validation.js +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/llm.d.ts +4 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/models/ModelRegistry.d.ts +3 -0
- package/dist/models/ModelRegistry.d.ts.map +1 -1
- package/dist/models/ModelRegistry.js +53 -16
- package/dist/models/PricingRegistry.d.ts.map +1 -1
- package/dist/models/PricingRegistry.js +14 -0
- package/dist/models/models.json +15118 -8614
- package/dist/providers/BaseProvider.d.ts.map +1 -1
- package/dist/providers/BaseProvider.js +1 -0
- package/dist/providers/Provider.d.ts +33 -0
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.js +1 -1
- package/dist/providers/anthropic/Capabilities.d.ts +1 -0
- package/dist/providers/anthropic/Capabilities.d.ts.map +1 -1
- package/dist/providers/anthropic/Capabilities.js +15 -34
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +16 -2
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +15 -1
- package/dist/providers/bedrock/BedrockProvider.d.ts +1 -1
- package/dist/providers/bedrock/BedrockProvider.js +1 -1
- package/dist/providers/bedrock/Capabilities.d.ts +3 -28
- package/dist/providers/bedrock/Capabilities.d.ts.map +1 -1
- package/dist/providers/bedrock/Capabilities.js +62 -183
- package/dist/providers/bedrock/Chat.d.ts.map +1 -1
- package/dist/providers/bedrock/Chat.js +1 -0
- package/dist/providers/bedrock/Streaming.d.ts.map +1 -1
- package/dist/providers/bedrock/Streaming.js +1 -0
- package/dist/providers/bedrock/mapper.d.ts +4 -3
- package/dist/providers/bedrock/mapper.d.ts.map +1 -1
- package/dist/providers/bedrock/mapper.js +19 -4
- package/dist/providers/deepseek/Capabilities.d.ts +2 -1
- package/dist/providers/deepseek/Capabilities.d.ts.map +1 -1
- package/dist/providers/deepseek/Capabilities.js +21 -30
- package/dist/providers/deepseek/DeepSeekProvider.d.ts +1 -1
- package/dist/providers/gemini/Capabilities.d.ts +1 -1
- package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
- package/dist/providers/gemini/Capabilities.js +33 -87
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +44 -9
- package/dist/providers/gemini/ChatUtils.d.ts.map +1 -1
- package/dist/providers/gemini/ChatUtils.js +59 -49
- package/dist/providers/gemini/GeminiProvider.js +1 -1
- package/dist/providers/gemini/Image.d.ts.map +1 -1
- package/dist/providers/gemini/Image.js +17 -5
- package/dist/providers/gemini/Streaming.d.ts.map +1 -1
- package/dist/providers/gemini/Streaming.js +41 -1
- package/dist/providers/gemini/types.d.ts +1 -0
- package/dist/providers/gemini/types.d.ts.map +1 -1
- package/dist/providers/mistral/Capabilities.d.ts +1 -0
- package/dist/providers/mistral/Capabilities.d.ts.map +1 -1
- package/dist/providers/mistral/Capabilities.js +30 -59
- package/dist/providers/mistral/Chat.d.ts.map +1 -1
- package/dist/providers/mistral/Chat.js +13 -1
- package/dist/providers/mistral/Streaming.d.ts.map +1 -1
- package/dist/providers/mistral/Streaming.js +13 -1
- package/dist/providers/mistral/Transcription.d.ts.map +1 -1
- package/dist/providers/mistral/Transcription.js +3 -1
- package/dist/providers/ollama/Capabilities.d.ts +1 -0
- package/dist/providers/ollama/Capabilities.d.ts.map +1 -1
- package/dist/providers/ollama/Capabilities.js +17 -27
- package/dist/providers/openai/Capabilities.d.ts +2 -1
- package/dist/providers/openai/Capabilities.d.ts.map +1 -1
- package/dist/providers/openai/Capabilities.js +35 -71
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +4 -1
- package/dist/providers/openai/Image.d.ts +1 -0
- package/dist/providers/openai/Image.d.ts.map +1 -1
- package/dist/providers/openai/Image.js +61 -2
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +7 -1
- package/dist/providers/openai/Transcription.d.ts.map +1 -1
- package/dist/providers/openai/Transcription.js +7 -2
- package/dist/providers/openrouter/Capabilities.d.ts +10 -9
- package/dist/providers/openrouter/Capabilities.d.ts.map +1 -1
- package/dist/providers/openrouter/Capabilities.js +25 -48
- package/dist/providers/utils.d.ts +4 -0
- package/dist/providers/utils.d.ts.map +1 -1
- package/dist/providers/utils.js +11 -0
- package/dist/providers/xai/Capabilities.d.ts +13 -9
- package/dist/providers/xai/Capabilities.d.ts.map +1 -1
- package/dist/providers/xai/Capabilities.js +34 -65
- package/dist/transcription/Transcription.d.ts +23 -1
- package/dist/transcription/Transcription.d.ts.map +1 -1
- package/dist/transcription/Transcription.js +22 -0
- package/dist/utils/Binary.d.ts +8 -0
- package/dist/utils/Binary.d.ts.map +1 -1
- package/dist/utils/Binary.js +12 -0
- package/package.json +1 -1
|
@@ -3,229 +3,108 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
5
5
|
import { PricingRegistry } from "../../models/PricingRegistry.js";
|
|
6
|
-
const MODEL_FAMILIES = [
|
|
7
|
-
[/anthropic\.claude-3-opus/, "claude3_opus"],
|
|
8
|
-
[/anthropic\.claude-3-sonnet/, "claude3_sonnet"],
|
|
9
|
-
[/anthropic\.claude-3-5-sonnet/, "claude3_sonnet"],
|
|
10
|
-
[/anthropic\.claude-3-7-sonnet/, "claude3_sonnet"],
|
|
11
|
-
[/anthropic\.claude-3-haiku/, "claude3_haiku"],
|
|
12
|
-
[/anthropic\.claude-3-5-haiku/, "claude3_5_haiku"],
|
|
13
|
-
[/anthropic\.claude-v2/, "claude2"],
|
|
14
|
-
[/anthropic\.claude-2/, "claude2"],
|
|
15
|
-
[/anthropic\.claude-instant/, "claude_instant"],
|
|
16
|
-
[/anthropic\.claude-(opus|sonnet|haiku)-4/, "claude4"],
|
|
17
|
-
[/amazon\.nova-2/, "nova2"],
|
|
18
|
-
[/amazon\.nova/, "nova"]
|
|
19
|
-
];
|
|
20
6
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
21
|
-
//
|
|
22
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
23
|
-
const PRICES = {
|
|
24
|
-
claude3_opus: { input: 15.0, output: 75.0 },
|
|
25
|
-
claude3_sonnet: { input: 3.0, output: 15.0 },
|
|
26
|
-
claude3_haiku: { input: 0.25, output: 1.25 },
|
|
27
|
-
claude3_5_haiku: { input: 0.8, output: 4.0 },
|
|
28
|
-
claude2: { input: 8.0, output: 24.0 },
|
|
29
|
-
claude_instant: { input: 0.8, output: 2.4 },
|
|
30
|
-
claude4: { input: 3.0, output: 15.0 }, // Assuming Sonnet 4 as baseline for the family
|
|
31
|
-
nova: { input: 0.06, output: 0.24 },
|
|
32
|
-
nova2: { input: 0.03, output: 0.12 }, // Assuming Nova 2 is cheaper as per trend
|
|
33
|
-
other: { input: 0.1, output: 0.2 }
|
|
34
|
-
};
|
|
35
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
36
|
-
// Capabilities Class
|
|
7
|
+
// Model Family Patterns
|
|
37
8
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
38
9
|
export class Capabilities {
|
|
39
|
-
static getModelFamily(modelId) {
|
|
40
|
-
for (const [pattern, family] of MODEL_FAMILIES) {
|
|
41
|
-
if (pattern.test(modelId))
|
|
42
|
-
return family;
|
|
43
|
-
}
|
|
44
|
-
return "other";
|
|
45
|
-
}
|
|
46
10
|
static getContextWindow(modelId) {
|
|
47
|
-
|
|
48
|
-
if (val)
|
|
49
|
-
return val;
|
|
50
|
-
// Claude 2 has 100k, others have 200k
|
|
51
|
-
if (/anthropic\.claude-2/.test(modelId))
|
|
52
|
-
return 100_000;
|
|
53
|
-
if (/anthropic\.claude/.test(modelId))
|
|
54
|
-
return 200_000;
|
|
55
|
-
// DeepSeek
|
|
56
|
-
if (/deepseek/.test(modelId))
|
|
57
|
-
return 128_000;
|
|
58
|
-
// Mistral
|
|
59
|
-
if (/mistral-large/.test(modelId))
|
|
60
|
-
return 128_000;
|
|
61
|
-
if (/mistral/.test(modelId))
|
|
62
|
-
return 32_000;
|
|
63
|
-
// Llama
|
|
64
|
-
if (/llama/.test(modelId))
|
|
65
|
-
return 128_000;
|
|
66
|
-
// Titan
|
|
67
|
-
if (/titan/.test(modelId))
|
|
68
|
-
return 32_000;
|
|
69
|
-
// Nova
|
|
70
|
-
if (/nova/.test(modelId))
|
|
71
|
-
return 300_000;
|
|
72
|
-
return null;
|
|
11
|
+
return ModelRegistry.getContextWindow(modelId, "bedrock") ?? 128_000;
|
|
73
12
|
}
|
|
74
13
|
static getMaxOutputTokens(modelId) {
|
|
75
|
-
|
|
76
|
-
if (val)
|
|
77
|
-
return val;
|
|
78
|
-
return 4_096;
|
|
14
|
+
return ModelRegistry.getMaxOutputTokens(modelId, "bedrock") ?? 4_096;
|
|
79
15
|
}
|
|
80
16
|
static supportsChat(modelId) {
|
|
81
|
-
|
|
82
|
-
if (model?.capabilities?.includes("chat"))
|
|
83
|
-
return true;
|
|
84
|
-
return (/anthropic\.claude/.test(modelId) ||
|
|
85
|
-
/amazon\.nova/.test(modelId) ||
|
|
86
|
-
/mistral\.mistral/.test(modelId) ||
|
|
87
|
-
/meta\.llama/.test(modelId) ||
|
|
88
|
-
/deepseek/.test(modelId));
|
|
17
|
+
return ModelRegistry.supports(modelId, "chat", "bedrock") || !modelId.includes("titan-embed");
|
|
89
18
|
}
|
|
90
19
|
static supportsStreaming(modelId) {
|
|
91
|
-
|
|
92
|
-
if (model?.capabilities?.includes("streaming"))
|
|
93
|
-
return true;
|
|
94
|
-
return (/anthropic\.claude/.test(modelId) ||
|
|
95
|
-
/amazon\.nova/.test(modelId) ||
|
|
96
|
-
/mistral\.mistral/.test(modelId) ||
|
|
97
|
-
/meta\.llama/.test(modelId) ||
|
|
98
|
-
/deepseek/.test(modelId));
|
|
20
|
+
return (ModelRegistry.supports(modelId, "streaming", "bedrock") || !modelId.includes("titan-embed"));
|
|
99
21
|
}
|
|
100
22
|
static supportsVision(modelId) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (model?.capabilities?.includes("vision"))
|
|
105
|
-
return true;
|
|
106
|
-
return /anthropic\.claude-3|anthropic\.claude-4|amazon\.nova/.test(modelId);
|
|
23
|
+
return (ModelRegistry.supports(modelId, "vision", "bedrock") ||
|
|
24
|
+
modelId.includes("vision") ||
|
|
25
|
+
modelId.includes("nova"));
|
|
107
26
|
}
|
|
108
27
|
static supportsTools(modelId) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return true;
|
|
112
|
-
return /anthropic\.claude|amazon\.nova|deepseek-chat/.test(modelId);
|
|
28
|
+
return (ModelRegistry.supports(modelId, "tools", "bedrock") ||
|
|
29
|
+
ModelRegistry.supports(modelId, "function_calling", "bedrock"));
|
|
113
30
|
}
|
|
114
31
|
static supportsJsonMode(modelId) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
model?.capabilities?.includes("structured_output"))
|
|
118
|
-
return true;
|
|
119
|
-
return /anthropic\.claude|amazon\.nova/.test(modelId);
|
|
32
|
+
return (ModelRegistry.supports(modelId, "json_mode", "bedrock") ||
|
|
33
|
+
ModelRegistry.supports(modelId, "structured_output", "bedrock"));
|
|
120
34
|
}
|
|
121
35
|
static supportsExtendedThinking(modelId) {
|
|
122
|
-
|
|
123
|
-
if (model?.capabilities?.includes("reasoning"))
|
|
124
|
-
return true;
|
|
125
|
-
return /claude-3-7|deepseek-reasoner|deepseek\.r1/.test(modelId);
|
|
36
|
+
return ModelRegistry.supports(modelId, "reasoning", "bedrock");
|
|
126
37
|
}
|
|
127
38
|
static supportsEmbeddings(modelId) {
|
|
128
|
-
|
|
129
|
-
if (model?.capabilities?.includes("embeddings"))
|
|
130
|
-
return true;
|
|
131
|
-
return /amazon\.titan-embed/.test(modelId);
|
|
39
|
+
return (ModelRegistry.supports(modelId, "embeddings", "bedrock") || modelId.includes("titan-embed"));
|
|
132
40
|
}
|
|
133
41
|
static supportsImageGeneration(modelId) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*/
|
|
142
|
-
static supportsAudio(_modelId) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Get input modalities for a model.
|
|
147
|
-
*/
|
|
42
|
+
return (ModelRegistry.supports(modelId, "image_generation", "bedrock") ||
|
|
43
|
+
modelId.includes("image-generator") ||
|
|
44
|
+
modelId.includes("stable-diffusion"));
|
|
45
|
+
}
|
|
46
|
+
static supportsToolChoice(_modelId) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
148
49
|
static getInputModalities(modelId) {
|
|
50
|
+
const model = this.findModel(modelId);
|
|
51
|
+
if (model?.modalities?.input)
|
|
52
|
+
return model.modalities.input;
|
|
149
53
|
const modalities = ["text"];
|
|
150
|
-
if ((
|
|
151
|
-
|
|
152
|
-
modalities.push("image");
|
|
153
|
-
modalities.push("pdf");
|
|
54
|
+
if (this.supportsVision(modelId)) {
|
|
55
|
+
modalities.push("image", "pdf");
|
|
154
56
|
}
|
|
155
57
|
return modalities;
|
|
156
58
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
static getOutputModalities(_modelId) {
|
|
161
|
-
return ["text"];
|
|
59
|
+
static getOutputModalities(modelId) {
|
|
60
|
+
const model = this.findModel(modelId);
|
|
61
|
+
return model?.modalities?.output || ["text"];
|
|
162
62
|
}
|
|
163
|
-
/**
|
|
164
|
-
* Get all capabilities for a model.
|
|
165
|
-
*/
|
|
166
63
|
static getCapabilities(modelId) {
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
capabilities
|
|
64
|
+
const model = this.findModel(modelId);
|
|
65
|
+
if (model?.capabilities) {
|
|
66
|
+
const caps = [...model.capabilities];
|
|
67
|
+
if (!caps.includes("streaming"))
|
|
68
|
+
caps.push("streaming");
|
|
69
|
+
return caps;
|
|
170
70
|
}
|
|
171
|
-
|
|
71
|
+
const capabilities = ["streaming"];
|
|
72
|
+
if (this.supportsTools(modelId))
|
|
172
73
|
capabilities.push("function_calling");
|
|
173
|
-
|
|
174
|
-
if (/claude-3-7|nova/.test(modelId)) {
|
|
74
|
+
if (this.supportsExtendedThinking(modelId))
|
|
175
75
|
capabilities.push("reasoning");
|
|
176
|
-
}
|
|
177
|
-
if (/claude-3\.5|claude-3-7|nova/.test(modelId)) {
|
|
178
|
-
capabilities.push("batch");
|
|
179
|
-
capabilities.push("citations");
|
|
180
|
-
}
|
|
181
76
|
return capabilities;
|
|
182
77
|
}
|
|
183
78
|
static getPricing(modelId) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Get input price per million tokens.
|
|
206
|
-
*/
|
|
207
|
-
static getInputPrice(modelId) {
|
|
208
|
-
const family = this.getModelFamily(modelId);
|
|
209
|
-
return PRICES[family].input;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Get output price per million tokens.
|
|
213
|
-
*/
|
|
214
|
-
static getOutputPrice(modelId) {
|
|
215
|
-
const family = this.getModelFamily(modelId);
|
|
216
|
-
return PRICES[family].output;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Format model ID as display name.
|
|
220
|
-
*/
|
|
79
|
+
return PricingRegistry.getPricing(modelId, "bedrock");
|
|
80
|
+
}
|
|
81
|
+
static getModelFamily(modelId) {
|
|
82
|
+
const model = this.findModel(modelId);
|
|
83
|
+
if (model?.family)
|
|
84
|
+
return model.family;
|
|
85
|
+
if (modelId.includes("claude"))
|
|
86
|
+
return "claude";
|
|
87
|
+
if (modelId.includes("mistral"))
|
|
88
|
+
return "mistral";
|
|
89
|
+
if (modelId.includes("llama"))
|
|
90
|
+
return "llama";
|
|
91
|
+
if (modelId.includes("titan"))
|
|
92
|
+
return "titan";
|
|
93
|
+
if (modelId.includes("nova"))
|
|
94
|
+
return "nova";
|
|
95
|
+
if (modelId.includes("deepseek"))
|
|
96
|
+
return "deepseek";
|
|
97
|
+
return "other";
|
|
98
|
+
}
|
|
221
99
|
static formatDisplayName(modelId) {
|
|
100
|
+
const model = this.findModel(modelId);
|
|
101
|
+
if (model?.name && model.name !== modelId)
|
|
102
|
+
return model.name;
|
|
222
103
|
return modelId
|
|
223
104
|
.replace(/-/g, " ")
|
|
224
105
|
.split(".")
|
|
225
106
|
.pop()
|
|
226
|
-
.
|
|
227
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
228
|
-
.join(" ");
|
|
107
|
+
.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
229
108
|
}
|
|
230
109
|
static findModel(modelId) {
|
|
231
110
|
return ModelRegistry.find(modelId, "bedrock");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Chat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,aAAa,EAA6C,MAAM,aAAa,CAAC;AAavF,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,aAAa;IAMjC;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Chat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAElE,OAAO,EAAE,aAAa,EAA6C,MAAM,aAAa,CAAC;AAavF,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,aAAa;IAMjC;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAyD1D;;OAEG;IACH,OAAO,CAAC,YAAY;IA6CpB;;OAEG;IACH,OAAO,CAAC,aAAa;CAiDtB"}
|
|
@@ -40,6 +40,7 @@ export class BedrockChat {
|
|
|
40
40
|
temperature: request.temperature,
|
|
41
41
|
thinking: request.thinking,
|
|
42
42
|
guardrail,
|
|
43
|
+
toolChoice: request.tool_choice,
|
|
43
44
|
additionalModelRequestFields: request.additionalModelRequestFields
|
|
44
45
|
});
|
|
45
46
|
const bodyJson = JSON.stringify(body);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAA6C,MAAM,aAAa,CAAC;AAQvF,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,aAAa;IAM1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/Streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAA6C,MAAM,aAAa,CAAC;AAQvF,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,MAAM,EAAE,aAAa;IAM1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;IA6H7F;;OAEG;IACH,OAAO,CAAC,UAAU;IAyGlB,OAAO,CAAC,YAAY;CAsCrB"}
|
|
@@ -39,6 +39,7 @@ export class BedrockStreaming {
|
|
|
39
39
|
temperature: request.temperature,
|
|
40
40
|
thinking: request.thinking,
|
|
41
41
|
guardrail,
|
|
42
|
+
toolChoice: request.tool_choice,
|
|
42
43
|
additionalModelRequestFields: request.additionalModelRequestFields
|
|
43
44
|
});
|
|
44
45
|
const bodyJson = JSON.stringify(body);
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Message } from "../../chat/Message.js";
|
|
8
8
|
import { ToolDefinition } from "../../chat/Tool.js";
|
|
9
|
-
import { BedrockMessage, BedrockContentBlock, BedrockConverseRequest
|
|
10
|
-
import { ThinkingConfig } from "../../providers/Provider.js";
|
|
9
|
+
import { BedrockToolConfig, BedrockMessage, BedrockContentBlock, BedrockConverseRequest } from "./types.js";
|
|
10
|
+
import { ThinkingConfig, ToolChoice } from "../../providers/Provider.js";
|
|
11
11
|
/**
|
|
12
12
|
* Convert NodeLLM messages to Bedrock Converse format.
|
|
13
13
|
* Extracts system messages to the top-level system field.
|
|
@@ -19,7 +19,7 @@ export declare function convertMessages(messages: Message[]): {
|
|
|
19
19
|
/**
|
|
20
20
|
* Convert NodeLLM tool definitions to Bedrock tool config.
|
|
21
21
|
*/
|
|
22
|
-
export declare function convertTools(tools?: ToolDefinition[]): BedrockToolConfig | undefined;
|
|
22
|
+
export declare function convertTools(tools?: ToolDefinition[], toolChoice?: ToolChoice): BedrockToolConfig | undefined;
|
|
23
23
|
/**
|
|
24
24
|
* Build a complete Bedrock Converse request from NodeLLM ChatRequest.
|
|
25
25
|
*/
|
|
@@ -32,6 +32,7 @@ export declare function buildConverseRequest(messages: Message[], tools?: ToolDe
|
|
|
32
32
|
guardrailVersion: string;
|
|
33
33
|
trace?: "enabled" | "disabled";
|
|
34
34
|
};
|
|
35
|
+
toolChoice?: ToolChoice;
|
|
35
36
|
additionalModelRequestFields?: Record<string, any>;
|
|
36
37
|
}): BedrockConverseRequest;
|
|
37
38
|
//# sourceMappingURL=mapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/mapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../../src/providers/bedrock/mapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,iBAAiB,EAEjB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAiDzE;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG;IACpD,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAChC,CAuFA;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAC1B,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,UAAU,CAAC,EAAE,UAAU,GACtB,iBAAiB,GAAG,SAAS,CA8B/B;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,CAAC,EAAE,cAAc,EAAE,EACxB,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,SAAS,CAAC,EAAE;QACV,mBAAmB,EAAE,MAAM,CAAC;QAC5B,gBAAgB,EAAE,MAAM,CAAC;QACzB,KAAK,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;KAChC,CAAC;IACF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,4BAA4B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpD,GACA,sBAAsB,CAmDxB"}
|
|
@@ -136,11 +136,11 @@ export function convertMessages(messages) {
|
|
|
136
136
|
/**
|
|
137
137
|
* Convert NodeLLM tool definitions to Bedrock tool config.
|
|
138
138
|
*/
|
|
139
|
-
export function convertTools(tools) {
|
|
140
|
-
if (!tools || tools.length === 0) {
|
|
139
|
+
export function convertTools(tools, toolChoice) {
|
|
140
|
+
if (!tools || tools.length === 0 || toolChoice === "none") {
|
|
141
141
|
return undefined;
|
|
142
142
|
}
|
|
143
|
-
|
|
143
|
+
const config = {
|
|
144
144
|
tools: tools.map((tool) => ({
|
|
145
145
|
toolSpec: {
|
|
146
146
|
name: tool.function.name,
|
|
@@ -151,6 +151,21 @@ export function convertTools(tools) {
|
|
|
151
151
|
}
|
|
152
152
|
}))
|
|
153
153
|
};
|
|
154
|
+
if (toolChoice) {
|
|
155
|
+
if (toolChoice === "auto") {
|
|
156
|
+
config.toolChoice = { auto: {} };
|
|
157
|
+
}
|
|
158
|
+
else if (toolChoice === "required") {
|
|
159
|
+
config.toolChoice = { any: {} };
|
|
160
|
+
}
|
|
161
|
+
else if (typeof toolChoice === "string") {
|
|
162
|
+
config.toolChoice = { tool: { name: toolChoice } };
|
|
163
|
+
}
|
|
164
|
+
else if (typeof toolChoice === "object" && "function" in toolChoice) {
|
|
165
|
+
config.toolChoice = { tool: { name: toolChoice.function.name } };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return config;
|
|
154
169
|
}
|
|
155
170
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
156
171
|
// Request Builder
|
|
@@ -166,7 +181,7 @@ export function buildConverseRequest(messages, tools, options) {
|
|
|
166
181
|
if (system) {
|
|
167
182
|
request.system = system;
|
|
168
183
|
}
|
|
169
|
-
const toolConfig = convertTools(tools);
|
|
184
|
+
const toolConfig = convertTools(tools, options?.toolChoice);
|
|
170
185
|
if (toolConfig) {
|
|
171
186
|
request.toolConfig = toolConfig;
|
|
172
187
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModelPricing } from "../../models/types.js";
|
|
2
2
|
export declare class Capabilities {
|
|
3
3
|
static getCapabilities(modelId: string): string[];
|
|
4
|
-
static getContextWindow(modelId: string): number
|
|
4
|
+
static getContextWindow(modelId: string): number;
|
|
5
5
|
static getMaxOutputTokens(modelId: string): number | null;
|
|
6
6
|
static supportsVision(modelId: string): boolean;
|
|
7
7
|
static supportsTools(modelId: string): boolean;
|
|
@@ -11,6 +11,7 @@ export declare class Capabilities {
|
|
|
11
11
|
static supportsTranscription(_modelId: string): boolean;
|
|
12
12
|
static supportsModeration(_modelId: string): boolean;
|
|
13
13
|
static supportsReasoning(modelId: string): boolean;
|
|
14
|
+
static supportsToolChoice(_modelId: string): boolean;
|
|
14
15
|
static getPricing(modelId: string): ModelPricing | undefined;
|
|
15
16
|
private static findModel;
|
|
16
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Capabilities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,qBAAa,YAAY;IACvB,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Capabilities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,qBAAa,YAAY;IACvB,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAejD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAIhD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAQ9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAMzD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAKnD,MAAM,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIzD,MAAM,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIvD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI5D,OAAO,CAAC,MAAM,CAAC,SAAS;CAGzB"}
|
|
@@ -2,49 +2,40 @@ import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
|
2
2
|
import { PricingRegistry } from "../../models/PricingRegistry.js";
|
|
3
3
|
export class Capabilities {
|
|
4
4
|
static getCapabilities(modelId) {
|
|
5
|
+
const model = this.findModel(modelId);
|
|
6
|
+
if (model?.capabilities) {
|
|
7
|
+
const caps = [...model.capabilities];
|
|
8
|
+
if (!caps.includes("streaming"))
|
|
9
|
+
caps.push("streaming");
|
|
10
|
+
return caps;
|
|
11
|
+
}
|
|
5
12
|
const caps = ["streaming"];
|
|
6
|
-
if (
|
|
13
|
+
if (this.supportsTools(modelId))
|
|
7
14
|
caps.push("function_calling");
|
|
8
|
-
|
|
9
|
-
if (/deepseek-reasoner/.test(modelId)) {
|
|
15
|
+
if (this.supportsReasoning(modelId))
|
|
10
16
|
caps.push("reasoning");
|
|
11
|
-
}
|
|
12
17
|
return caps;
|
|
13
18
|
}
|
|
14
19
|
static getContextWindow(modelId) {
|
|
15
|
-
|
|
16
|
-
if (val)
|
|
17
|
-
return val;
|
|
18
|
-
if (/deepseek-(?:chat|reasoner)/.test(modelId)) {
|
|
19
|
-
return 128_000;
|
|
20
|
-
}
|
|
21
|
-
return 32_768;
|
|
20
|
+
return ModelRegistry.getContextWindow(modelId, "deepseek") ?? 32_768;
|
|
22
21
|
}
|
|
23
22
|
static getMaxOutputTokens(modelId) {
|
|
24
|
-
|
|
25
|
-
return 8_192;
|
|
26
|
-
}
|
|
27
|
-
return 4_096;
|
|
23
|
+
return ModelRegistry.getMaxOutputTokens(modelId, "deepseek") ?? 8_192;
|
|
28
24
|
}
|
|
29
25
|
static supportsVision(modelId) {
|
|
30
|
-
|
|
31
|
-
return model?.modalities?.input?.includes("image") || false;
|
|
26
|
+
return ModelRegistry.supports(modelId, "vision", "deepseek");
|
|
32
27
|
}
|
|
33
28
|
static supportsTools(modelId) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return /deepseek-chat/.test(modelId);
|
|
29
|
+
return (ModelRegistry.supports(modelId, "tools", "deepseek") ||
|
|
30
|
+
ModelRegistry.supports(modelId, "function_calling", "deepseek") ||
|
|
31
|
+
modelId.includes("chat"));
|
|
38
32
|
}
|
|
39
33
|
static supportsStructuredOutput(modelId) {
|
|
40
|
-
|
|
41
|
-
if (model?.capabilities?.includes("structured_output"))
|
|
42
|
-
return true;
|
|
43
|
-
return /deepseek-chat/.test(modelId);
|
|
34
|
+
return (ModelRegistry.supports(modelId, "structured_output", "deepseek") || modelId.includes("chat"));
|
|
44
35
|
}
|
|
45
36
|
static supportsEmbeddings(modelId) {
|
|
46
37
|
const model = this.findModel(modelId);
|
|
47
|
-
return model?.modalities?.output?.includes("embeddings")
|
|
38
|
+
return model?.modalities?.output?.includes("embeddings") ?? false;
|
|
48
39
|
}
|
|
49
40
|
static supportsImageGeneration(_modelId) {
|
|
50
41
|
return false;
|
|
@@ -56,10 +47,10 @@ export class Capabilities {
|
|
|
56
47
|
return false;
|
|
57
48
|
}
|
|
58
49
|
static supportsReasoning(modelId) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return
|
|
50
|
+
return ModelRegistry.supports(modelId, "reasoning", "deepseek") || modelId.includes("reasoner");
|
|
51
|
+
}
|
|
52
|
+
static supportsToolChoice(_modelId) {
|
|
53
|
+
return true;
|
|
63
54
|
}
|
|
64
55
|
static getPricing(modelId) {
|
|
65
56
|
return PricingRegistry.getPricing(modelId, "deepseek");
|
|
@@ -20,7 +20,7 @@ export declare class DeepSeekProvider extends BaseProvider implements Provider {
|
|
|
20
20
|
supportsModeration: (model: string) => boolean;
|
|
21
21
|
supportsReasoning: (model: string) => boolean;
|
|
22
22
|
supportsDeveloperRole: (_model: string) => boolean;
|
|
23
|
-
getContextWindow: (model: string) => number
|
|
23
|
+
getContextWindow: (model: string) => number;
|
|
24
24
|
};
|
|
25
25
|
constructor(options: DeepSeekProviderOptions);
|
|
26
26
|
apiBase(): string;
|
|
@@ -11,6 +11,7 @@ export declare class Capabilities {
|
|
|
11
11
|
static supportsImageGeneration(modelId: string): boolean;
|
|
12
12
|
static supportsTranscription(modelId: string): boolean;
|
|
13
13
|
static supportsModeration(_modelId: string): boolean;
|
|
14
|
+
static supportsToolChoice(_modelId: string): boolean;
|
|
14
15
|
static normalizeTemperature(temperature: number | undefined, _model: string): number | undefined;
|
|
15
16
|
static getModalities(modelId: string): {
|
|
16
17
|
input: string[];
|
|
@@ -18,7 +19,6 @@ export declare class Capabilities {
|
|
|
18
19
|
};
|
|
19
20
|
static getCapabilities(modelId: string): string[];
|
|
20
21
|
static getPricing(modelId: string): ModelPricing | undefined;
|
|
21
|
-
private static normalizeModelId;
|
|
22
22
|
private static findModel;
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Capabilities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,qBAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Capabilities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,qBAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIzD,MAAM,CAAC,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI5D,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOjD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAKnD,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IASxD,MAAM,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOtD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIhG,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IAc5E,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAgBjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAI5D,OAAO,CAAC,MAAM,CAAC,SAAS;CAGzB"}
|