Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(community): Support AWS Bedrock invoke model #7810

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AllenFang
Copy link
Contributor

Context

In short, AWS Bedrock not only support Converse but also Invoke model which is suitable for single-turn inference, content generation tasks, embeddings. This MR is inspired from #7697 discussion. Today AWS supports the cache point but Converse hasn't support yet from aws SDK but Invoke Model supported.

About PR

This is first draft for supporting AWS Bedrock Invoke Model and I want to let team and @jacoblee93 to decide whether we should continue to support this feature. If no, feel free to close. If true, I will then add some testing codes, code comments and prepare document.

Notes

  • this PR doesn't support streaming, i want streaming to be supported in next time for minimizing the code changes and review efforts
  • cache checkpoints will be implemented in this PR once team decide to support Invoke Model in langchain.

Let me know your thoughts. Thx 🙏 🙏

Local Testing

  • Basic Message
    Request:
const model = new ChatBedrockInvokeModel({
    region: "us-east-1",
    model: "anthropic.claude-3-5-sonnet-20240620-v1:0",
    credentials: {
      accessKeyId: "...",
      secretAccessKey: "...",
    },
});

const response = await model.invoke([
 [new HumanMessage("Hello, how are you?")]
], {
  body: {
      max_tokens: 120,
      anthropic_version: "bedrock-2023-05-31"
      // temperature: 0.5,
      // top_p: 2,
      // stop_sequences: [],
      // ... others
    },
});

Response:

AIMessage {
  "id": "msg_bdrk_01Ci5ueXLCNPduGzbYUyJGkR",
  "content": "Hello! As an AI language model, I don't have feelings or emotions, but I'm functioning properly and ready to assist you with any questions or tasks you may have. How can I help you today?",
  "additional_kwargs": {},
  "response_metadata": {
    "$metadata": {
      "httpStatusCode": 200,
      "requestId": "7497471b-664c-43c5-b374-083603ead322",
      "attempts": 1,
      "totalRetryDelay": 0
    },
    "contentType": "application/json",
    "type": "message",
    "model": "claude-3-haiku-20240307",
    "stop_reason": "end_turn",
    "stop_sequence": null
  },
  "tool_calls": [],
  "invalid_tool_calls": [],
  "usage_metadata": {
    "input_tokens": 13,
    "output_tokens": 45,
    "total_tokens": 58
  }
}
  • With tool
    Request:
const model = new ChatBedrockInvokeModel({
    region: "us-east-1",
    model: "anthropic.claude-3-5-sonnet-20240620-v1:0",
    credentials: {
      accessKeyId: "...",
      secretAccessKey: "....",
    },
});

const response = await model.invoke([
 [new HumanMessage("Hello, how are you?")]
], {
  body: {
      max_tokens: 120,
      anthropic_version: "bedrock-2023-05-31"
      // temperature: 0.5,
      // top_p: 2,
      // stop_sequences: [],
      // ... others
    },
    tools: [....]
});

Response:

AIMessage {
  "id": "msg_bdrk_017An62jigbN7gShHUpXHJ3x",
  "content": [
    {
      "type": "text",
      "text": "Here is the calculation:"
    }
  ],
  "additional_kwargs": {},
  "response_metadata": {
    "$metadata": {
      "httpStatusCode": 200,
      "requestId": "a9a70436-4cd2-463c-9ad9-e771cf32f804",
      "attempts": 1,
      "totalRetryDelay": 0
    },
    "contentType": "application/json",
    "type": "message",
    "model": "claude-3-haiku-20240307",
    "stop_reason": "tool_use",
    "stop_sequence": null
  },
  "tool_calls": [
    {
      "id": "toolu_bdrk_01DiDiMN2WVzpeab5x9FPueb",
      "name": "multiply",
      "args": {
        "a": 2,
        "b": 3
      },
      "type": "tool_call"
    }
  ],
  "invalid_tool_calls": [],
  "usage_metadata": {
    "input_tokens": 372,
    "output_tokens": 68,
    "total_tokens": 440
  }
}
  • Images
  • Documents

Copy link

vercel bot commented Mar 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Mar 7, 2025 8:28am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Mar 7, 2025 8:28am

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. auto:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features labels Mar 7, 2025
@jacoblee93
Copy link
Collaborator

Hey @AllenFang, thanks for this PR!

@3coins are you all planning to gradually migrate everything over to the Converse API?

If so, I'd rather just leave the parallel implementation in community. If not, this makes sense.

@jacoblee93 jacoblee93 added the question Further information is requested label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:enhancement A large net-new component, integration, or chain. Use sparingly. The largest features question Further information is requested size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants