@llumiverse/drivers 0.16.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 +191 -51
- 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 +4 -4
- 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 +218 -83
- package/lib/cjs/openai/index.js.map +1 -1
- package/lib/cjs/replicate.js +4 -17
- package/lib/cjs/replicate.js.map +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 +117 -52
- package/lib/cjs/vertexai/index.js.map +1 -1
- package/lib/cjs/vertexai/models/claude.js +51 -17
- package/lib/cjs/vertexai/models/claude.js.map +1 -1
- package/lib/cjs/vertexai/models/gemini.js +42 -20
- 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 +12 -6
- package/lib/cjs/watsonx/index.js.map +1 -1
- package/lib/esm/bedrock/converse.js +63 -14
- package/lib/esm/bedrock/converse.js.map +1 -1
- package/lib/esm/bedrock/index.js +193 -50
- 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 +4 -4
- 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 +219 -85
- package/lib/esm/openai/index.js.map +1 -1
- package/lib/esm/replicate.js +3 -16
- package/lib/esm/replicate.js.map +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 +120 -55
- package/lib/esm/vertexai/index.js.map +1 -1
- package/lib/esm/vertexai/models/claude.js +52 -18
- package/lib/esm/vertexai/models/claude.js.map +1 -1
- package/lib/esm/vertexai/models/gemini.js +42 -20
- 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 +12 -6
- package/lib/esm/watsonx/index.js.map +1 -1
- package/lib/types/bedrock/converse.d.ts +3 -2
- package/lib/types/bedrock/converse.d.ts.map +1 -1
- package/lib/types/bedrock/index.d.ts +5 -16
- 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 +11 -6
- 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/gemini.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/lib/types/watsonx/index.d.ts.map +1 -1
- package/lib/types/watsonx/interfaces.d.ts +4 -0
- package/lib/types/watsonx/interfaces.d.ts.map +1 -1
- package/package.json +19 -21
- package/src/bedrock/converse.ts +69 -20
- package/src/bedrock/index.ts +231 -62
- 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 +4 -4
- package/src/openai/azure.ts +2 -2
- package/src/openai/index.ts +269 -93
- package/src/openai/openai.ts +1 -1
- package/src/replicate.ts +4 -16
- 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 +168 -67
- package/src/vertexai/models/claude.ts +71 -32
- package/src/vertexai/models/gemini.ts +47 -23
- package/src/vertexai/models/imagen.ts +4 -3
- package/src/vertexai/models.ts +1 -1
- package/src/watsonx/index.ts +12 -6
- package/src/watsonx/interfaces.ts +4 -0
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,C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AC;IAED,IAAI,MAAM,EAAE,CAAC;QACT,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,GAAG,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,QAAQ,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAE5C,OAAO;QACH,OAAO,EAAE,SAAS,EAAE,gDAAgD;QACpE,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,MAAM;KACjB,CAAC;AACN,CAAC"}
|
package/lib/cjs/bedrock/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.BedrockDriver = void 0;
|
|
7
4
|
const client_bedrock_1 = require("@aws-sdk/client-bedrock");
|
|
@@ -10,12 +7,11 @@ const client_s3_1 = require("@aws-sdk/client-s3");
|
|
|
10
7
|
const core_1 = require("@llumiverse/core");
|
|
11
8
|
const async_1 = require("@llumiverse/core/async");
|
|
12
9
|
const formatters_1 = require("@llumiverse/core/formatters");
|
|
13
|
-
const mnemonist_1 =
|
|
10
|
+
const mnemonist_1 = require("mnemonist");
|
|
14
11
|
const converse_js_1 = require("./converse.js");
|
|
15
12
|
const nova_image_payload_js_1 = require("./nova-image-payload.js");
|
|
16
13
|
const s3_js_1 = require("./s3.js");
|
|
17
|
-
const
|
|
18
|
-
const supportStreamingCache = new LRUCache(4096);
|
|
14
|
+
const supportStreamingCache = new mnemonist_1.LRUCache(4096);
|
|
19
15
|
var BedrockModelType;
|
|
20
16
|
(function (BedrockModelType) {
|
|
21
17
|
BedrockModelType["FoundationModel"] = "foundation-model";
|
|
@@ -70,9 +66,9 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
70
66
|
if (opts.model.includes("canvas")) {
|
|
71
67
|
return await (0, formatters_1.formatNovaPrompt)(segments, opts.result_schema);
|
|
72
68
|
}
|
|
73
|
-
return await (0, converse_js_1.
|
|
69
|
+
return await (0, converse_js_1.formatConversePrompt)(segments, opts.result_schema);
|
|
74
70
|
}
|
|
75
|
-
static
|
|
71
|
+
static getExtractedExecution(result, _prompt) {
|
|
76
72
|
return {
|
|
77
73
|
result: result.output?.message?.content?.map(c => c.text).join("\n") ?? "",
|
|
78
74
|
token_usage: {
|
|
@@ -109,14 +105,39 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
109
105
|
}
|
|
110
106
|
;
|
|
111
107
|
async requestTextCompletion(prompt, options) {
|
|
112
|
-
|
|
108
|
+
let conversation = updateConversation(options.conversation, prompt);
|
|
109
|
+
const payload = this.preparePayload(conversation, options);
|
|
113
110
|
const executor = this.getExecutor();
|
|
114
111
|
const res = await executor.converse({
|
|
115
112
|
...payload,
|
|
116
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
|
+
}
|
|
117
136
|
const completion = {
|
|
118
|
-
...BedrockDriver.
|
|
137
|
+
...BedrockDriver.getExtractedExecution(res, prompt),
|
|
119
138
|
original_response: options.include_original_response ? res : undefined,
|
|
139
|
+
conversation: conversation,
|
|
140
|
+
tool_use: tool_use,
|
|
120
141
|
};
|
|
121
142
|
return completion;
|
|
122
143
|
}
|
|
@@ -220,12 +241,18 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
220
241
|
const model_options = options.model_options;
|
|
221
242
|
let additionalField = {};
|
|
222
243
|
if (options.model.includes("amazon")) {
|
|
244
|
+
if (options.result_schema) {
|
|
245
|
+
prompt.messages = (0, converse_js_1.converseJSONprefill)(prompt.messages);
|
|
246
|
+
}
|
|
223
247
|
//Titan models also exists but does not support any additional options
|
|
224
248
|
if (options.model.includes("nova")) {
|
|
225
249
|
additionalField = { inferenceConfig: { topK: model_options?.top_k } };
|
|
226
250
|
}
|
|
227
251
|
}
|
|
228
252
|
else if (options.model.includes("claude")) {
|
|
253
|
+
if (options.result_schema) {
|
|
254
|
+
prompt.messages = (0, converse_js_1.converseJSONprefill)(prompt.messages);
|
|
255
|
+
}
|
|
229
256
|
if (options.model.includes("claude-3-7")) {
|
|
230
257
|
const thinking_options = options.model_options;
|
|
231
258
|
const thinking = thinking_options?.thinking_mode ?? false;
|
|
@@ -233,7 +260,7 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
233
260
|
model_options.max_tokens = thinking ? 128000 : 8192;
|
|
234
261
|
}
|
|
235
262
|
additionalField = {
|
|
236
|
-
|
|
263
|
+
...additionalField,
|
|
237
264
|
reasoning_config: {
|
|
238
265
|
type: thinking ? "enabled" : "disabled",
|
|
239
266
|
budget_tokens: thinking_options?.thinking_budget_tokens,
|
|
@@ -248,23 +275,12 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
248
275
|
}
|
|
249
276
|
//Needs max_tokens to be set
|
|
250
277
|
if (!model_options?.max_tokens) {
|
|
251
|
-
|
|
252
|
-
model_options.max_tokens = 8192;
|
|
253
|
-
//Bug with AWS Converse Sonnet 3.5, does not effect Haiku.
|
|
254
|
-
//See https://github.com/boto/boto3/issues/4279
|
|
255
|
-
if (options.model.includes("claude-3-5-sonnet")) {
|
|
256
|
-
model_options.max_tokens = 4096;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
model_options.max_tokens = 4096;
|
|
261
|
-
}
|
|
278
|
+
model_options.max_tokens = (0, core_1.getMaxTokensLimit)(options.model, model_options);
|
|
262
279
|
}
|
|
263
|
-
additionalField = { top_k: model_options?.top_k };
|
|
280
|
+
additionalField = { ...additionalField, top_k: model_options?.top_k };
|
|
264
281
|
}
|
|
265
282
|
else if (options.model.includes("meta")) {
|
|
266
|
-
//
|
|
267
|
-
prompt.messages = (0, converse_js_1.converseRemoveJSONprefill)(prompt.messages);
|
|
283
|
+
//LLaMA models support no additional options
|
|
268
284
|
}
|
|
269
285
|
else if (options.model.includes("mistral")) {
|
|
270
286
|
//7B instruct and 8x7B instruct
|
|
@@ -276,16 +292,16 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
276
292
|
prompt.system = undefined;
|
|
277
293
|
prompt.messages = (0, converse_js_1.converseConcatMessages)(prompt.messages);
|
|
278
294
|
}
|
|
295
|
+
if (options.result_schema) {
|
|
296
|
+
prompt.messages = (0, converse_js_1.converseJSONprefill)(prompt.messages);
|
|
297
|
+
}
|
|
279
298
|
}
|
|
280
299
|
else {
|
|
281
300
|
//Other models such as Mistral Small,Large and Large 2
|
|
282
301
|
//Support no additional fields.
|
|
283
|
-
prompt.messages = (0, converse_js_1.converseRemoveJSONprefill)(prompt.messages);
|
|
284
302
|
}
|
|
285
303
|
}
|
|
286
304
|
else if (options.model.includes("ai21")) {
|
|
287
|
-
//If last message is "```json", remove it. Model requires the final message to be a user message
|
|
288
|
-
prompt.messages = (0, converse_js_1.converseRemoveJSONprefill)(prompt.messages);
|
|
289
305
|
//Jamba models support no additional options
|
|
290
306
|
//Jurassic 2 models do.
|
|
291
307
|
if (options.model.includes("j2")) {
|
|
@@ -303,8 +319,6 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
303
319
|
}
|
|
304
320
|
else if (options.model.includes("cohere.command")) {
|
|
305
321
|
// If last message is "```json", remove it.
|
|
306
|
-
// Model requires the final message to be a user message or does not support assistant messages
|
|
307
|
-
prompt.messages = (0, converse_js_1.converseRemoveJSONprefill)(prompt.messages);
|
|
308
322
|
//Command R and R plus
|
|
309
323
|
if (options.model.includes("cohere.command-r")) {
|
|
310
324
|
additionalField = {
|
|
@@ -324,6 +338,18 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
324
338
|
}
|
|
325
339
|
}
|
|
326
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
|
+
}
|
|
327
353
|
//If last message is "```json", add corresponding ``` as a stop sequence.
|
|
328
354
|
if (prompt.messages && prompt.messages.length > 0) {
|
|
329
355
|
if (prompt.messages[prompt.messages.length - 1].content?.[0].text === "```json") {
|
|
@@ -337,7 +363,8 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
337
363
|
}
|
|
338
364
|
}
|
|
339
365
|
}
|
|
340
|
-
|
|
366
|
+
const tool_defs = getToolDefinitions(options.tools);
|
|
367
|
+
const request = {
|
|
341
368
|
messages: prompt.messages,
|
|
342
369
|
system: prompt.system,
|
|
343
370
|
modelId: options.model,
|
|
@@ -349,8 +376,15 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
349
376
|
},
|
|
350
377
|
additionalModelRequestFields: {
|
|
351
378
|
...additionalField,
|
|
352
|
-
}
|
|
379
|
+
}
|
|
353
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;
|
|
354
388
|
}
|
|
355
389
|
async requestImageGeneration(prompt, options) {
|
|
356
390
|
if (options.output_modality !== core_1.Modalities.image) {
|
|
@@ -454,7 +488,7 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
454
488
|
}
|
|
455
489
|
async _listModels(foundationFilter) {
|
|
456
490
|
const service = this.getService();
|
|
457
|
-
const [
|
|
491
|
+
const [foundationModelsList, customModelsList, inferenceProfilesList] = await Promise.all([
|
|
458
492
|
service.listFoundationModels({}).catch(() => {
|
|
459
493
|
this.logger.warn("[Bedrock] Can't list foundation models. Check if the user has the right permissions.");
|
|
460
494
|
return undefined;
|
|
@@ -468,17 +502,48 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
468
502
|
return undefined;
|
|
469
503
|
}),
|
|
470
504
|
]);
|
|
471
|
-
if (!
|
|
505
|
+
if (!foundationModelsList?.modelSummaries) {
|
|
472
506
|
throw new Error("Foundation models not found");
|
|
473
507
|
}
|
|
474
|
-
let
|
|
508
|
+
let foundationModels = foundationModelsList.modelSummaries || [];
|
|
475
509
|
if (foundationFilter) {
|
|
476
|
-
|
|
510
|
+
foundationModels = foundationModels.filter(foundationFilter);
|
|
477
511
|
}
|
|
478
|
-
const
|
|
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) => {
|
|
479
543
|
if (!m.modelId) {
|
|
480
544
|
throw new Error("modelId not found");
|
|
481
545
|
}
|
|
546
|
+
const modelCapability = (0, core_1.getModelCapabilities)(m.modelArn ?? m.modelId, this.provider);
|
|
482
547
|
const model = {
|
|
483
548
|
id: m.modelArn ?? m.modelId,
|
|
484
549
|
name: `${m.providerName} ${m.modelName}`,
|
|
@@ -486,43 +551,65 @@ class BedrockDriver extends core_1.AbstractDriver {
|
|
|
486
551
|
//description: ``,
|
|
487
552
|
owner: m.providerName,
|
|
488
553
|
can_stream: m.responseStreamingSupported ?? false,
|
|
489
|
-
|
|
490
|
-
|
|
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,
|
|
491
557
|
};
|
|
492
558
|
return model;
|
|
493
559
|
});
|
|
494
560
|
//add custom models
|
|
495
|
-
if (
|
|
496
|
-
|
|
561
|
+
if (customModelsList?.modelSummaries) {
|
|
562
|
+
customModelsList.modelSummaries.forEach((m) => {
|
|
497
563
|
if (!m.modelArn) {
|
|
498
564
|
throw new Error("Model ID not found");
|
|
499
565
|
}
|
|
566
|
+
const modelCapability = (0, core_1.getModelCapabilities)(m.modelArn, this.provider);
|
|
500
567
|
const model = {
|
|
501
568
|
id: m.modelArn,
|
|
502
569
|
name: m.modelName ?? m.modelArn,
|
|
503
570
|
provider: this.provider,
|
|
504
571
|
description: `Custom model from ${m.baseModelName}`,
|
|
505
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,
|
|
506
576
|
};
|
|
507
|
-
|
|
577
|
+
aiModels.push(model);
|
|
508
578
|
this.validateConnection;
|
|
509
579
|
});
|
|
510
580
|
}
|
|
511
581
|
//add inference profiles
|
|
512
|
-
if (
|
|
513
|
-
|
|
582
|
+
if (inferenceProfilesList?.inferenceProfileSummaries) {
|
|
583
|
+
inferenceProfilesList.inferenceProfileSummaries.forEach((p) => {
|
|
514
584
|
if (!p.inferenceProfileArn) {
|
|
515
585
|
throw new Error("Profile ARN not found");
|
|
516
586
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
+
}
|
|
523
610
|
});
|
|
524
611
|
}
|
|
525
|
-
return
|
|
612
|
+
return aiModels;
|
|
526
613
|
}
|
|
527
614
|
async generateEmbeddings({ text, image, model }) {
|
|
528
615
|
this.logger.info("[Bedrock] Generating embeddings with model " + model);
|
|
@@ -578,4 +665,57 @@ function jobInfo(job, jobId) {
|
|
|
578
665
|
details
|
|
579
666
|
};
|
|
580
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
|
+
}
|
|
581
721
|
//# sourceMappingURL=index.js.map
|