llama-index-llms-bedrock-converse 0.10.5__py3-none-any.whl → 0.10.7__py3-none-any.whl

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.
@@ -4,6 +4,7 @@ from typing import (
4
4
  Callable,
5
5
  Dict,
6
6
  List,
7
+ Literal,
7
8
  Optional,
8
9
  Sequence,
9
10
  Tuple,
@@ -157,6 +158,13 @@ class BedrockConverse(FunctionCallingLLM):
157
158
  guardrail_version: Optional[str] = Field(
158
159
  description="The version number for the guardrail. The value can also be DRAFT"
159
160
  )
161
+ guardrail_stream_processing_mode: Optional[Literal["sync", "async"]] = Field(
162
+ description=(
163
+ "The stream processing mode to use when leveraging a guardrail in a streaming request (ConverseStream). "
164
+ "If set, the specified mode will be included in the request's guardrail configuration object, altering the streaming response behavior. "
165
+ "If a value is not provided, no mode will be explicitly included in the request's guardrail configuration object, and thus Amazon Bedrock's default, Synchronous Mode, will be used."
166
+ )
167
+ )
160
168
  application_inference_profile_arn: Optional[str] = Field(
161
169
  description="The ARN of an application inference profile to invoke in place of the model. If provided, make sure the model argument refers to the same one underlying the application inference profile."
162
170
  )
@@ -167,6 +175,10 @@ class BedrockConverse(FunctionCallingLLM):
167
175
  description="Specifies the thinking configuration of a reasoning model. Only applicable to Anthropic and DeepSeek models",
168
176
  default=None,
169
177
  )
178
+ supports_forced_tool_calls: bool = Field(
179
+ default=True,
180
+ description="Whether the model supports forced tool calls. If True, the model can be forced to call at least 1 or more tools.",
181
+ )
170
182
  additional_kwargs: Dict[str, Any] = Field(
171
183
  default_factory=dict,
172
184
  description="Additional kwargs for the bedrock invokeModel request.",
@@ -207,9 +219,11 @@ class BedrockConverse(FunctionCallingLLM):
207
219
  output_parser: Optional[BaseOutputParser] = None,
208
220
  guardrail_identifier: Optional[str] = None,
209
221
  guardrail_version: Optional[str] = None,
222
+ guardrail_stream_processing_mode: Optional[Literal["sync", "async"]] = None,
210
223
  application_inference_profile_arn: Optional[str] = None,
211
224
  trace: Optional[str] = None,
212
225
  thinking: Optional[ThinkingDict] = None,
226
+ supports_forced_tool_calls: bool = True,
213
227
  ) -> None:
214
228
  additional_kwargs = additional_kwargs or {}
215
229
  callback_manager = callback_manager or CallbackManager([])
@@ -258,9 +272,11 @@ class BedrockConverse(FunctionCallingLLM):
258
272
  botocore_config=botocore_config,
259
273
  guardrail_identifier=guardrail_identifier,
260
274
  guardrail_version=guardrail_version,
275
+ guardrail_stream_processing_mode=guardrail_stream_processing_mode,
261
276
  application_inference_profile_arn=application_inference_profile_arn,
262
277
  trace=trace,
263
278
  thinking=thinking,
279
+ supports_forced_tool_calls=supports_forced_tool_calls,
264
280
  )
265
281
 
266
282
  self._config = None
@@ -468,6 +484,7 @@ class BedrockConverse(FunctionCallingLLM):
468
484
  stream=True,
469
485
  guardrail_identifier=self.guardrail_identifier,
470
486
  guardrail_version=self.guardrail_version,
487
+ guardrail_stream_processing_mode=self.guardrail_stream_processing_mode,
471
488
  trace=self.trace,
472
489
  **all_kwargs,
473
490
  )
@@ -662,6 +679,7 @@ class BedrockConverse(FunctionCallingLLM):
662
679
  stream=False,
663
680
  guardrail_identifier=self.guardrail_identifier,
664
681
  guardrail_version=self.guardrail_version,
682
+ guardrail_stream_processing_mode=self.guardrail_stream_processing_mode,
665
683
  trace=self.trace,
666
684
  boto_client_kwargs=self._boto_client_kwargs,
667
685
  **all_kwargs,
@@ -913,6 +931,7 @@ class BedrockConverse(FunctionCallingLLM):
913
931
  tool_choice=tool_choice,
914
932
  tool_required=tool_required,
915
933
  tool_caching=tool_caching,
934
+ supports_forced_tool_calls=self.supports_forced_tool_calls,
916
935
  )
917
936
 
