Skip to main content

Documentation Index

Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Amazon Bedrock Converse is a fully managed service that makes Foundation Models (FMs) from leading AI startups and Amazon available via an API. You can choose from a wide range of FMs to find the model that is best suited for your use case. It provides a unified conversational interface for Bedrock models, but does not yet have feature parity for all functionality within the older Bedrock model service. This will help you getting started with ChatBedrockConverse chat models. For detailed documentation of all ChatBedrockConverse features and configurations head to the API reference.

概述

集成详情

ClassPackageSerializablePY supportDownloadsVersion
ChatBedrockConverse@langchain/awsNPM - DownloadsNPM - Version

模型功能

请参阅下表标题中的链接,了解如何使用特定功能。

设置

要访问 Bedrock models,你需要create an AWS account, set up the Bedrock API service, get an access key ID and secret key, and install the @langchain/community integration package.

凭证

Head to the AWS docs to sign up for AWS and setup your credentials. You’ll also need to turn on model access for your account, which you can do by following these instructions. 如果你想要自动追踪模型调用,还可以设置你的 LangSmith API 密钥,取消注释以下内容:
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"

安装

LangChain 的 ChatBedrockConverse 集成位于 @langchain/aws 包中:
npm install @langchain/aws @langchain/core

实例化

Now we can instantiate our model object and generate chat completions. There are a few different ways to authenticate with AWS - the below examples rely on an access key, secret access key and region set in your environment variables:
import { ChatBedrockConverse } from "@langchain/aws";

const llm = new ChatBedrockConverse({
  model: "anthropic.claude-3-5-sonnet-20240620-v1:0",
  region: process.env.BEDROCK_AWS_REGION,
  credentials: {
    accessKeyId: process.env.BEDROCK_AWS_ACCESS_KEY_ID!,
    secretAccessKey: process.env.BEDROCK_AWS_SECRET_ACCESS_KEY!,
  },
});

调用

const aiMsg = await llm.invoke([
  [
    "system",
    "You are a helpful assistant that translates English to French. Translate the user sentence.",
  ],
  ["human", "I love programming."],
])
aiMsg
AIMessage {
  "id": "f5dc5791-224e-4fe5-ba2e-4cc51d9e7795",
  "content": "J'adore la programmation.",
  "additional_kwargs": {},
  "response_metadata": {
    "$metadata": {
      "httpStatusCode": 200,
      "requestId": "f5dc5791-224e-4fe5-ba2e-4cc51d9e7795",
      "attempts": 1,
      "totalRetryDelay": 0
    },
    "metrics": {
      "latencyMs": 584
    },
    "stopReason": "end_turn",
    "usage": {
      "inputTokens": 29,
      "outputTokens": 11,
      "totalTokens": 40
    }
  },
  "tool_calls": [],
  "invalid_tool_calls": [],
  "usage_metadata": {
    "input_tokens": 29,
    "output_tokens": 11,
    "total_tokens": 40
  }
}
console.log(aiMsg.content)
J'adore la programmation.

工具调用

Tool calling with Bedrock models works in a similar way to other models, but note that not all Bedrock models support tool calling. Please refer to the AWS model documentation for more information.

API 参考

有关所有 ChatBedrockConverse 功能和配置的详细文档,请前往 API 参考