Convert inputs to API kwargs for AWS Bedrock.
(
self, input: Any = None, model_kwargs: Dict = None, model_type: ModelType = None
)
| 440 | return self.call(api_kwargs, model_type) |
| 441 | |
| 442 | def convert_inputs_to_api_kwargs( |
| 443 | self, input: Any = None, model_kwargs: Dict = None, model_type: ModelType = None |
| 444 | ) -> Dict: |
| 445 | """Convert inputs to API kwargs for AWS Bedrock.""" |
| 446 | model_kwargs = model_kwargs or {} |
| 447 | api_kwargs = {} |
| 448 | |
| 449 | if model_type == ModelType.LLM: |
| 450 | api_kwargs["model"] = model_kwargs.get("model", "anthropic.claude-3-sonnet-20240229-v1:0") |
| 451 | api_kwargs["input"] = input |
| 452 | |
| 453 | # Add model parameters |
| 454 | if "temperature" in model_kwargs: |
| 455 | api_kwargs["temperature"] = model_kwargs["temperature"] |
| 456 | if "top_p" in model_kwargs: |
| 457 | api_kwargs["top_p"] = model_kwargs["top_p"] |
| 458 | |
| 459 | return api_kwargs |
| 460 | elif model_type == ModelType.EMBEDDER: |
| 461 | if isinstance(input, str): |
| 462 | inputs = [input] |
| 463 | elif isinstance(input, Sequence): |
| 464 | inputs = list(input) |
| 465 | else: |
| 466 | raise TypeError("input must be a string or sequence of strings") |
| 467 | |
| 468 | api_kwargs["model"] = model_kwargs.get("model", "amazon.titan-embed-text-v2:0") |
| 469 | api_kwargs["input"] = inputs |
| 470 | api_kwargs["model_kwargs"] = model_kwargs |
| 471 | return api_kwargs |
| 472 | else: |
| 473 | raise ValueError(f"Model type {model_type} is not supported by AWS Bedrock client") |
nothing calls this directly
no outgoing calls
no test coverage detected