Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Update AmazonBedrockGenerator docstrings #956

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
@component
class AmazonBedrockGenerator:
"""
`AmazonBedrockGenerator` enables text generation via Amazon Bedrock hosted LLMs.
Generates text using models hosted on Amazon Bedrock.

For example, to use the Anthropic Claude model, simply initialize the `AmazonBedrockGenerator` with the
'anthropic.claude-v2' model name. Provide AWS credentials either via local AWS profile or directly via
For example, to use the Anthropic Claude model, pass 'anthropic.claude-v2' in the `model` parameter.
Provide AWS credentials either via local AWS profile or directly via
agnieszka-m marked this conversation as resolved.
Show resolved Hide resolved
`aws_access_key_id`, `aws_secret_access_key`, `aws_session_token`, and `aws_region_name` parameters.

Usage example:
### Usage example

```python
from haystack_integrations.components.generators.amazon_bedrock import AmazonBedrockGenerator

Expand All @@ -52,6 +53,16 @@ class AmazonBedrockGenerator:

print(generator.run("Who is the best American actor?"))
```

AmazonBedrockGenerator uses AWS for authentication. You can use the AWS CLI to authenticate through your IAM.
For more information on setting up an IAM identity-based policy, see [Amazon Bedrock documentation]
(https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html).
If the AWS environment is configured correctly, the AWS credentials are not required as they're loaded
automatically from the environment or the AWS configuration file.
If the AWS environment is not configured, set `aws_access_key_id`, `aws_secret_access_key`,
`aws_session_token`, and `aws_region_name` as environment variables or pass them as
[Secret](https://docs.haystack.deepset.ai/v2.0/docs/secret-management) arguments. Make sure the region you set
supports Amazon Bedrock.
"""

SUPPORTED_MODEL_PATTERNS: ClassVar[Dict[str, Type[BedrockModelAdapter]]] = {
Expand Down Expand Up @@ -85,11 +96,12 @@ def __init__(
:param aws_access_key_id: The AWS access key ID.
:param aws_secret_access_key: The AWS secret access key.
:param aws_session_token: The AWS session token.
:param aws_region_name: The AWS region name.
:param aws_region_name: The AWS region name. Make sure the region you set supports Amazon Bedrock.
:param aws_profile_name: The AWS profile name.
:param max_length: The maximum length of the generated text.
:param truncate: Whether to truncate the prompt or not.
:param kwargs: Additional keyword arguments to be passed to the model.
These arguments are specific to the model. You can find them in the model's documentation.
:raises ValueError: If the model name is empty or None.
:raises AmazonBedrockConfigurationError: If the AWS environment is not configured correctly or the model is
not supported.
Expand Down Expand Up @@ -236,8 +248,9 @@ def run(self, prompt: str, generation_kwargs: Optional[Dict[str, Any]] = None):
"""
Generates a list of string response to the given prompt.

:param prompt: The prompt to generate a response for.
:param generation_kwargs: Additional keyword arguments passed to the generator.
:param prompt: Instructions for the model.
:param generation_kwargs: Additional keyword arguments to customize text generation.
These arguments are specific to the model. You can find them in the model's documentation.
:returns: A dictionary with the following keys:
- `replies`: A list of generated responses.
:raises ValueError: If the prompt is empty or None.
Expand Down