@llumiverse/drivers 0.17.0 → 0.18.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/README.md +1 -1
- package/lib/cjs/bedrock/converse.js +65 -15
- package/lib/cjs/bedrock/converse.js.map +1 -1
- package/lib/cjs/bedrock/index.js +189 -52
- package/lib/cjs/bedrock/index.js.map +1 -1
- package/lib/cjs/bedrock/nova-image-payload.js.map +1 -1
- package/lib/cjs/bedrock/s3.js +47 -0
- package/lib/cjs/bedrock/s3.js.map +1 -1
- package/lib/cjs/groq/index.js +4 -4
- package/lib/cjs/groq/index.js.map +1 -1
- package/lib/cjs/mistral/index.js +3 -3
- package/lib/cjs/mistral/index.js.map +1 -1
- package/lib/cjs/openai/azure.js +1 -1
- package/lib/cjs/openai/azure.js.map +1 -1
- package/lib/cjs/openai/index.js +203 -81
- package/lib/cjs/openai/index.js.map +1 -1
- package/lib/cjs/replicate.js +1 -1
- package/lib/cjs/togetherai/index.js +2 -2
- package/lib/cjs/vertexai/embeddings/embeddings-image.js +2 -1
- package/lib/cjs/vertexai/embeddings/embeddings-image.js.map +1 -1
- package/lib/cjs/vertexai/embeddings/embeddings-text.js +2 -1
- package/lib/cjs/vertexai/embeddings/embeddings-text.js.map +1 -1
- package/lib/cjs/vertexai/index.js +58 -28
- package/lib/cjs/vertexai/index.js.map +1 -1
- package/lib/cjs/vertexai/models/claude.js +48 -14
- package/lib/cjs/vertexai/models/claude.js.map +1 -1
- package/lib/cjs/vertexai/models/gemini.js +3 -3
- package/lib/cjs/vertexai/models/gemini.js.map +1 -1
- package/lib/cjs/vertexai/models/imagen.js.map +1 -1
- package/lib/cjs/watsonx/index.js +2 -2
- package/lib/esm/bedrock/converse.js +63 -14
- package/lib/esm/bedrock/converse.js.map +1 -1
- package/lib/esm/bedrock/index.js +192 -55
- package/lib/esm/bedrock/index.js.map +1 -1
- package/lib/esm/bedrock/nova-image-payload.js.map +1 -1
- package/lib/esm/bedrock/s3.js +46 -0
- package/lib/esm/bedrock/s3.js.map +1 -1
- package/lib/esm/groq/index.js +4 -4
- package/lib/esm/groq/index.js.map +1 -1
- package/lib/esm/mistral/index.js +3 -3
- package/lib/esm/mistral/index.js.map +1 -1
- package/lib/esm/openai/azure.js +1 -1
- package/lib/esm/openai/azure.js.map +1 -1
- package/lib/esm/openai/index.js +204 -83
- package/lib/esm/openai/index.js.map +1 -1
- package/lib/esm/replicate.js +1 -1
- package/lib/esm/togetherai/index.js +2 -2
- package/lib/esm/vertexai/embeddings/embeddings-image.js +2 -1
- package/lib/esm/vertexai/embeddings/embeddings-image.js.map +1 -1
- package/lib/esm/vertexai/embeddings/embeddings-text.js +2 -1
- package/lib/esm/vertexai/embeddings/embeddings-text.js.map +1 -1
- package/lib/esm/vertexai/index.js +59 -29
- package/lib/esm/vertexai/index.js.map +1 -1
- package/lib/esm/vertexai/models/claude.js +49 -15
- package/lib/esm/vertexai/models/claude.js.map +1 -1
- package/lib/esm/vertexai/models/gemini.js +3 -3
- package/lib/esm/vertexai/models/gemini.js.map +1 -1
- package/lib/esm/vertexai/models/imagen.js.map +1 -1
- package/lib/esm/watsonx/index.js +2 -2
- package/lib/types/bedrock/converse.d.ts +2 -1
- package/lib/types/bedrock/converse.d.ts.map +1 -1
- package/lib/types/bedrock/index.d.ts +4 -15
- package/lib/types/bedrock/index.d.ts.map +1 -1
- package/lib/types/bedrock/nova-image-payload.d.ts.map +1 -1
- package/lib/types/bedrock/s3.d.ts +6 -0
- package/lib/types/bedrock/s3.d.ts.map +1 -1
- package/lib/types/openai/index.d.ts +8 -5
- package/lib/types/openai/index.d.ts.map +1 -1
- package/lib/types/togetherai/interfaces.d.ts +3 -3
- package/lib/types/togetherai/interfaces.d.ts.map +1 -1
- package/lib/types/vertexai/embeddings/embeddings-image.d.ts.map +1 -1
- package/lib/types/vertexai/embeddings/embeddings-text.d.ts.map +1 -1
- package/lib/types/vertexai/index.d.ts +4 -3
- package/lib/types/vertexai/index.d.ts.map +1 -1
- package/lib/types/vertexai/models/claude.d.ts.map +1 -1
- package/lib/types/vertexai/models/imagen.d.ts.map +1 -1
- package/lib/types/vertexai/models.d.ts +1 -1
- package/lib/types/vertexai/models.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/bedrock/converse.ts +65 -16
- package/src/bedrock/index.ts +228 -66
- package/src/bedrock/nova-image-payload.ts +1 -2
- package/src/bedrock/s3.ts +48 -0
- package/src/groq/index.ts +4 -4
- package/src/mistral/index.ts +3 -3
- package/src/openai/azure.ts +2 -2
- package/src/openai/index.ts +251 -92
- package/src/openai/openai.ts +1 -1
- package/src/replicate.ts +1 -1
- package/src/togetherai/index.ts +2 -2
- package/src/togetherai/interfaces.ts +3 -3
- package/src/vertexai/embeddings/embeddings-image.ts +5 -3
- package/src/vertexai/embeddings/embeddings-text.ts +5 -3
- package/src/vertexai/index.ts +65 -30
- package/src/vertexai/models/claude.ts +68 -29
- package/src/vertexai/models/gemini.ts +3 -3
- package/src/vertexai/models/imagen.ts +4 -3
- package/src/vertexai/models.ts +1 -1
- package/src/watsonx/index.ts +2 -2
package/README.md
CHANGED
|
@@ -297,4 +297,4 @@ Please see [CONTRIBUTING.md](https://github.com/vertesia/llumiverse/blob/main/CO
|
|
|
297
297
|
|
|
298
298
|
## License
|
|
299
299
|
|
|
300
|
-
|
|
300
|
+
Llumiverse is licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). Feel free to use it accordingly.
|
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.converseConcatMessages = converseConcatMessages;
|
|
4
4
|
exports.converseSystemToMessages = converseSystemToMessages;
|
|
5
5
|
exports.converseRemoveJSONprefill = converseRemoveJSONprefill;
|
|
6
|
-
exports.
|
|
6
|
+
exports.converseJSONprefill = converseJSONprefill;
|
|
7
|
+
exports.formatConversePrompt = formatConversePrompt;
|
|
7
8
|
const core_1 = require("@llumiverse/core");
|
|
8
9
|
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
|
|
10
|
+
const s3_js_1 = require("./s3.js");
|
|
9
11
|
function getJSONSafetyNotice(schema) {
|
|
10
12
|
return "The answer must be a JSON object using the following JSON Schema:\n" + JSON.stringify(schema, undefined, 2);
|
|
11
13
|
}
|
|
@@ -72,15 +74,40 @@ function converseRemoveJSONprefill(messages) {
|
|
|
72
74
|
}
|
|
73
75
|
return messages ?? [];
|
|
74
76
|
}
|
|
75
|
-
|
|
77
|
+
function converseJSONprefill(messages) {
|
|
78
|
+
if (!messages) {
|
|
79
|
+
messages = [];
|
|
80
|
+
}
|
|
81
|
+
//prefill the json
|
|
82
|
+
messages.push({
|
|
83
|
+
content: [{ text: "```json" }],
|
|
84
|
+
role: client_bedrock_runtime_1.ConversationRole.ASSISTANT,
|
|
85
|
+
});
|
|
86
|
+
return messages;
|
|
87
|
+
}
|
|
88
|
+
async function formatConversePrompt(segments, schema) {
|
|
76
89
|
//Non-const for concat
|
|
77
90
|
let system = [];
|
|
78
91
|
const safety = [];
|
|
79
92
|
let messages = [];
|
|
80
93
|
for (const segment of segments) {
|
|
81
94
|
const parts = [];
|
|
95
|
+
//Tool response
|
|
96
|
+
if (segment.role === core_1.PromptRole.tool) {
|
|
97
|
+
parts.push({
|
|
98
|
+
content: [{
|
|
99
|
+
toolResult: {
|
|
100
|
+
toolUseId: segment.tool_use_id,
|
|
101
|
+
content: [{ text: segment.content }],
|
|
102
|
+
}
|
|
103
|
+
}],
|
|
104
|
+
role: client_bedrock_runtime_1.ConversationRole.USER,
|
|
105
|
+
});
|
|
106
|
+
messages = messages.concat(parts);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
82
109
|
//File segments
|
|
83
|
-
if (segment.files)
|
|
110
|
+
if (segment.files) {
|
|
84
111
|
for (const f of segment.files) {
|
|
85
112
|
const source = await f.getStream();
|
|
86
113
|
let content;
|
|
@@ -110,14 +137,41 @@ async function fortmatConversePrompt(segments, schema) {
|
|
|
110
137
|
//Video file - "mov | mkv | mp4 | webm | flv | mpeg | mpg | wmv | three_gp"
|
|
111
138
|
}
|
|
112
139
|
else if (f.mime_type && f.mime_type.startsWith("video")) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
140
|
+
let url_string = (await f.getURL()).toLowerCase();
|
|
141
|
+
let url_format = new URL(url_string);
|
|
142
|
+
if (url_format.hostname.endsWith("amazonaws.com") &&
|
|
143
|
+
(url_format.hostname.startsWith("s3.") || url_format.hostname.includes(".s3."))) {
|
|
144
|
+
//Convert to s3:// format
|
|
145
|
+
const parsedUrl = (0, s3_js_1.parseS3UrlToUri)(new URL(url_string));
|
|
146
|
+
url_string = parsedUrl;
|
|
147
|
+
url_format = new URL(parsedUrl);
|
|
148
|
+
}
|
|
149
|
+
if (url_format.protocol === "s3:") {
|
|
150
|
+
//Use S3 bucket if available
|
|
151
|
+
content = [
|
|
152
|
+
{
|
|
153
|
+
video: {
|
|
154
|
+
format: mimeToVideoType(f.mime_type),
|
|
155
|
+
source: {
|
|
156
|
+
s3Location: {
|
|
157
|
+
uri: url_string, //S3 URL
|
|
158
|
+
//bucketOwner: We don't have this additional information.
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
},
|
|
118
162
|
},
|
|
119
|
-
|
|
120
|
-
|
|
163
|
+
];
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
content = [
|
|
167
|
+
{
|
|
168
|
+
video: {
|
|
169
|
+
format: mimeToVideoType(f.mime_type),
|
|
170
|
+
source: { bytes: await readStreamAsUint8Array(source) },
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
}
|
|
121
175
|
//Fallback, send string
|
|
122
176
|
}
|
|
123
177
|
else {
|
|
@@ -128,6 +182,7 @@ async function fortmatConversePrompt(segments, schema) {
|
|
|
128
182
|
role: roleConversion(segment.role),
|
|
129
183
|
});
|
|
130
184
|
}
|
|
185
|
+
}
|
|
131
186
|
//Text segments
|
|
132
187
|
if (segment.content) {
|
|
133
188
|
parts.push({
|
|
@@ -161,11 +216,6 @@ async function fortmatConversePrompt(segments, schema) {
|
|
|
161
216
|
if (schema) {
|
|
162
217
|
safety.push({ text: "IMPORTANT: " + getJSONSafetyNotice(schema) });
|
|
163
218
|
system = system.concat(safety);
|
|
164
|
-
//prefill the json
|
|
165
|
-
messages.push({
|
|
166
|
-
content: [{ text: "```json" }],
|
|
167
|
-
role: client_bedrock_runtime_1.ConversationRole.ASSISTANT,
|
|
168
|
-
});
|
|
169
219
|
}
|
|
170
220
|
messages = converseConcatMessages(messages);
|
|
171
221
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converse.js","sourceRoot":"","sources":["../../../src/bedrock/converse.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"converse.js","sourceRoot":"","sources":["../../../src/bedrock/converse.ts"],"names":[],"mappings":";;AAuDA,wDAWC;AAED,4DAKC;AAED,8DAQC;AAED,kDAWC;AAED,oDAgJC;AAjPD,2CAA6D;AAC7D,4EAMyC;AACzC,mCAA0C;AAE1C,SAAS,mBAAmB,CAAC,MAAkB;IAC3C,OAAO,qEAAqE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;AACxH,CAAC;AAED,SAAS,cAAc,CAAC,IAAgB;IACpC,OAAO,IAAI,KAAK,iBAAU,CAAC,SAAS,CAAC,CAAC,CAAC,yCAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,yCAAgB,CAAC,IAAI,CAAC;AAC9F,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACjC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAoC,CAAC;IACjE,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CAA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,EAAE,SAAS,EAAE,gDAAgD;QACpE,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,MAAM;KACjB,CAAC;AACN,CAAC"}
|
package/lib/cjs/bedrock/index.js
CHANGED
|
@@ -66,9 +66,9 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
66
66
|
if (opts.model.includes("canvas")) {
|
|
67
67
|
return await (0, formatters_1.formatNovaPrompt)(segments, opts.result_schema);
|
|
68
68
|
}
|
|
69
|
-
return await (0, converse_js_1.
|
|
69
|
+
return await (0, converse_js_1.formatConversePrompt)(segments, opts.result_schema);
|
|
70
70
|
}
|
|
71
|
-
static
|
|
71
|
+
static getExtractedExecution(result, _prompt) {
|
|
72
72
|
return {
|
|
73
73
|
result: result.output?.message?.content?.map(c => c.text).join("\n") ?? "",
|
|
74
74
|
token_usage: {
|
|
@@ -105,14 +105,39 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
105
105
|
}
|
|
106
106
|
;
|
|
107
107
|
async requestTextCompletion(prompt, options) {
|
|
108
|
-
|
|
108
|
+
let conversation = updateConversation(options.conversation, prompt);
|
|
109
|
+
const payload = this.preparePayload(conversation, options);
|
|
109
110
|
const executor = this.getExecutor();
|
|
110
111
|
const res = await executor.converse({
|
|
111
112
|
...payload,
|
|
112
113
|
});
|
|
114
|
+
conversation = updateConversation(conversation, {
|
|
115
|
+
messages: [res.output?.message ?? { content: [{ text: "" }], role: "assistant" }],
|
|
116
|
+
modelId: prompt.modelId,
|
|
117
|
+
});
|
|
118
|
+
let tool_use = undefined;
|
|
119
|
+
//Get tool requests
|
|
120
|
+
if (res.stopReason == "tool_use") {
|
|
121
|
+
tool_use = res.output?.message?.content?.reduce((tools, c) => {
|
|
122
|
+
if (c.toolUse) {
|
|
123
|
+
tools.push({
|
|
124
|
+
tool_name: c.toolUse.name ?? "",
|
|
125
|
+
tool_input: c.toolUse.input,
|
|
126
|
+
id: c.toolUse.toolUseId ?? "",
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return tools;
|
|
130
|
+
}, []);
|
|
131
|
+
//If no tools were used, set to undefined
|
|
132
|
+
if (tool_use && tool_use.length == 0) {
|
|
133
|
+
tool_use = undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
113
136
|
const completion = {
|
|
114
|
-
...BedrockDriver.
|
|
137
|
+
...BedrockDriver.getExtractedExecution(res, prompt),
|
|
115
138
|
original_response: options.include_original_response ? res : undefined,
|
|
139
|
+
conversation: conversation,
|
|
140
|
+
tool_use: tool_use,
|
|
116
141
|
};
|
|
117
142
|
return completion;
|
|
118
143
|
}
|
|
@@ -216,12 +241,18 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
216
241
|
const model_options = options.model_options;
|
|
217
242
|
let additionalField = {};
|
|
218
243
|
if (options.model.includes("amazon")) {
|
|
244
|
+
if (options.result_schema) {
|
|
245
|
+
prompt.messages = (0, converse_js_1.converseJSONprefill)(prompt.messages);
|
|
246
|
+
}
|
|
219
247
|
//Titan models also exists but does not support any additional options
|
|
220
248
|
if (options.model.includes("nova")) {
|
|
221
249
|
additionalField = { inferenceConfig: { topK: model_options?.top_k } };
|
|
222
250
|
}
|
|
223
251
|
}
|
|
224
252
|
else if (options.model.includes("claude")) {
|
|
253
|
+
if (options.result_schema) {
|
|
254
|
+
prompt.messages = (0, converse_js_1.converseJSONprefill)(prompt.messages);
|
|
255
|
+
}
|
|
225
256
|
if (options.model.includes("claude-3-7")) {
|
|
226
257
|
const thinking_options = options.model_options;
|
|
227
258
|
const thinking = thinking_options?.thinking_mode ?? false;
|
|
@@ -229,7 +260,7 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
229
260
|
model_options.max_tokens = thinking ? 128000 : 8192;
|
|
230
261
|
}
|
|
231
262
|
additionalField = {
|
|
232
|
-
|
|
263
|
+
...additionalField,
|
|
233
264
|
reasoning_config: {
|
|
234
265
|
type: thinking ? "enabled" : "disabled",
|
|
235
266
|
budget_tokens: thinking_options?.thinking_budget_tokens,
|
|
@@ -244,23 +275,12 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
244
275
|
}
|
|
245
276
|
//Needs max_tokens to be set
|
|
246
277
|
if (!model_options?.max_tokens) {
|
|
247
|
-
|
|
248
|
-
model_options.max_tokens = 8192;
|
|
249
|
-
//Bug with AWS Converse Sonnet 3.5, does not effect Haiku.
|
|
250
|
-
//See https://github.com/boto/boto3/issues/4279
|
|
251
|
-
if (options.model.includes("claude-3-5-sonnet")) {
|
|
252
|
-
model_options.max_tokens = 4096;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
model_options.max_tokens = 4096;
|
|
257
|
-
}
|
|
278
|
+
model_options.max_tokens = (0, core_1.getMaxTokensLimit)(options.model, model_options);
|
|
258
279
|
}
|
|
259
|
-
additionalField = { top_k: model_options?.top_k };
|
|
280
|
+
additionalField = { ...additionalField, top_k: model_options?.top_k };
|
|
260
281
|
}
|
|
261
282
|
else if (options.model.includes("meta")) {
|
|
262
|
-
//
|
|
263
|
-
prompt.messages = (0, converse_js_1.converseRemoveJSONprefill)(prompt.messages);
|
|
283
|
+
//LLaMA models support no additional options
|
|
264
284
|
}
|
|
265
285
|
else if (options.model.includes("mistral")) {
|
|
266
286
|
//7B instruct and 8x7B instruct
|
|
@@ -272,16 +292,16 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
272
292
|
prompt.system = undefined;
|
|
273
293
|
prompt.messages = (0, converse_js_1.converseConcatMessages)(prompt.messages);
|
|
274
294
|
}
|
|
295
|
+
if (options.result_schema) {
|
|
296
|
+
prompt.messages = (0, converse_js_1.converseJSONprefill)(prompt.messages);
|
|
297
|
+
}
|
|
275
298
|
}
|
|
276
299
|
else {
|
|
277
300
|
//Other models such as Mistral Small,Large and Large 2
|
|
278
301
|
//Support no additional fields.
|
|
279
|
-
prompt.messages = (0, converse_js_1.converseRemoveJSONprefill)(prompt.messages);
|
|
280
302
|
}
|
|
281
303
|
}
|
|
282
304
|
else if (options.model.includes("ai21")) {
|
|
283
|
-
//If last message is "```json", remove it. Model requires the final message to be a user message
|
|
284
|
-
prompt.messages = (0, converse_js_1.converseRemoveJSONprefill)(prompt.messages);
|
|
285
305
|
//Jamba models support no additional options
|
|
286
306
|
//Jurassic 2 models do.
|
|
287
307
|
if (options.model.includes("j2")) {
|
|
@@ -299,8 +319,6 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
299
319
|
}
|
|
300
320
|
else if (options.model.includes("cohere.command")) {
|
|
301
321
|
// If last message is "```json", remove it.
|
|
302
|
-
// Model requires the final message to be a user message or does not support assistant messages
|
|
303
|
-
prompt.messages = (0, converse_js_1.converseRemoveJSONprefill)(prompt.messages);
|
|
304
322
|
//Command R and R plus
|
|
305
323
|
if (options.model.includes("cohere.command-r")) {
|
|
306
324
|
additionalField = {
|
|
@@ -320,6 +338,18 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
320
338
|
}
|
|
321
339
|
}
|
|
322
340
|
}
|
|
341
|
+
else if (options.model.includes("palmyra")) {
|
|
342
|
+
const palmyraOptions = options.model_options;
|
|
343
|
+
additionalField = {
|
|
344
|
+
seed: palmyraOptions?.seed,
|
|
345
|
+
presence_penalty: palmyraOptions?.presence_penalty,
|
|
346
|
+
frequency_penalty: palmyraOptions?.frequency_penalty,
|
|
347
|
+
min_tokens: palmyraOptions?.min_tokens,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
else if (options.model.includes("deepseek")) {
|
|
351
|
+
//DeepSeek models support no additional options
|
|
352
|
+
}
|
|
323
353
|
//If last message is "```json", add corresponding ``` as a stop sequence.
|
|
324
354
|
if (prompt.messages && prompt.messages.length > 0) {
|
|
325
355
|
if (prompt.messages[prompt.messages.length - 1].content?.[0].text === "```json") {
|
|
@@ -333,7 +363,8 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
333
363
|
}
|
|
334
364
|
}
|
|
335
365
|
}
|
|
336
|
-
|
|
366
|
+
const tool_defs = getToolDefinitions(options.tools);
|
|
367
|
+
const request = {
|
|
337
368
|
messages: prompt.messages,
|
|
338
369
|
system: prompt.system,
|
|
339
370
|
modelId: options.model,
|
|
@@ -345,8 +376,15 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
345
376
|
},
|
|
346
377
|
additionalModelRequestFields: {
|
|
347
378
|
...additionalField,
|
|
348
|
-
}
|
|
379
|
+
}
|
|
349
380
|
};
|
|
381
|
+
//Only add tools if they are defined
|
|
382
|
+
if (tool_defs) {
|
|
383
|
+
request.toolConfig = {
|
|
384
|
+
tools: tool_defs,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
return request;
|
|
350
388
|
}
|
|
351
389
|
async requestImageGeneration(prompt, options) {
|
|
352
390
|
if (options.output_modality !== core_1.Modalities.image) {
|
|
@@ -450,7 +488,7 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
450
488
|
}
|
|
451
489
|
async _listModels(foundationFilter) {
|
|
452
490
|
const service = this.getService();
|
|
453
|
-
const [
|
|
491
|
+
const [foundationModelsList, customModelsList, inferenceProfilesList] = await Promise.all([
|
|
454
492
|
service.listFoundationModels({}).catch(() => {
|
|
455
493
|
this.logger.warn("[Bedrock] Can't list foundation models. Check if the user has the right permissions.");
|
|
456
494
|
return undefined;
|
|
@@ -464,68 +502,114 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
464
502
|
return undefined;
|
|
465
503
|
}),
|
|
466
504
|
]);
|
|
467
|
-
if (!
|
|
505
|
+
if (!foundationModelsList?.modelSummaries) {
|
|
468
506
|
throw new Error("Foundation models not found");
|
|
469
507
|
}
|
|
470
|
-
let
|
|
508
|
+
let foundationModels = foundationModelsList.modelSummaries || [];
|
|
471
509
|
if (foundationFilter) {
|
|
472
|
-
|
|
510
|
+
foundationModels = foundationModels.filter(foundationFilter);
|
|
473
511
|
}
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
512
|
+
const supportedPublishers = ["amazon", "anthropic", "cohere", "ai21", "mistral", "meta", "deepseek", "writer"];
|
|
513
|
+
const unsupportedModelsByPublisher = {
|
|
514
|
+
amazon: ["titan-image-generator", "nova-reel", "nova-sonic", "rerank"],
|
|
515
|
+
anthropic: [],
|
|
516
|
+
cohere: ["rerank"],
|
|
517
|
+
ai21: [],
|
|
518
|
+
mistral: [],
|
|
519
|
+
meta: [],
|
|
520
|
+
deepseek: [],
|
|
521
|
+
writer: [],
|
|
522
|
+
};
|
|
523
|
+
// Helper function to check if model should be filtered out
|
|
524
|
+
const shouldIncludeModel = (modelId, providerName) => {
|
|
525
|
+
if (!modelId || !providerName)
|
|
526
|
+
return false;
|
|
527
|
+
const normalizedProvider = providerName.toLowerCase();
|
|
528
|
+
// Check if provider is supported
|
|
529
|
+
const isProviderSupported = supportedPublishers.some(provider => normalizedProvider.includes(provider));
|
|
530
|
+
if (!isProviderSupported)
|
|
531
|
+
return false;
|
|
532
|
+
// Check if model is in the unsupported list for its provider
|
|
533
|
+
for (const provider of supportedPublishers) {
|
|
534
|
+
if (normalizedProvider.includes(provider)) {
|
|
535
|
+
const unsupportedModels = unsupportedModelsByPublisher[provider] || [];
|
|
536
|
+
return !unsupportedModels.some(unsupported => modelId.toLowerCase().includes(unsupported));
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return true;
|
|
540
|
+
};
|
|
541
|
+
foundationModels = foundationModels.filter(m => shouldIncludeModel(m.modelId, m.providerName));
|
|
542
|
+
const aiModels = foundationModels.map((m) => {
|
|
481
543
|
if (!m.modelId) {
|
|
482
544
|
throw new Error("modelId not found");
|
|
483
545
|
}
|
|
546
|
+
const modelCapability = (0, core_1.getModelCapabilities)(m.modelArn ?? m.modelId, this.provider);
|
|
484
547
|
const model = {
|
|
485
548
|
id: m.modelArn ?? m.modelId,
|
|
486
549
|
name: `${m.providerName} ${m.modelName}`,
|
|
487
550
|
provider: this.provider,
|
|
488
|
-
input_modalities: m.inputModalities ?? [],
|
|
489
551
|
//description: ``,
|
|
490
552
|
owner: m.providerName,
|
|
491
553
|
can_stream: m.responseStreamingSupported ?? false,
|
|
492
|
-
|
|
493
|
-
|
|
554
|
+
input_modalities: m.inputModalities ? formatAmazonModalities(m.inputModalities) : (0, core_1.modelModalitiesToArray)(modelCapability.input),
|
|
555
|
+
output_modalities: m.outputModalities ? formatAmazonModalities(m.outputModalities) : (0, core_1.modelModalitiesToArray)(modelCapability.input),
|
|
556
|
+
tool_support: modelCapability.tool_support,
|
|
494
557
|
};
|
|
495
558
|
return model;
|
|
496
559
|
});
|
|
497
560
|
//add custom models
|
|
498
|
-
if (
|
|
499
|
-
|
|
561
|
+
if (customModelsList?.modelSummaries) {
|
|
562
|
+
customModelsList.modelSummaries.forEach((m) => {
|
|
500
563
|
if (!m.modelArn) {
|
|
501
564
|
throw new Error("Model ID not found");
|
|
502
565
|
}
|
|
566
|
+
const modelCapability = (0, core_1.getModelCapabilities)(m.modelArn, this.provider);
|
|
503
567
|
const model = {
|
|
504
568
|
id: m.modelArn,
|
|
505
569
|
name: m.modelName ?? m.modelArn,
|
|
506
570
|
provider: this.provider,
|
|
507
571
|
description: `Custom model from ${m.baseModelName}`,
|
|
508
572
|
is_custom: true,
|
|
573
|
+
input_modalities: (0, core_1.modelModalitiesToArray)(modelCapability.input),
|
|
574
|
+
output_modalities: (0, core_1.modelModalitiesToArray)(modelCapability.output),
|
|
575
|
+
tool_support: modelCapability.tool_support,
|
|
509
576
|
};
|
|
510
|
-
|
|
577
|
+
aiModels.push(model);
|
|
511
578
|
this.validateConnection;
|
|
512
579
|
});
|
|
513
580
|
}
|
|
514
581
|
//add inference profiles
|
|
515
|
-
if (
|
|
516
|
-
|
|
582
|
+
if (inferenceProfilesList?.inferenceProfileSummaries) {
|
|
583
|
+
inferenceProfilesList.inferenceProfileSummaries.forEach((p) => {
|
|
517
584
|
if (!p.inferenceProfileArn) {
|
|
518
585
|
throw new Error("Profile ARN not found");
|
|
519
586
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
587
|
+
// Apply the same filtering logic to inference profiles based on their name
|
|
588
|
+
const profileId = p.inferenceProfileId || "";
|
|
589
|
+
const profileName = p.inferenceProfileName || "";
|
|
590
|
+
// Extract provider name from profile name or ID
|
|
591
|
+
let providerName = "";
|
|
592
|
+
for (const provider of supportedPublishers) {
|
|
593
|
+
if (profileName.toLowerCase().includes(provider) || profileId.toLowerCase().includes(provider)) {
|
|
594
|
+
providerName = provider;
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const modelCapability = (0, core_1.getModelCapabilities)(p.inferenceProfileArn ?? p.inferenceProfileId, this.provider);
|
|
599
|
+
if (providerName && shouldIncludeModel(profileId, providerName)) {
|
|
600
|
+
const model = {
|
|
601
|
+
id: p.inferenceProfileArn ?? p.inferenceProfileId,
|
|
602
|
+
name: p.inferenceProfileName ?? p.inferenceProfileArn,
|
|
603
|
+
provider: this.provider,
|
|
604
|
+
input_modalities: (0, core_1.modelModalitiesToArray)(modelCapability.input),
|
|
605
|
+
output_modalities: (0, core_1.modelModalitiesToArray)(modelCapability.output),
|
|
606
|
+
tool_support: modelCapability.tool_support,
|
|
607
|
+
};
|
|
608
|
+
aiModels.push(model);
|
|
609
|
+
}
|
|
526
610
|
});
|
|
527
611
|
}
|
|
528
|
-
return
|
|
612
|
+
return aiModels;
|
|
529
613
|
}
|
|
530
614
|
async generateEmbeddings({ text, image, model }) {
|
|
531
615
|
this.logger.info("[Bedrock] Generating embeddings with model " + model);
|
|
@@ -581,4 +665,57 @@ function jobInfo(job, jobId) {
|
|
|
581
665
|
details
|
|
582
666
|
};
|
|
583
667
|
}
|
|
668
|
+
function getToolDefinitions(tools) {
|
|
669
|
+
return tools ? tools.map(getToolDefinition) : undefined;
|
|
670
|
+
}
|
|
671
|
+
function getToolDefinition(tool) {
|
|
672
|
+
return {
|
|
673
|
+
toolSpec: {
|
|
674
|
+
name: tool.name,
|
|
675
|
+
description: tool.description,
|
|
676
|
+
inputSchema: {
|
|
677
|
+
json: tool.input_schema,
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Update the conversation messages
|
|
684
|
+
* @param prompt
|
|
685
|
+
* @param response
|
|
686
|
+
* @returns
|
|
687
|
+
*/
|
|
688
|
+
function updateConversation(conversation, prompt) {
|
|
689
|
+
return {
|
|
690
|
+
...conversation,
|
|
691
|
+
...prompt,
|
|
692
|
+
messages: [...(conversation?.messages || []), ...(prompt.messages || [])],
|
|
693
|
+
system: prompt.system || conversation?.system,
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function formatAmazonModalities(modalities) {
|
|
697
|
+
const standardizedModalities = [];
|
|
698
|
+
for (const modality of modalities) {
|
|
699
|
+
if (modality === client_bedrock_1.ModelModality.TEXT) {
|
|
700
|
+
standardizedModalities.push("text");
|
|
701
|
+
}
|
|
702
|
+
else if (modality === client_bedrock_1.ModelModality.IMAGE) {
|
|
703
|
+
standardizedModalities.push("image");
|
|
704
|
+
}
|
|
705
|
+
else if (modality === client_bedrock_1.ModelModality.EMBEDDING) {
|
|
706
|
+
standardizedModalities.push("embedding");
|
|
707
|
+
}
|
|
708
|
+
else if (modality == "SPEECH") {
|
|
709
|
+
standardizedModalities.push("audio");
|
|
710
|
+
}
|
|
711
|
+
else if (modality == "VIDEO") {
|
|
712
|
+
standardizedModalities.push("video");
|
|
713
|
+
}
|
|
714
|
+
else {
|
|
715
|
+
// Handle other modalities as needed
|
|
716
|
+
standardizedModalities.push(modality.toString().toLowerCase());
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return standardizedModalities;
|
|
720
|
+
}
|
|
584
721
|
//# sourceMappingURL=index.js.map
|