Amazon Bedrock Nova model integration for pydantic-ai
Project description
pydantic-ai-nova
Amazon Bedrock Nova model integration for pydantic-ai.
Installation
pip install pydantic-ai-nova
Requirements
- Python 3.8 or higher
- pydantic-ai
- boto3
- AWS credentials configured with access to Amazon Bedrock
Usage
from pydantic_ai_nova import AmazonNovaModel
from pydantic_ai import Agent, RunContext
from pydantic import BaseModel
# Define system prompts for better function calling
SYSTEM_PROMPTS = [
{"text": "You are an AI assistant that helps users with their requests."},
{"text": "Model Instructions:"},
{"text": "- Do not assume any information. All required parameters for actions must come from the User."},
{"text": "- If you are going to use a tool you should always generate a Thought within <thinking></thinking> tags before you invoke a function."},
{"text": "- You have access to a weather function that can provide current weather information."},
{"text": "- When users ask about weather, use the get_weather function instead of suggesting websites."}
]
# Define your function parameters
class WeatherParams(BaseModel):
city: str
def get_weather(ctx: RunContext[WeatherParams]) -> str:
"""Get current weather for a city"""
weather_data = {
"tokyo": {
"temp": 12,
"condition": "Partly Cloudy",
"humidity": 70
}
}
city = ctx.params.city.lower()
if city in weather_data:
data = weather_data[city]
return (
f"Current weather in {city.title()}:\n"
f"Temperature: {data['temp']}°C\n"
f"Condition: {data['condition']}\n"
f"Humidity: {data['humidity']}%"
)
return f"Sorry, weather data for {city} is not available."
# Initialize the model
model = AmazonNovaModel(
model_id='amazon.nova-micro-v1:0', # or your preferred Nova model
region_name='us-east-1', # your AWS region
system_prompts=SYSTEM_PROMPTS # customize model behavior
)
# Create an agent
agent = Agent(model=model)
# Register your function
agent._register_function(
get_weather,
WeatherParams,
retries=3,
prepare=None
)
# Run a simple query
response = agent.run_sync("How are you?")
print(response.data)
# Use function calling
response = agent.run_sync("What's the weather in Tokyo?")
print(response.data)
# Ask follow-up questions
response = agent.run_sync("Is it cold there?")
print(response.data)
Features
- Full integration with pydantic-ai's Agent framework
- Support for both streaming and non-streaming responses
- Function calling support
- Token usage tracking
- AWS authentication handling through boto3
Configuration
The package uses boto3 for AWS authentication. Make sure you have your AWS credentials configured either through:
- Environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY) - AWS credentials file (
~/.aws/credentials) - IAM role when running on AWS services
Development
To contribute to this project:
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]"
- Run tests:
pytest
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ai_nova-0.2.0.tar.gz.
File metadata
- Download URL: pydantic_ai_nova-0.2.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83d38fcfb2bc4b43823ef757f0b8822ec08cef94772ed4d6fec9c329653b9fba
|
|
| MD5 |
d57b74a989a8f397eb94c2bcf67e437d
|
|
| BLAKE2b-256 |
fd8b1e345858143af5e420ec4063ef721a203731c4d702f9fac220d4d5f6f804
|
Provenance
The following attestation bundles were made for pydantic_ai_nova-0.2.0.tar.gz:
Publisher:
workflow.yml on speetchai/speetchai-pydantic-ai-nova
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ai_nova-0.2.0.tar.gz -
Subject digest:
83d38fcfb2bc4b43823ef757f0b8822ec08cef94772ed4d6fec9c329653b9fba - Sigstore transparency entry: 161712187
- Sigstore integration time:
-
Permalink:
speetchai/speetchai-pydantic-ai-nova@a04aa223a1d7a534a00c41b645a6e718e6f43105 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/speetchai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a04aa223a1d7a534a00c41b645a6e718e6f43105 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pydantic_ai_nova-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_nova-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90129f5e5f760155e2a28a09c2bec86cc972b35e51b7e29ae9486538e1f52aed
|
|
| MD5 |
63fa84ccb1d72af29fd61b046daa1453
|
|
| BLAKE2b-256 |
fcd2441eb69a6ad0e2e91ffc3f22f0a94abe2750b55db9903a12aca166c0bbbd
|
Provenance
The following attestation bundles were made for pydantic_ai_nova-0.2.0-py3-none-any.whl:
Publisher:
workflow.yml on speetchai/speetchai-pydantic-ai-nova
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydantic_ai_nova-0.2.0-py3-none-any.whl -
Subject digest:
90129f5e5f760155e2a28a09c2bec86cc972b35e51b7e29ae9486538e1f52aed - Sigstore transparency entry: 161712189
- Sigstore integration time:
-
Permalink:
speetchai/speetchai-pydantic-ai-nova@a04aa223a1d7a534a00c41b645a6e718e6f43105 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/speetchai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@a04aa223a1d7a534a00c41b645a6e718e6f43105 -
Trigger Event:
workflow_dispatch
-
Statement type: