bedrock tools
1.0.0
一個小型 Python 函式庫,可簡化 Amazon Bedrock Converse API 函式呼叫(即工具使用)。
該程式庫減少了將本機 Python 函數與 Amazon Bedrock Converse API 整合所需的樣板程式碼,從而更輕鬆地創建功能強大、工具增強的對話式 AI 應用程式。
pip install bedrock-tools
from bedrock_tools import BedrockTools
# define native functions as tools (using type annotations)
def add_numbers ( a : int , b : int ) -> int :
"""Add two numbers together."""
return a + b
def greet ( name : str ) -> str :
"""Greet a person by name."""
return f"Hello, { name } !"
def get_weather ( city : str , state : str ) -> dict :
"""Get the weather for a location."""
return {
"city" : city ,
"state" : state ,
"temperature" : "75°F" ,
"condition" : "Partly Cloudy" ,
}
# setup
tools = BedrockTools ()
tools . add_function ( add_numbers )
tools . add_function ( greet )
tools . add_function ( get_weather )
# Use the config in your Bedrock Converse API call
response = bedrock . converse (
modelId = model_id ,
toolConfig = tools . get_tool_config ()
messages = messages ,
)
# When you receive a toolUse from the API, invoke the tool
if "toolUse" in content_block :
tool_results . append ( tools . invoke ( content_block [ "toolUse" ]))
message = { "role" : "user" , "content" : tool_results }
下面是一個包含和不包含該程式庫的範例(來自 Bedrock Converse API 文件):
目前支援的函數參數類型:
Choose a make command to run
init run this once to initialize a new python project
install install project dependencies
start run local project
test run unit tests