最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

typescript - Sending an attachment to Claude in AWS Bedrock - Stack Overflow

programmeradmin2浏览0评论

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.

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?

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.

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?

Share Improve this question asked Feb 7 at 21:20 lpetruccilpetrucci 1,6796 gold badges29 silver badges49 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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

发布评论

评论列表(0)

  1. 暂无评论