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
> AWS Bedrock's official SDK (`boto3`) does not support async natively. If you need to call Bedrock from async code, you can use `asyncio.to_thread` to run synchronous Bedrock calls in a non-blocking way.
93
90
94
91
```python
95
-
import boto3
96
92
import instructor
97
93
from pydantic import BaseModel
98
94
import asyncio
99
95
100
-
# Initialize the Bedrock client
101
-
bedrock_client = boto3.client('bedrock-runtime')
102
-
103
-
# Enable instructor patches for async Bedrock client
{"role": "user", "content": "Extract: Jason is 25 years old"},
151
-
],
139
+
Instructor’s Bedrock integration supports both OpenAI-style and Bedrock-native message formats, as well as any mix of the two. You can use either:
140
+
141
+
-**OpenAI-style**:
142
+
`{"role": "user", "content": "Extract: Jason is 25 years old"}`
143
+
144
+
-**Bedrock-native**:
145
+
`{"role": "user", "content": [{"text": "Extract: Jason is 25 years old"}]}`
146
+
147
+
-**Mixed**:
148
+
You can freely mix OpenAI-style and Bedrock-native messages in the same request. The integration will automatically convert OpenAI-style messages to the correct Bedrock format, while preserving any Bedrock-native fields you provide.
149
+
150
+
This flexibility also applies to other keyword arguments, such as the model name:
151
+
152
+
- You can use either `model` (OpenAI-style) or `modelId` (Bedrock-native) as a keyword argument.
153
+
- If you provide `model`, Instructor will automatically convert it to `modelId` for Bedrock.
154
+
- If you provide both, `modelId` takes precedence.
155
+
156
+
**Example:**
157
+
158
+
```python
159
+
import instructor
160
+
161
+
messages = [
162
+
{"role": "system", "content": "Extract the name and age."}, # OpenAI-style
163
+
{"role": "user", "content": [{"text": "Extract: Jason is 25 years old"}]}, # Bedrock-native
164
+
{"role": "assistant", "content": "Sure! Jason is 25."}, # OpenAI-style
0 commit comments