Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions BedrockPromptCachingRoutingDemo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual environments
venv/
env/
ENV/
.venv/
.env/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# AWS
.aws/
*.pem

# Logs
*.log
logs/

# Temporary files
*.tmp
*.temp

# Jupyter Notebook
.ipynb_checkpoints

# Streamlit
.streamlit/

# Benchmark results
benchmark_results_*.csv
benchmark_plot_*.png
21 changes: 21 additions & 0 deletions BedrockPromptCachingRoutingDemo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Amazon Bedrock Workshop

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
129 changes: 129 additions & 0 deletions BedrockPromptCachingRoutingDemo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Amazon Bedrock Prompt Caching and Routing Workshop

This repository contains a complete implementation of Amazon Bedrock's prompt caching and routing capabilities using the latest Claude 4.5 models.

## Features

- **Prompt Caching**: Reduce latency and costs by caching frequently used prompts
- **Prompt Routing**: Intelligently route requests to optimal models
- **Latest Models**: Updated to use Claude Haiku 4.5, Sonnet 4.5, and Opus 4.1
- **Global Endpoints**: Compatible across all AWS regions
- **Multiple Interfaces**: Both CLI and Streamlit web applications

## Project Structure

```
BedrockPromptDemo/
├── src/
│ ├── bedrock_prompt_caching.py # CLI application for prompt caching
│ ├── bedrock_prompt_routing.py # CLI application for prompt routing
│ ├── prompt_caching_app.py # Streamlit UI for prompt caching
│ ├── prompt_router_app.py # Streamlit UI for prompt routing
│ ├── model_manager.py # Model selection and management
│ ├── bedrock_service.py # Bedrock API service wrapper
│ └── file_processor.py # File processing utilities
├── requirements.txt # Python dependencies
└── README.md # This file
```

## Latest Models Supported

- **Claude Haiku 4.5**: `anthropic.claude-haiku-4-5-20251001-v1:0`
- **Claude Sonnet 4.5**: `anthropic.claude-sonnet-4-5-20250929-v1:0`
- **Claude Opus 4.1**: `anthropic.claude-opus-4-1-20250805-v1:0`
- **Amazon Nova Models**: `amazon.nova-micro-v1:0`, `amazon.nova-lite-v1:0`, `amazon.nova-pro-v1:0`

## Prerequisites

- AWS CLI configured with appropriate credentials
- Python 3.8+
- Access to Amazon Bedrock with Claude models enabled

## Installation

1. Clone this repository:
```bash
git clone <your-repo-url>
cd BedrockPromptDemo
```

2. Install dependencies:
```bash
pip install -r requirements.txt
```

3. Configure AWS credentials:
```bash
aws configure
```

## Usage

### CLI Applications

**Prompt Caching:**
```bash
cd src
python bedrock_prompt_caching.py
```

**Prompt Routing:**
```bash
cd src
python bedrock_prompt_routing.py
```

### Web Applications

**Prompt Caching UI:**
```bash
cd src
streamlit run prompt_caching_app.py
```

**Prompt Routing UI:**
```bash
cd src
streamlit run prompt_router_app.py
```

## Key Features

### Prompt Caching
- Automatically caches document context for faster subsequent queries
- Shows cache hit/miss statistics
- Demonstrates cost and latency benefits
- Supports multi-turn conversations

### Prompt Routing
- Intelligently routes requests to optimal models
- Displays routing decisions and model selection
- Tracks usage statistics across different models
- Supports file uploads (PDF, DOCX, TXT)

### Model Management
- Dynamic model selection from available Bedrock models
- Inference profile resolution for optimal performance
- Fallback model configuration
- Global endpoint support for multi-region compatibility

## Configuration

The applications use global model endpoints by default, making them compatible across all AWS regions. Models are automatically resolved to regional endpoints by Bedrock's routing service.

## Workshop Learning Objectives

This code demonstrates:
1. How to implement prompt caching to reduce costs and latency
2. How to use prompt routing for intelligent model selection
3. Best practices for Bedrock API integration
4. Performance monitoring and usage tracking
5. Multi-modal file processing capabilities

## Contributing

Feel free to submit issues and enhancement requests!

## License

This project is licensed under the MIT License - see the LICENSE file for details.
Loading