Skip to content

Commit 2f4b278

Browse files
committed
feat: refactor based on strands recs
1 parent 56d1a63 commit 2f4b278

5 files changed

Lines changed: 758 additions & 315 deletions

File tree

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,19 @@ response = await agent.run("Tell me about quantum computing")
133133

134134
### Error Handling
135135

136+
The package provides custom exceptions for Nova-specific errors, along with support for Strands SDK exceptions:
137+
136138
```python
137139
from strands.types.exceptions import (
138140
ContextWindowOverflowException,
139141
ModelThrottledException
140142
)
143+
from strands_nova import (
144+
NovaAPIException, # Base exception for all Nova API errors
145+
NovaValidationException, # HTTP 400 validation errors
146+
NovaModelNotFoundException, # HTTP 404 model not found
147+
NovaModelException # HTTP 500 internal model errors
148+
)
141149

142150
try:
143151
async for chunk in model.stream(messages=messages):
@@ -149,10 +157,32 @@ except ContextWindowOverflowException as e:
149157
except ModelThrottledException as e:
150158
print(f"Rate limited: {e}")
151159
# Implement retry with backoff
160+
except NovaValidationException as e:
161+
print(f"Validation error: {e}")
162+
# Check request parameters
163+
except NovaModelNotFoundException as e:
164+
print(f"Model not found: {e}")
165+
# Verify model_id is correct
166+
except NovaModelException as e:
167+
print(f"Model error: {e}")
168+
# Nova API internal error
169+
except NovaAPIException as e:
170+
print(f"Nova API error: {e}")
171+
# Catch-all for other Nova errors
152172
except Exception as e:
153-
print(f"API error: {e}")
173+
print(f"Unexpected error: {e}")
154174
```
155175

176+
**Custom Nova Exceptions:**
177+
- `NovaAPIException`: Base exception for all Nova API errors
178+
- `NovaValidationException`: Raised for HTTP 400 validation errors (malformed requests, invalid parameters)
179+
- `NovaModelNotFoundException`: Raised for HTTP 404 errors (model not found or inaccessible)
180+
- `NovaModelException`: Raised for HTTP 500 errors (internal model service errors)
181+
182+
**Strands SDK Exceptions:**
183+
- `ContextWindowOverflowException`: Raised when input exceeds the model's context window
184+
- `ModelThrottledException`: Raised when requests are rate-limited (HTTP 429)
185+
156186
## Getting Your API Key
157187

158188
1. Visit [https://nova.amazon.com/dev-apis](https://nova.amazon.com/dev-apis)

src/strands_nova/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,24 @@
55
access to Nova Pro, Nova Premier, reasoning models, and image generation capabilities.
66
"""
77

8-
from .nova import NovaModel, NovaSystemTool
8+
from .nova import (
9+
NovaModel,
10+
NovaSystemTool,
11+
NovaAPIException,
12+
NovaValidationException,
13+
NovaModelNotFoundException,
14+
NovaModelException,
15+
)
916

1017
__version__ = "0.1.0"
11-
__all__ = ["NovaModel", "NovaSystemTool"]
18+
__all__ = [
19+
"NovaModel",
20+
"NovaSystemTool",
21+
"NovaAPIException",
22+
"NovaValidationException",
23+
"NovaModelNotFoundException",
24+
"NovaModelException",
25+
]
1226

1327

1428
# Convenience exports for common use cases

0 commit comments

Comments
 (0)