Skip to content

Commit

Permalink
feat: image recognition working and added some anthropic models
Browse files Browse the repository at this point in the history
  • Loading branch information
xavidop committed Dec 26, 2024
1 parent a708504 commit a761d94
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 41 additions & 1 deletion src/aws_bedrock_llms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,38 @@ export const amazonNovaProV1 = modelRef({
info: {
versions: ["amazon.nova-pro-v1:0"],
label: "Amazon - Nova Pro V1",
supports: {
multiturn: true,
tools: true,
media: false,
systemRole: true,
output: ["text", "json"],
},
},
configSchema: GenerationCommonConfigSchema,
});

export const anthropicClaude35HaikuV1 = modelRef({
name: "aws-bedrock/us.anthropic.claude-3-5-haiku-20241022-v1:0",
info: {
versions: ["us.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: GenerationCommonConfigSchema,
});

export const anthropicClaude35SonnetV1 = modelRef({
name: "aws-bedrock/us.anthropic.claude-3-5-sonnet-20241022-v2:0",
info: {
versions: ["us.anthropic.claude-3-5-sonnet-20241022-v2:0"],
label: "Anthropic - Claude 3.5 Haiku V1",
supports: {
multiturn: true,
tools: true,
Expand All @@ -68,6 +100,8 @@ export const amazonNovaProV1 = modelRef({

export const SUPPORTED_AWS_BEDROCK_MODELS: Record<string, any> = {
"amazon.nova-pro-v1:0": amazonNovaProV1,
"us.anthropic.claude-3-5-haiku-20241022-v1:0": anthropicClaude35HaikuV1,
"us.anthropic.claude-3-5-sonnet-20241022-v2:0": anthropicClaude35SonnetV1,
};

function toAwsBedrockbRole(role: Role): string {
Expand All @@ -92,6 +126,9 @@ function toAwsBedrockbRole(role: Role): string {
// input: tool.inputSchema,
// };
// }
const regex = /data:.*base64,/
const getDataPart = (dataUrl: string) => dataUrl.replace(regex,"");


export function toAwsBedrockTextAndMedia(
part: Part,
Expand All @@ -102,7 +139,7 @@ export function toAwsBedrockTextAndMedia(
text: part.text,
};
} else if (part.media) {
const imageBuffer = new Uint8Array(Buffer.from(part.media.url, "base64"));
const imageBuffer = new Uint8Array(Buffer.from(getDataPart(part.media.url), "base64"));

return {
image: {
Expand Down Expand Up @@ -140,6 +177,9 @@ export function toAwsBedrockMessages(
const msg = new Message(message);
const role = toAwsBedrockbRole(message.role);
switch (role) {
case "system": {
break;
}
case "user": {
const textAndMedia = msg.content.map((part) =>
toAwsBedrockTextAndMedia(part, imageFormat),
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import {
awsBedrockModel,
amazonNovaProV1,
anthropicClaude35HaikuV1,
anthropicClaude35SonnetV1,
SUPPORTED_AWS_BEDROCK_MODELS,
} from "./aws_bedrock_llms.js";
import {
Expand All @@ -16,7 +18,7 @@ import {
SUPPORTED_EMBEDDING_MODELS,
} from "./aws_bedrock_embedders.js";

export { amazonNovaProV1 };
export { amazonNovaProV1, anthropicClaude35HaikuV1, anthropicClaude35SonnetV1 };

export { amazonTitanEmbedTextV2 };

Expand Down

0 comments on commit a761d94

Please sign in to comment.