-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add AWS Bedrock tutorial to the example (#1350)
* docs: clarify the API key message Adding AWS Bedrock example script * docs: clarify the API key message
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Example of using PandasAI with a Dataframe and Amazon Bedrock.""" | ||
|
||
import pandas as pd | ||
from pandasai import Agent | ||
from pandasai.llm import BedrockClaude | ||
import boto3 | ||
|
||
# Configure the AWS account credential files : https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html | ||
|
||
region = "us-east-1" | ||
bedrock_runtime_client = boto3.client("bedrock-runtime", region_name=region) | ||
|
||
df = pd.DataFrame( | ||
{ | ||
"country": [ | ||
"United States", | ||
"United Kingdom", | ||
"France", | ||
"Germany", | ||
"Italy", | ||
"Spain", | ||
"Canada", | ||
"Australia", | ||
"Japan", | ||
"China", | ||
], | ||
"sales": [5000, 3200, 2900, 4100, 2300, 2100, 2500, 2600, 4500, 7000], | ||
} | ||
) | ||
|
||
# To check supported models : https://github.com/dimwael/pandas-ai/blob/main/pandasai/llm/bedrock_claude.py | ||
model_id = "anthropic.claude-3-haiku-20240307-v1:0" | ||
|
||
llm = BedrockClaude(model=model_id, bedrock_runtime_client=bedrock_runtime_client) | ||
|
||
agent = Agent(df, config={"llm": llm}) | ||
response = agent.chat("What is the sum of sales for Us and UK ") | ||
print(response) | ||
# 8200 |