Skip to main content

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:

  1. Clone the repository
  2. Install development dependencies:
    pip install -e ".[dev]"
    
  3. Run tests:
    pytest
    

License

MIT License - see LICENSE file for details.

Metadata

Release files for pydantic-ai-nova 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-ai-nova 0.2.0
File Size Uploaded
pydantic_ai_nova-0.2.0.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-ai-nova 0.2.0
File Interpreter ABI Platform
pydantic_ai_nova-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.8 kB

Release files / pydantic_ai_nova-0.2.0.tar.gz

Download URL pydantic_ai_nova-0.2.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
83d38fcfb2bc4b43823ef757f0b8822ec08cef94772ed4d6fec9c329653b9fba
BLAKE2b-256 checksum
How to use checksums
fd8b1e345858143af5e420ec4063ef721a203731c4d702f9fac220d4d5f6f804
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 11, 2025.

Transparency log

Release files / pydantic_ai_nova-0.2.0-py3-none-any.whl

Download URL pydantic_ai_nova-0.2.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90129f5e5f760155e2a28a09c2bec86cc972b35e51b7e29ae9486538e1f52aed
BLAKE2b-256 checksum
How to use checksums
fcd2441eb69a6ad0e2e91ffc3f22f0a94abe2750b55db9903a12aca166c0bbbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 11, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page