Function Calling Using Amazon Bedrock Anthropic Claude 3 banner
aws-samples aws-samples

Function Calling Using Amazon Bedrock Anthropic Claude 3

AI community

Description

Function calling using Amazon Bedrock with Anthropic Claude 3 foundation model

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

Function calling using Amazon Bedrock with Anthropic Claude 3

Amazon Bedrock is a fully managed service that offers a choice of high-performing foundation models from leading AI companies and a set of capabilities to build generative AI applications.

This sample repo provide an example for using function calling using the [Converse API](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/converse.html) with [Anthropic Claude 3 Sonnet](https://aws.amazon.com/about-aws/whats-new/2024/03/anthropics-claude-3-sonnet-model-amazon-bedrock/), using multiple tools. This repo is a sample only code, that demonstrate how to use function calling as tools for a model to use to fetch results using plain function code.

The `Converse` API provides a consistent interface that works with all models that support messages. This allows you to write code once and use it with different models. Should a model have unique inference parameters, you can also pass those unique parameters to the model.

Overview

Function calling (also known as tools), is a way to provide the model, with a descriptive guidance for a function that is available to the model to use for answering the user input.

In this sample, we will ask a Claude 3 to answer, what is a stock ticker value, and with option to convert the default ticker currency to any currency that was provided in the user input.

Tools

There are 2 tools available to the models to use:

  • get_stock_price - given a ticker string, the open source library yfinance will get the current stock value, and currency that its being traded.
  • convert_currency - given an amount, source and target currency, the open source library CurrencyConverter will convert the amount given from source currency to target currency.

The model each turn will review the prompt given, will decide if it can answer properly the question p