918
937
  return {
@@ -454,6 +454,7 @@ def tools_to_converse_tools(
454
454
  tool_choice: Optional[dict] = None,
455
455
  tool_required: bool = False,
456
456
  tool_caching: bool = False,
457
+ supports_forced_tool_calls: bool = True,
457
458
  ) -> Dict[str, Any]:
458
459
  """
459
460
  Converts a list of tools to AWS Bedrock Converse tools.
@@ -482,11 +483,18 @@ def tools_to_converse_tools(
482
483
  if tool_caching:
483
484
  converse_tools.append({"cachePoint": {"type": "default"}})
484
485
 
486
+ if tool_choice:
487
+ tool_choice = tool_choice
488
+ elif supports_forced_tool_calls and tool_required:
489
+ tool_choice = {"any": {}}
490
+ else:
491
+ tool_choice = {"auto": {}}
492
+
485
493
  return {
486
494
  "tools": converse_tools,
487
495
  # https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ToolChoice.html
488
496
  # e.g. { "auto": {} }
489
- "toolChoice": tool_choice or ({"any": {}} if tool_required else {"auto": {}}),
497
+ "toolChoice": tool_choice,
490
498
  }
491
499
 
492
500
 
@@ -555,6 +563,7 @@ def converse_with_retry(
555
563
  stream: bool = False,
556
564
  guardrail_identifier: Optional[str] = None,
557
565
  guardrail_version: Optional[str] = None,
566
+ guardrail_stream_processing_mode: Optional[Literal["sync", "async"]] = None,
558
567
  trace: Optional[str] = None,
559
568
  **kwargs: Any,
560
569
  ) -> Any:
@@ -595,6 +604,10 @@ def converse_with_retry(
595
604
  converse_kwargs["guardrailConfig"]["guardrailVersion"] = guardrail_version
596
605
  if trace:
597
606
  converse_kwargs["guardrailConfig"]["trace"] = trace
607
+ if guardrail_stream_processing_mode and stream:
608
+ converse_kwargs["guardrailConfig"]["streamProcessingMode"] = (
609
+ guardrail_stream_processing_mode
610
+ )
598
611
 
599
612
  converse_kwargs = join_two_dicts(
600
613
  converse_kwargs,
@@ -636,6 +649,7 @@ async def converse_with_retry_async(
636
649
  stream: bool = False,
637
650
  guardrail_identifier: Optional[str] = None,
638
651
  guardrail_version: Optional[str] = None,
652
+ guardrail_stream_processing_mode: Optional[Literal["sync", "async"]] = None,
639
653
  trace: Optional[str] = None,
640
654
  boto_client_kwargs: Optional[Dict[str, Any]] = None,
641
655
  **kwargs: Any,
@@ -682,6 +696,10 @@ async def converse_with_retry_async(
682
696
  converse_kwargs["guardrailConfig"]["guardrailVersion"] = guardrail_version
683
697
  if trace:
684
698
  converse_kwargs["guardrailConfig"]["trace"] = trace
699
+ if guardrail_stream_processing_mode and stream:
700
+ converse_kwargs["guardrailConfig"]["streamProcessingMode"] = (
701
+ guardrail_stream_processing_mode
702
+ )
685
703
  converse_kwargs = join_two_dicts(
686
704
  converse_kwargs,
687
705
  {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: llama-index-llms-bedrock-converse
3
- Version: 0.10.5
3
+ Version: 0.10.7
4
4
  Summary: llama-index llms bedrock converse integration
5
5
  Author-email: Your Name <you@example.com>
6
6
  License-Expression: MIT
@@ -0,0 +1,7 @@
1
+ llama_index/llms/bedrock_converse/__init__.py,sha256=xE3ZHLXqFr7TTTgQlYH9bLLPRZAV3dJyiz_iUFXBfak,98
2
+ llama_index/llms/bedrock_converse/base.py,sha256=EhpNGpUZeRdgGxOiDrKQpsbEBK0SjsUrnWyBahk3kzA,42405
3
+ llama_index/llms/bedrock_converse/utils.py,sha256=9DTBUqUjGmuMTZqoMPKmbEn8HKlFuwkM75Qwxo3RTzc,28443
4
+ llama_index_llms_bedrock_converse-0.10.7.dist-info/METADATA,sha256=IrUx5LV4T9y5eEJfrJ3eOcR7vjZqDBdYbJng4VnGcrM,7834
5
+ llama_index_llms_bedrock_converse-0.10.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ llama_index_llms_bedrock_converse-0.10.7.dist-info/licenses/LICENSE,sha256=JPQLUZD9rKvCTdu192Nk0V5PAwklIg6jANii3UmTyMs,1065
7
+ llama_index_llms_bedrock_converse-0.10.7.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- llama_index/llms/bedrock_converse/__init__.py,sha256=xE3ZHLXqFr7TTTgQlYH9bLLPRZAV3dJyiz_iUFXBfak,98
2
- llama_index/llms/bedrock_converse/base.py,sha256=tXQMmgyYZmrudRsQ7uofvQyIKNUTQtTpcdny1EoMCB0,41080
3
- llama_index/llms/bedrock_converse/utils.py,sha256=LAeSiK_GLiRhoLMEVJKtMEOcqon_8UW-db04-NQJDn4,27711
4
- llama_index_llms_bedrock_converse-0.10.5.dist-info/METADATA,sha256=z2YFtHev0AwKQRhyNnTCdlkAzwzHPLY_PKdSJk7HqP8,7834
5
- llama_index_llms_bedrock_converse-0.10.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
- llama_index_llms_bedrock_converse-0.10.5.dist-info/licenses/LICENSE,sha256=JPQLUZD9rKvCTdu192Nk0V5PAwklIg6jANii3UmTyMs,1065
7
- llama_index_llms_bedrock_converse-0.10.5.dist-info/RECORD,,