typescriptamazon-web-serviceslarge-language-modelamazon-bedrock

Sending an attachment to Claude in AWS Bedrock


I've tested my prompt out in the AWS Bedrock Chat interface and I'm happy with it, so I'm now trying to convert it into code.

The issue is that I cannot understand how to attach a txt document to my request.

enter image description here

I've clicked on the paperclip icon to add a file to my prompt. The file was then added to my textbox.

How does this look when using the @aws-sdk/client-bedrock-runtime package?

So far I have:

const client = new BedrockRuntimeClient({
  region: "us-east-1",
});

const data = await client.send(
  new InvokeModelCommand({
    modelId: "anthropic.claude-3-5-sonnet-20240620-v1:0",
    contentType: "application/json",
    accept: "application/json",
    body: JSON.stringify({
      anthropic_version: "bedrock-2023-05-31",
      max_tokens: 10000,
      temperature: 1.0,
      messages: [
        {
          role: "user",
          content: "My prompt",
        },
      ],
    }),
  })
);

I've tried adding my file contents as a message, but the output was completely different from what I get in the Bedrock interface.

I've looked at docs, I've asked various LLMs... Nothing.

Help?


Solution

  • Based on Anthropic API reference, it seems that the body.messages[].content[].type supports only

    1. image or
    2. text

    For example, for images, load the image as base64 string. For .txt, I can only assume then you need to load the file content and just pass it as a text type.

    Reference: https://docs.anthropic.com/en/api/messages#body-messages-content