llama-index-llms-bedrock-converse 0.12.4__tar.gz → 0.12.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: llama-index-llms-bedrock-converse
3
- Version: 0.12.4
3
+ Version: 0.12.6
4
4
  Summary: llama-index llms bedrock converse integration
5
5
  Author-email: Your Name <you@example.com>
6
6
  License-Expression: MIT
@@ -12,10 +12,12 @@ from typing import (
12
12
  Literal,
13
13
  Union,
14
14
  )
15
+ from botocore.exceptions import ClientError
15
16
  from typing_extensions import TypedDict
16
17
  from tenacity import (
17
18
  before_sleep_log,
18
19
  retry,
20
+ retry_if_exception,
19
21
  retry_if_exception_type,
20
22
  stop_after_attempt,
21
23
  wait_exponential,
@@ -491,7 +493,7 @@ def tools_to_converse_tools(
491
493
  tool_required: bool = False,
492
494
  tool_caching: bool = False,
493
495
  supports_forced_tool_calls: bool = True,
494
- ) -> Dict[str, Any]:
496
+ ) -> Optional[Dict[str, Any]]:
495
497
  """
496
498
  Converts a list of tools to AWS Bedrock Converse tools.
497
499
 
@@ -499,9 +501,12 @@ def tools_to_converse_tools(
499
501
  tools: List of BaseTools
500
502
 
501
503
  Returns:
502
- AWS Bedrock Converse tools
504
+ AWS Bedrock Converse tools, or None if tools list is empty
503
505
 
504
506
  """
507
+ if not tools:
508
+ return None
509
+
505
510
  converse_tools = []
506
511
  for tool in tools:
507
512
  tool_name, tool_description = tool.metadata.name, tool.metadata.description
@@ -563,11 +568,38 @@ def _create_retry_decorator(client: Any, max_retries: int) -> Callable[[Any], An
563
568
  reraise=True,
564
569
  stop=stop_after_attempt(max_retries),
565
570
  wait=wait_exponential(multiplier=1, min=min_seconds, max=max_seconds),
566
- retry=(retry_if_exception_type(client.exceptions.ThrottlingException)),
571
+ retry=(
572
+ retry_if_exception_type(
573
+ (
574
+ client.exceptions.ThrottlingException,
575
+ client.exceptions.InternalServerException,
576
+ client.exceptions.ServiceUnavailableException,
577
+ client.exceptions.ModelTimeoutException,
578
+ )
579
+ )
580
+ ),
567
581
  before_sleep=before_sleep_log(logger, logging.WARNING),
568
582
  )
569
583
 
570
584
 
585
+ RETRYABLE_ERROR_CODES = frozenset(
586
+ {
587
+ "ThrottlingException",
588
+ "InternalServerException",
589
+ "ServiceUnavailableException",
590
+ "ModelTimeoutException",
591
+ }
592
+ )
593
+
594
+
595
+ def _is_retryable_client_error(exception: BaseException) -> bool:
596
+ """Check if an exception is a retryable ClientError from botocore."""
597
+ if isinstance(exception, ClientError):
598
+ error_code = exception.response.get("Error", {}).get("Code", "")
599
+ return error_code in RETRYABLE_ERROR_CODES
600
+ return False
601
+
602
+
571
603
  def _create_retry_decorator_async(max_retries: int) -> Callable[[Any], Any]:
572
604
  min_seconds = 4
573
605
  max_seconds = 10
@@ -585,9 +617,7 @@ def _create_retry_decorator_async(max_retries: int) -> Callable[[Any], Any]:
585
617
  reraise=True,
586
618
  stop=stop_after_attempt(max_retries),
587
619
  wait=wait_exponential(multiplier=1, min=min_seconds, max=max_seconds),
588
- retry=(
589
- retry_if_exception_type()
590
- ), # TODO: Add throttling exception in async version
620
+ retry=retry_if_exception(_is_retryable_client_error),
591
621
  before_sleep=before_sleep_log(logger, logging.WARNING),
592
622
  )
593
623
 
@@ -29,7 +29,7 @@ dev = [
29
29
 
30
30
  [project]
31
31
  name = "llama-index-llms-bedrock-converse"
32
- version = "0.12.4"
32
+ version = "0.12.6"
33
33
  description = "llama-index llms bedrock converse integration"
34
34
  authors = [{name = "Your Name", email = "you@example.com"}]
35
35
  requires-python = ">=3.9,<4.0"