You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See the [Quick Start for SageMaker](#-quick-start-sagemaker-endpoints) section below for a complete example.
94
+
95
+
53
96
## 🏁 Quick Start
54
97
### Facility Support Analyzer Dataset
55
98
The Facility Support Analyzer dataset consists of emails that are to be classified based on category, urgency and sentiment.
56
99
57
100
Please see the [samples](samples/facility-support-analyzer/) folder for example notebooks of how to optimize a prompt in the scenario where a [user prompt template is to be optimized](samples/facility-support-analyzer/user_prompt_only) and the scenario where a [user and system prompt is to be optimized together](samples/facility-support-analyzer/system_and_user_prompt)
58
101
59
102
103
+
## 🚀 Quick Start: SageMaker Endpoints
104
+
105
+
Optimize prompts for models deployed on Amazon SageMaker in just a few steps:
106
+
107
+
### 1. Install and Configure
108
+
```bash
109
+
pip install nova-prompt-optimizer
110
+
export AWS_ACCESS_KEY_ID="..."
111
+
export AWS_SECRET_ACCESS_KEY="..."
112
+
```
113
+
114
+
### 2. Prepare Your Dataset
115
+
```jsonl
116
+
{"input": "What is machine learning?", "answer": "Machine learning is..."}
NovaPromptOptimizer uses Premier for Meta Prompting and then uses MIPROv2 with 20 candidates and 50 trials with Premier as Prompting model and task model dependent on the mode it's set at.
409
+
NovaPromptOptimizer uses Nova 2.0 Lite for Meta Prompting and then uses MIPROv2 with 20 candidates and 30 trials. The task model depends on the mode it's set at.
410
+
411
+
**Automatic Meta-Prompting with Bedrock:**
412
+
When you don't provide a `meta_prompt_inference_adapter`, NovaPromptOptimizer automatically creates a BedrockInferenceAdapter with Nova 2.0 Lite for the meta-prompting phase. This means you can use any inference adapter (including SageMaker) for your task model, and the optimizer will handle meta-prompting with Bedrock automatically.
413
+
414
+
**Optimization Modes:**
415
+
416
+
| Mode | Meta-Prompt Model | Task Model | Use Case |
|`micro`| Nova 2.0 Lite | Nova Micro | Fast, cost-effective |
419
+
|`lite`| Nova 2.0 Lite | Nova Lite | Balanced (default) |
420
+
|`pro`| Nova 2.0 Lite | Nova Pro | High quality |
421
+
|`lite-2`| Nova 2.0 Lite | Nova 2.0 Lite | Maximum quality |
422
+
260
423
You can specify enable_json_fallback=False to disable the behavior that MIPROv2 will [fallback to use JSONAdapter to parse LM model output](https://github.com/stanfordnlp/dspy/blob/main/dspy/adapters/chat_adapter.py#L44-L51). This will force MIPROv2 use structured output (pydantic model) to parse LM output.
261
424
425
+
**Custom Mode:**
262
426
You could also define a custom mode and pass your own parameter values to NovaPromptOptimizer
WARNING amzn_nova_prompt_optimizer.core.inference: Warn: Prompt Variables not found in User Prompt, injecting them at the end of the prompt
315
479
```
316
480
481
+
## Advanced Features
482
+
483
+
### Separate Inference Adapters
484
+
485
+
Use different inference adapters for meta-prompting and task optimization phases. This is particularly useful when optimizing prompts for SageMaker endpoints while using Bedrock for meta-prompting.
486
+
487
+
**Example:**
488
+
```python
489
+
from amzn_nova_prompt_optimizer.core.inference import (
490
+
BedrockInferenceAdapter,
491
+
SageMakerInferenceAdapter
492
+
)
493
+
from amzn_nova_prompt_optimizer.core.optimizers import NovaPromptOptimizer
494
+
495
+
# Bedrock for meta-prompting (generates optimized prompts)
- Optimize SageMaker endpoints with Bedrock intelligence
519
+
- Cross-region support
520
+
- Independent rate limiting per adapter
521
+
522
+
For more details, see the [Separate Inference Adapters Guide](docs/SeparateInferenceAdapters.md).
523
+
524
+
### SageMaker Endpoint Support
525
+
526
+
The SDK now supports optimizing prompts for models deployed on Amazon SageMaker. SageMaker endpoints must use an OpenAI-compatible message format:
527
+
528
+
**Required Payload Format:**
529
+
```json
530
+
{
531
+
"messages": [
532
+
{"role": "system", "content": "You are helpful"},
533
+
{"role": "user", "content": "Hello"}
534
+
],
535
+
"max_tokens": 1000,
536
+
"temperature": 0.7,
537
+
"top_p": 0.9,
538
+
"top_k": 50
539
+
}
540
+
```
541
+
542
+
**Expected Response Format:**
543
+
```json
544
+
{
545
+
"choices": [
546
+
{
547
+
"message": {
548
+
"role": "assistant",
549
+
"content": "Hello! How can I help you?"
550
+
}
551
+
}
552
+
]
553
+
}
554
+
```
555
+
556
+
**Testing Your Endpoint:**
557
+
```python
558
+
from amzn_nova_prompt_optimizer.core.inference import SageMakerInferenceAdapter
559
+
560
+
adapter = SageMakerInferenceAdapter(
561
+
endpoint_name="my-endpoint",
562
+
region_name="us-west-2"
563
+
)
564
+
565
+
# Test connectivity
566
+
if adapter.test_connection():
567
+
print("✓ Endpoint is ready for optimization")
568
+
else:
569
+
print("✗ Endpoint connection failed")
570
+
```
571
+
572
+
For a complete guide, see the [SageMaker Quick Start](docs/QUICK_START_SAGEMAKER.md).
573
+
317
574
## Optimization Recommendations
318
575
1. Provide representative real-world evaluation sets and split them into training and testing sets. Ensure dataset is balanced on output label when splitting train and test sets.
319
576
2. For evaluation sets, the ground truth column should be as close to the inference output as possible. e.g. If the inference output is {"answer": "POSITIVE"} ground truth should also be in the same format {"answer": "POSITIVE"}
320
-
3. For NovaPromptOptimizer, choose the mode (mode= "premier" | ""pro" | "lite" | "micro") based on your Nova Model of choice. By default, we use "pro".
577
+
3. For NovaPromptOptimizer, choose the mode (mode= "lite-2" | ""pro" | "lite" | "micro") based on your Nova Model of choice. By default, we use "pro".
321
578
4. The `apply` function of the evaluation metric should return a numerical value between 0 and 1 for NovaPromptOptimizer or MIPROv2.
0 commit comments