genkitx-aws-bedrock
Version:
Firebase Genkit AI framework plugin for AWS Bedrock APIs.
1,026 lines • 42.1 kB
JavaScript
;
/**
* Copyright 2024 Xavier Portilla Edo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SUPPORTED_AWS_BEDROCK_MODELS = exports.metaLlama38BInstruct = exports.metaLlama370BInstruct = exports.metaLlama318BInstruct = exports.metaLlama3170BInstruct = exports.metaLlama3290BInstruct = exports.metaLlama323BInstruct = exports.metaLlama321BInstruct = exports.metaLlama3211BInstruct = exports.metaLlama3370BInstruct = exports.ai21Jurassic2UltraV1 = exports.ai21Jurassic2MidV1 = exports.ai21JambaInstructV1 = exports.ai21Jamba15MiniV1 = exports.ai21Jamba15LargeV1 = exports.mistral8x7BInstructV01 = exports.mistral7BInstructV02 = exports.mistralSmall2402V1 = exports.mistralLarge2402V1 = exports.anthropicClaudeInstantV1 = exports.anthropicClaude2V1 = exports.anthropicClaude21V1 = exports.anthropicClaude3SonnetV1 = exports.anthropicClaude35SonnetV1 = exports.anthropicClaude35SonnetV2 = exports.anthropicClaude37SonnetV1 = exports.anthropicClaude3OpusV1 = exports.anthropicClaude3HaikuV1 = exports.anthropicClaude35HaikuV1 = exports.cohereCommandV14 = exports.cohereCommandLightV14 = exports.cohereCommandRPlusV1 = exports.cohereCommandRV1 = exports.amazonTitanTextG1LiteV1 = exports.amazonTitanTextG1ExpressV1 = exports.amazonTitanTextG1PremierV1 = exports.amazonNovaMicroV1 = exports.amazonNovaLiteV1 = exports.amazonNovaProV1 = void 0;
exports.toAwsBedrockTextAndMedia = toAwsBedrockTextAndMedia;
exports.getSystemMessage = getSystemMessage;
exports.toAwsBedrockMessages = toAwsBedrockMessages;
exports.toAwsBedrockRequestBody = toAwsBedrockRequestBody;
exports.awsBedrockModel = awsBedrockModel;
const genkit_1 = require("genkit");
const model_1 = require("genkit/model");
const client_bedrock_runtime_1 = require("@aws-sdk/client-bedrock-runtime");
exports.amazonNovaProV1 = (0, model_1.modelRef)({
name: "aws-bedrock/amazon.nova-pro-v1:0",
info: {
versions: ["amazon.nova-pro-v1:0"],
label: "Amazon - Nova Pro V1",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.amazonNovaLiteV1 = (0, model_1.modelRef)({
name: "aws-bedrock/amazon.nova-lite-v1:0",
info: {
versions: ["amazon.nova-lite-v1:0"],
label: "Amazon - Nova Lite V1",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.amazonNovaMicroV1 = (0, model_1.modelRef)({
name: "aws-bedrock/amazon.nova-micro-v1:0",
info: {
versions: ["amazon.nova-micro-v1:0"],
label: "Amazon - Nova Micro V1",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.amazonTitanTextG1PremierV1 = (0, model_1.modelRef)({
name: "aws-bedrock/amazon.titan-text-premier-v1:0",
info: {
versions: ["amazon.titan-text-premier-v1:0"],
label: "Amazon - Titan Text Premier G1 V1",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.amazonTitanTextG1ExpressV1 = (0, model_1.modelRef)({
name: "aws-bedrock/amazon.titan-text-express-v1",
info: {
versions: ["amazon.titan-text-express-v1"],
label: "Amazon - Titan Text Express G1 V1",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.amazonTitanTextG1LiteV1 = (0, model_1.modelRef)({
name: "aws-bedrock/amazon.titan-text-lite-v1",
info: {
versions: ["amazon.titan-text-lite-v1"],
label: "Amazon - Titan Text Lite G1 V1",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.cohereCommandRV1 = (0, model_1.modelRef)({
name: "aws-bedrock/cohere.command-r-v1:0",
info: {
versions: ["cohere.command-r-v1:0"],
label: "Cohere - Command R",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.cohereCommandRPlusV1 = (0, model_1.modelRef)({
name: "aws-bedrock/cohere.command-r-plus-v1:0",
info: {
versions: ["cohere.command-r-plus-v1:0"],
label: "Cohere - Command R+",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.cohereCommandLightV14 = (0, model_1.modelRef)({
name: "aws-bedrock/cohere.command-light-text-v14",
info: {
versions: ["cohere.command-light-text-v14"],
label: "Cohere - Command Light V14",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.cohereCommandV14 = (0, model_1.modelRef)({
name: "aws-bedrock/cohere.command-text-v14",
info: {
versions: ["cohere.command-text-v14"],
label: "Cohere - Command V14",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
const anthropicClaude35HaikuV1 = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.anthropic.claude-3-5-haiku-20241022-v1:0`,
info: {
versions: [`${inferenceRegion}.anthropic.claude-3-5-haiku-20241022-v1:0`],
label: "Anthropic - Claude 3.5 Haiku V1",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.anthropicClaude35HaikuV1 = anthropicClaude35HaikuV1;
const anthropicClaude3HaikuV1 = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.anthropic.claude-3-haiku-20240307-v1:0`,
info: {
versions: [`${inferenceRegion}.anthropic.claude-3-haiku-20240307-v1:0`],
label: "Anthropic - Claude 3 Haiku V1",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.anthropicClaude3HaikuV1 = anthropicClaude3HaikuV1;
const anthropicClaude3OpusV1 = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.anthropic.claude-3-opus-20240229-v1:0`,
info: {
versions: [`${inferenceRegion}.anthropic.claude-3-opus-20240229-v1:0`],
label: "Anthropic - Claude 3 Opus V1",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.anthropicClaude3OpusV1 = anthropicClaude3OpusV1;
const anthropicClaude37SonnetV1 = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.anthropic.claude-3-7-sonnet-20250219-v1:0`,
info: {
versions: [
`${inferenceRegion}.anthropic.claude-3-7-sonnet-20250219-v1:0`,
],
label: "Anthropic - Claude 3.7 Sonnet V1",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.anthropicClaude37SonnetV1 = anthropicClaude37SonnetV1;
const anthropicClaude35SonnetV2 = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.anthropic.claude-3-5-sonnet-20241022-v2:0`,
info: {
versions: [
`${inferenceRegion}.anthropic.claude-3-5-sonnet-20241022-v2:0`,
],
label: "Anthropic - Claude 3.5 Sonnet V2",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.anthropicClaude35SonnetV2 = anthropicClaude35SonnetV2;
const anthropicClaude35SonnetV1 = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.anthropic.claude-3-5-sonnet-20240620-v1:0`,
info: {
versions: [
`${inferenceRegion}.anthropic.claude-3-5-sonnet-20240620-v1:0`,
],
label: "Anthropic - Claude 3.5 Sonnet V1",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.anthropicClaude35SonnetV1 = anthropicClaude35SonnetV1;
const anthropicClaude3SonnetV1 = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.anthropic.claude-3-sonnet-20240229-v1:0`,
info: {
versions: [`${inferenceRegion}.anthropic.claude-3-sonnet-20240229-v1:0`],
label: "Anthropic - Claude 3 Sonnet V1",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.anthropicClaude3SonnetV1 = anthropicClaude3SonnetV1;
exports.anthropicClaude21V1 = (0, model_1.modelRef)({
name: "aws-bedrock/anthropic.claude-v2:1",
info: {
versions: ["anthropic.claude-v2:1"],
label: "Anthropic - Claude 2.1 V1",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.anthropicClaude2V1 = (0, model_1.modelRef)({
name: "aws-bedrock/anthropic.claude-v2",
info: {
versions: ["anthropic.claude-v2"],
label: "Anthropic - Claude 2 V1",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.anthropicClaudeInstantV1 = (0, model_1.modelRef)({
name: "aws-bedrock/anthropic.claude-instant-v1",
info: {
versions: ["anthropic.claude-instant-v1"],
label: "Anthropic - Claude Instant V1",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.mistralLarge2402V1 = (0, model_1.modelRef)({
name: "aws-bedrock/mistral.mistral-large-2402-v1:0",
info: {
versions: ["mistral.mistral-large-2402-v1:0"],
label: "Mistral - Large (24.02)",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.mistralSmall2402V1 = (0, model_1.modelRef)({
name: "aws-bedrock/mistral.mistral-small-2402-v1:0",
info: {
versions: ["mistral.mistral-small-2402-v1:0"],
label: "Mistral - Small (24.02)",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.mistral7BInstructV02 = (0, model_1.modelRef)({
name: "aws-bedrock/mistral.mistral-7b-instruct-v0:2",
info: {
versions: ["mistral.mistral-7b-instruct-v0:2"],
label: "Mistral - 7B Instruct",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.mistral8x7BInstructV01 = (0, model_1.modelRef)({
name: "aws-bedrock/mistral.mixtral-8x7b-instruct-v0:1",
info: {
versions: ["mistral.mixtral-8x7b-instruct-v0:1"],
label: "Mistral - 8x7B Instruct",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.ai21Jamba15LargeV1 = (0, model_1.modelRef)({
name: "aws-bedrock/ai21.jamba-1-5-large-v1:0",
info: {
versions: ["ai21.jamba-1-5-large-v1:0"],
label: "AI21 - Jambda 1.5 Large",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.ai21Jamba15MiniV1 = (0, model_1.modelRef)({
name: "aws-bedrock/ai21.jamba-1-5-mini-v1:0",
info: {
versions: ["ai21.jamba-1-5-mini-v1:0"],
label: "AI21 - Jambda 1.5 Mini",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.ai21JambaInstructV1 = (0, model_1.modelRef)({
name: "aws-bedrock/ai21.jamba-instruct-v1:0",
info: {
versions: ["ai21.jamba-instruct-v1:0"],
label: "AI21 - Jambda Instruct",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.ai21Jurassic2MidV1 = (0, model_1.modelRef)({
name: "aws-bedrock/ai21.j2-mid-v1",
info: {
versions: ["ai21.j2-mid-v1"],
label: "AI21 - Jurassic-2 Mid",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.ai21Jurassic2UltraV1 = (0, model_1.modelRef)({
name: "aws-bedrock/ai21.j2-ultra-v1",
info: {
versions: ["ai21.j2-ultra-v1"],
label: "AI21 - Jurassic-2 Ultra",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: false,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
const metaLlama3370BInstruct = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.meta.llama3-3-70b-instruct-v1:0`,
info: {
versions: [`${inferenceRegion}.meta.llama3-3-70b-instruct-v1:0`],
label: "Meta - Llama 3.3 70b Instruct",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.metaLlama3370BInstruct = metaLlama3370BInstruct;
const metaLlama3211BInstruct = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.meta.llama3-2-11b-instruct-v1:0`,
info: {
versions: [`${inferenceRegion}.meta.llama3-2-11b-instruct-v1:0`],
label: "Meta - Llama 3.2 11b Instruct",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.metaLlama3211BInstruct = metaLlama3211BInstruct;
const metaLlama321BInstruct = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.meta.llama3-2-1b-instruct-v1:0`,
info: {
versions: [`${inferenceRegion}.meta.llama3-2-1b-instruct-v1:0`],
label: "Meta - Llama 3.2 1b Instruct",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.metaLlama321BInstruct = metaLlama321BInstruct;
const metaLlama323BInstruct = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.meta.llama3-2-3b-instruct-v1:0`,
info: {
versions: [`${inferenceRegion}.meta.llama3-2-3b-instruct-v1:0`],
label: "Meta - Llama 3.2 3b Instruct",
supports: {
multiturn: true,
tools: false,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.metaLlama323BInstruct = metaLlama323BInstruct;
const metaLlama3290BInstruct = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.meta.llama3-2-90b-instruct-v1:0`,
info: {
versions: [`${inferenceRegion}.meta.llama3-2-90b-instruct-v1:0`],
label: "Meta - Llama 3.2 90b Instruct",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.metaLlama3290BInstruct = metaLlama3290BInstruct;
const metaLlama3170BInstruct = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.meta.llama3-1-70b-instruct-v1:0`,
info: {
versions: [`${inferenceRegion}.meta.llama3-1-70b-instruct-v1:0`],
label: "Meta - Llama 3.1 70b Instruct",
supports: {
multiturn: true,
tools: false,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.metaLlama3170BInstruct = metaLlama3170BInstruct;
const metaLlama318BInstruct = (inferenceRegion = "us") => {
return (0, model_1.modelRef)({
name: `aws-bedrock/${inferenceRegion}.meta.llama3-1-8b-instruct-v1:0`,
info: {
versions: [`${inferenceRegion}.meta.llama3-1-8b-instruct-v1:0`],
label: "Meta - Llama 3.1 8b Instruct",
supports: {
multiturn: true,
tools: true,
media: true,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
};
exports.metaLlama318BInstruct = metaLlama318BInstruct;
exports.metaLlama370BInstruct = (0, model_1.modelRef)({
name: "aws-bedrock/meta.llama3-70b-instruct-v1:0",
info: {
versions: ["meta.llama3-70b-instruct-v1:0"],
label: "Meta - Llama 3 70b Instruct",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
exports.metaLlama38BInstruct = (0, model_1.modelRef)({
name: "aws-bedrock/meta.llama3-8b-instruct-v1:0",
info: {
versions: ["meta.llama3-8b-instruct-v1:0"],
label: "Meta - Llama 3 8b Instruct",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: genkit_1.GenerationCommonConfigSchema,
});
const SUPPORTED_AWS_BEDROCK_MODELS = (inferenceRegion = "us") => {
return {
"amazon.nova-pro-v1:0": exports.amazonNovaProV1,
"amazon.nova-lite-v1:0": exports.amazonNovaLiteV1,
"amazon.nova-micro-v1:0": exports.amazonNovaMicroV1,
"amazon.titan-text-premier-v1:0": exports.amazonTitanTextG1PremierV1,
"amazon.titan-text-express-v1": exports.amazonTitanTextG1ExpressV1,
"amazon.titan-text-lite-v1": exports.amazonTitanTextG1LiteV1,
"cohere.command-r-v1:0": exports.cohereCommandRV1,
"cohere.command-r-plus-v1:0": exports.cohereCommandRPlusV1,
"cohere.command-light-text-v14": exports.cohereCommandLightV14,
"cohere.command-text-v14": exports.cohereCommandV14,
"mistral.mistral-large-2402-v1:0": exports.mistralLarge2402V1,
"mistral.mistral-small-2402-v1:0": exports.mistralSmall2402V1,
"mistral.mistral-7b-instruct-v0:2": exports.mistral7BInstructV02,
"mistral.mixtral-8x7b-instruct-v0:1": exports.mistral8x7BInstructV01,
"ai21.jamba-1-5-large-v1:0": exports.ai21Jamba15LargeV1,
"ai21.jamba-1-5-mini-v1:0": exports.ai21Jamba15MiniV1,
"ai21.jamba-instruct-v1:0": exports.ai21JambaInstructV1,
"ai21.j2-mid-v1": exports.ai21Jurassic2MidV1,
"ai21.j2-ultra-v1": exports.ai21Jurassic2UltraV1,
[`${inferenceRegion}.meta.llama3-3-70b-instruct-v1:0`]: (0, exports.metaLlama3370BInstruct)(inferenceRegion),
[`${inferenceRegion}.meta.llama3-2-11b-instruct-v1:0`]: (0, exports.metaLlama3211BInstruct)(inferenceRegion),
[`${inferenceRegion}.meta.llama3-2-1b-instruct-v1:0`]: (0, exports.metaLlama321BInstruct)(inferenceRegion),
[`${inferenceRegion}.meta.llama3-2-3b-instruct-v1:0`]: (0, exports.metaLlama323BInstruct)(inferenceRegion),
[`${inferenceRegion}.meta.llama3-2-90b-instruct-v1:0`]: (0, exports.metaLlama3290BInstruct)(inferenceRegion),
[`${inferenceRegion}.meta.llama3-1-70b-instruct-v1:0`]: (0, exports.metaLlama3170BInstruct)(inferenceRegion),
[`${inferenceRegion}.meta.llama3-1-8b-instruct-v1:0`]: (0, exports.metaLlama318BInstruct)(inferenceRegion),
"meta.llama3-70b-instruct-v1:0": exports.metaLlama370BInstruct,
"meta.llama3-8b-instruct-v1:0": exports.metaLlama38BInstruct,
"anthropic.claude-v2:1": exports.anthropicClaude21V1,
"anthropic.claude-v2": exports.anthropicClaude2V1,
"anthropic.claude-instant-v1": exports.anthropicClaudeInstantV1,
[`${inferenceRegion}.anthropic.claude-3-5-haiku-20241022-v1:0`]: (0, exports.anthropicClaude35HaikuV1)(inferenceRegion),
[`${inferenceRegion}.anthropic.claude-3-7-sonnet-20250219-v1:0`]: (0, exports.anthropicClaude37SonnetV1)(inferenceRegion),
[`${inferenceRegion}.anthropic.claude-3-5-sonnet-20241022-v2:0`]: (0, exports.anthropicClaude35SonnetV2)(inferenceRegion),
[`${inferenceRegion}.anthropic.claude-3-5-sonnet-20240620-v1:0`]: (0, exports.anthropicClaude35SonnetV1)(inferenceRegion),
[`${inferenceRegion}.anthropic.claude-3-opus-20240229-v1:0`]: (0, exports.anthropicClaude3OpusV1)(inferenceRegion),
[`${inferenceRegion}.anthropic.claude-3-haiku-20240307-v1:0`]: (0, exports.anthropicClaude3HaikuV1)(inferenceRegion),
[`${inferenceRegion}.anthropic.claude-3-sonnet-20240229-v1:0`]: (0, exports.anthropicClaude3SonnetV1)(inferenceRegion),
};
};
exports.SUPPORTED_AWS_BEDROCK_MODELS = SUPPORTED_AWS_BEDROCK_MODELS;
function toAwsBedrockbRole(role) {
switch (role) {
case "user":
return "user";
case "model":
return "assistant";
case "system":
return "system";
case "tool":
return "tool";
default:
throw new Error(`role ${role} doesn't map to an AWS Bedrock role.`);
}
}
function toAwsBedrockTool(tool) {
return {
toolSpec: {
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema ? { json: tool.inputSchema } : undefined,
},
};
}
const regex = /data:.*base64,/;
const getDataPart = (dataUrl) => dataUrl.replace(regex, "");
function toAwsBedrockTextAndMedia(part, imageFormat) {
if (part.text) {
return {
text: part.text,
};
}
else if (part.media) {
const imageBuffer = new Uint8Array(Buffer.from(getDataPart(part.media.url), "base64"));
return {
image: {
source: { bytes: imageBuffer },
format: imageFormat,
},
};
}
throw Error(`Unsupported genkit part fields encountered for current message role: ${part}.`);
}
function getSystemMessage(messages) {
for (const message of messages) {
if (message.role === "system") {
return [
{
text: message.content[0].text,
},
];
}
}
return null;
}
function toAwsBedrockMessages(messages, imageFormat = "png") {
const awsBedrockMsgs = [];
for (const message of messages) {
const msg = new genkit_1.Message(message);
const role = toAwsBedrockbRole(message.role);
switch (role) {
case "system": {
break;
}
case "user": {
const textAndMedia = msg.content.map((part) => toAwsBedrockTextAndMedia(part, imageFormat));
if (textAndMedia.length > 1) {
awsBedrockMsgs.push({
role: role,
content: textAndMedia,
});
}
else {
awsBedrockMsgs.push({
role: role,
content: [
{
text: msg.text,
},
],
});
}
break;
}
case "assistant": {
// Request to call the tool
const toolCalls = msg.content
.filter((part) => part.toolRequest)
.map((part) => {
if (!part.toolRequest) {
throw Error("Mapping genkit message to openai tool call content part but message.toolRequest not provided.");
}
return {
toolUseId: part.toolRequest.ref || "",
name: part.toolRequest.name,
input: part.toolRequest.input,
};
});
if ((toolCalls === null || toolCalls === void 0 ? void 0 : toolCalls.length) > 0) {
awsBedrockMsgs.push({
role: role,
content: toolCalls.map((toolCall) => ({ toolUse: toolCall })),
});
}
else {
awsBedrockMsgs.push({
role: role,
content: [
{
text: msg.text,
},
],
});
}
break;
}
case "tool": {
// result of the tool
const toolResponseParts = msg.toolResponseParts();
toolResponseParts.map((part) => {
const toolresult = {
role: "user",
content: [
{
toolResult: {
toolUseId: part.toolResponse.ref,
content: [
{
json: {
result: part.toolResponse.output,
},
},
],
},
},
],
};
awsBedrockMsgs.push(toolresult);
});
break;
}
default:
throw new Error("unrecognized role");
}
}
return awsBedrockMsgs;
}
const finishReasonMap = {
max_tokens: "length",
end_turn: "stop",
stop_sequence: "stop",
tool_use: "stop",
content_filtered: "blocked",
guardrail_intervened: "blocked",
};
function fromAwsBedrockToolCall(toolCall) {
if (!("toolUseId" in toolCall)) {
throw Error(`Unexpected AWS chunk choice. tool_calls was provided but one or more tool_calls is missing.`);
}
const f = toolCall;
return [
{
toolRequest: {
name: f.name,
ref: toolCall.toolUseId,
input: f.input,
},
},
];
}
function fromAwsBedrockChoice(choice, jsonMode = false) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
const toolRequestParts = ((_b = (_a = choice.output) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.content) && choice.output.message.content[0].toolUse
? fromAwsBedrockToolCall(choice.output.message.content[0].toolUse)
: [];
return {
finishReason: "stopReason" in choice ? finishReasonMap[choice.stopReason] : "other",
message: {
role: "model",
content: Array.isArray(toolRequestParts) && toolRequestParts.length > 0
? toolRequestParts
: [
jsonMode
? {
data: ((_f = (_e = (_d = (_c = choice.output) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.text)
? JSON.parse((_j = (_h = (_g = choice.output.message.content) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.text) !== null && _j !== void 0 ? _j : "{}")
: {},
}
: { text: ((_o = (_m = (_l = (_k = choice.output) === null || _k === void 0 ? void 0 : _k.message) === null || _l === void 0 ? void 0 : _l.content) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.text) || "" },
],
},
custom: {},
};
}
function fromAwsBedrockChunkChoice(choice, finishReasonInput) {
var _a;
return {
finishReason: finishReasonInput
? finishReasonMap[finishReasonInput] || "other"
: "unknown",
message: {
role: "model",
content: [{ text: (_a = choice === null || choice === void 0 ? void 0 : choice.text) !== null && _a !== void 0 ? _a : "" }],
},
custom: {},
};
}
function toAwsBedrockRequestBody(modelName, request, inferenceRegion) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
const model = (0, exports.SUPPORTED_AWS_BEDROCK_MODELS)(inferenceRegion)[modelName];
if (!model)
throw new Error(`Unsupported model: ${modelName}`);
const awsBedrockMessages = toAwsBedrockMessages(request.messages);
const awsBedrockSystemMessage = getSystemMessage(request.messages) || [];
const jsonMode = ((_a = request.output) === null || _a === void 0 ? void 0 : _a.format) === "json" ||
((_b = request.output) === null || _b === void 0 ? void 0 : _b.contentType) === "application/json";
const textMode = ((_c = request.output) === null || _c === void 0 ? void 0 : _c.format) === "text" ||
((_d = request.output) === null || _d === void 0 ? void 0 : _d.contentType) === "plain/text";
const response_format = ((_e = request.output) === null || _e === void 0 ? void 0 : _e.format)
? (_f = request.output) === null || _f === void 0 ? void 0 : _f.format
: (_g = request.output) === null || _g === void 0 ? void 0 : _g.contentType;
if (jsonMode && ((_j = (_h = model.info.supports) === null || _h === void 0 ? void 0 : _h.output) === null || _j === void 0 ? void 0 : _j.includes("json"))) {
awsBedrockSystemMessage === null || awsBedrockSystemMessage === void 0 ? void 0 : awsBedrockSystemMessage.push({
text: "You write JSON objects based on the given instructions. Please generate only the JSON output. DO NOT provide any preamble.",
});
}
else if ((textMode && ((_l = (_k = model.info.supports) === null || _k === void 0 ? void 0 : _k.output) === null || _l === void 0 ? void 0 : _l.includes("text"))) ||
((_o = (_m = model.info.supports) === null || _m === void 0 ? void 0 : _m.output) === null || _o === void 0 ? void 0 : _o.includes("text"))) {
awsBedrockSystemMessage === null || awsBedrockSystemMessage === void 0 ? void 0 : awsBedrockSystemMessage.push({
text: "You write objects in plain text. DO NOT provide any preamble.",
});
}
else {
throw new Error(`${response_format} format is not supported for GPT models currently`);
}
const modelString = (((_p = request.config) === null || _p === void 0 ? void 0 : _p.version) ||
model.version ||
modelName);
const body = {
messages: awsBedrockMessages,
system: model.info.supports.systemRole === true
? awsBedrockSystemMessage
: [],
toolConfig: request.tools &&
model.info.supports.tools === true &&
request.tools.length > 0
? { tools: request.tools.map(toAwsBedrockTool) }
: undefined,
modelId: modelString,
inferenceConfig: {
maxTokens: (_q = request.config) === null || _q === void 0 ? void 0 : _q.maxOutputTokens,
temperature: (_r = request.config) === null || _r === void 0 ? void 0 : _r.temperature,
topP: (_s = request.config) === null || _s === void 0 ? void 0 : _s.topP,
//n: request.candidates,
stopSequences: (_t = request.config) === null || _t === void 0 ? void 0 : _t.stopSequences,
},
};
return body;
}
function awsBedrockModel(name, client, ai, inferenceRegion) {
const modelId = `aws-bedrock/${name}`;
const model = (0, exports.SUPPORTED_AWS_BEDROCK_MODELS)(inferenceRegion)[name];
if (!model)
throw new Error(`Unsupported model: ${name}`);
return ai.defineModel(Object.assign(Object.assign({ name: modelId }, model.info), { configSchema: (0, exports.SUPPORTED_AWS_BEDROCK_MODELS)(inferenceRegion)[name].configSchema }), (request, streamingCallback) => __awaiter(this, void 0, void 0, function* () {
var _a, e_1, _b, _c;
var _d, _e, _f, _g;
let response;
const body = toAwsBedrockRequestBody(name, request, inferenceRegion);
if (streamingCallback) {
const command = new client_bedrock_runtime_1.ConverseStreamCommand(body);
response = yield client.send(command);
try {
for (var _h = true, _j = __asyncValues(response.stream), _k; _k = yield _j.next(), _a = _k.done, !_a; _h = true) {
_c = _k.value;
_h = false;
const event = _c;
let finishReason;
if (event.messageStop) {
finishReason = event.messageStop.stopReason;
const c = fromAwsBedrockChunkChoice(undefined, finishReason);
streamingCallback({
index: 0,
content: [Object.assign(Object.assign({}, c), { custom: c.custom })],
});
}
if (event.contentBlockDelta) {
const delta = event.contentBlockDelta.delta;
const c = fromAwsBedrockChunkChoice(delta, finishReason);
streamingCallback({
index: 0,
content: [Object.assign(Object.assign({}, c), { custom: c.custom })],
});
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_h && !_a && (_b = _j.return)) yield _b.call(_j);
}
finally { if (e_1) throw e_1.error; }
}
}
else {
const command = new client_bedrock_runtime_1.ConverseCommand(body);
response = yield client.send(command);
}
return {
message: "output" in response
? fromAwsBedrockChoice(response, ((_d = request.output) === null || _d === void 0 ? void 0 : _d.format) === "json")
.message
: { role: "model", content: [] },
usage: {
inputTokens: "usage" in response ? (_e = response.usage) === null || _e === void 0 ? void 0 : _e.inputTokens : 0,
outputTokens: "usage" in response ? (_f = response.usage) === null || _f === void 0 ? void 0 : _f.outputTokens : 0,
totalTokens: "usage" in response ? (_g = response.usage) === null || _g === void 0 ? void 0 : _g.totalTokens : 0,
},
custom: response,
};
}));
}
//# sourceMappingURL=aws_bedrock_llms.js.map