Skip to content

Commit 9a0f6d4

Browse files
committed
fix: Set Bedrock client backoff to handle per-minute throttles
1 parent 5f9a670 commit 9a0f6d4

File tree

8 files changed

+37
-15
lines changed

8 files changed

+37
-15
lines changed

e2e_tests/python/chat_session.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ async def start(self) -> None:
6868
messages = []
6969

7070
for i, user_input in enumerate(self.user_utterances):
71-
if i != 0:
72-
print("\n**Pausing 30 seconds to avoid Bedrock throttling**")
73-
await asyncio.sleep(30)
74-
7571
print(f"\nYou: {user_input}")
7672

7773
messages.append({"role": "user", "content": [{"text": user_input}]})

e2e_tests/python/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import boto3
3+
from botocore.config import Config
34
import json
45
import logging
56
import os
@@ -57,7 +58,15 @@ def bedrock_client(self) -> Any:
5758
Returns:
5859
The Bedrock client.
5960
"""
60-
return boto3.client("bedrock-runtime", region_name=self.region)
61+
retry_config = Config(
62+
retries={
63+
"max_attempts": 10,
64+
"mode": "standard",
65+
}
66+
)
67+
return boto3.client(
68+
"bedrock-runtime", region_name=self.region, config=retry_config
69+
)
6170

6271

6372
async def main() -> None:

e2e_tests/typescript/src/chat_session.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ export class ChatSession {
8282
const messages: Message[] = [];
8383

8484
for (const [i, userInput] of this.userUtterances.entries()) {
85-
if (i != 0) {
86-
console.log("\n**Pausing 30 seconds to avoid Bedrock throttling**");
87-
await new Promise((resolve) => setTimeout(resolve, 30 * 1000));
88-
}
89-
9085
console.log(`\You: ${userInput}`);
9186

9287
messages.push({ role: "user", content: [{ text: userInput }] });

e2e_tests/typescript/src/configuration.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export class Configuration {
4343
* @returns The Bedrock client.
4444
*/
4545
get bedrockClient(): BedrockRuntimeClient {
46-
return new BedrockRuntimeClient({ region: this.region });
46+
return new BedrockRuntimeClient({
47+
region: this.region,
48+
retryMode: "standard",
49+
maxAttempts: 10,
50+
});
4751
}
4852
}

examples/chatbots/python/chat_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def start(self) -> None:
6666
while True:
6767
try:
6868
user_input = input("\nYou: ").strip().lower()
69-
if user_input in ["quit", "exit"]:
69+
if user_input in ["quit", "exit", "/quit", "/exit"]:
7070
logging.info("\nExiting...")
7171
break
7272

examples/chatbots/python/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import boto3
3+
from botocore.config import Config
34
import json
45
import logging
56
import os
@@ -57,7 +58,15 @@ def bedrock_client(self) -> Any:
5758
Returns:
5859
The Bedrock client.
5960
"""
60-
return boto3.client("bedrock-runtime", region_name=self.region)
61+
retry_config = Config(
62+
retries={
63+
"max_attempts": 10,
64+
"mode": "standard",
65+
}
66+
)
67+
return boto3.client(
68+
"bedrock-runtime", region_name=self.region, config=retry_config
69+
)
6170

6271

6372
async def main() -> None:

examples/chatbots/typescript/src/chat_session.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ export class ChatSession {
7878

7979
while (true) {
8080
const userInput = readline.question("\nYou: ").trim().toLowerCase();
81-
if (userInput === "quit" || userInput === "exit") {
81+
if (
82+
userInput === "quit" ||
83+
userInput === "exit" ||
84+
userInput === "/quit" ||
85+
userInput === "/exit"
86+
) {
8287
logger.info("\nExiting...");
8388
break;
8489
}

examples/chatbots/typescript/src/configuration.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export class Configuration {
4343
* @returns The Bedrock client.
4444
*/
4545
get bedrockClient(): BedrockRuntimeClient {
46-
return new BedrockRuntimeClient({ region: this.region });
46+
return new BedrockRuntimeClient({
47+
region: this.region,
48+
retryMode: "standard",
49+
maxAttempts: 10,
50+
});
4751
}
4852
}

0 commit comments

Comments
 (0)