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

[Amazon Bedrock] Amazon Bedrock example to demonstrate the feature #173

Closed
Tracked by #113
bilgeyucel opened this issue Jan 4, 2024 · 0 comments
Closed
Tracked by #113
Assignees

Comments

@bilgeyucel
Copy link
Contributor

bilgeyucel commented Jan 4, 2024

Something along the lines of:

from amazon_bedrock_haystack import AmazonBedrockGenerator

aws_access_key_id="..."
aws_secret_access_key="..."
aws_region_name="eu-central-1"

generator = AmazonBedrockGenerator(model_name="anthropic.claude-v2",aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key,aws_region_name=aws_region_name)
result = generator.run("Who is the best American actor?")
for reply in result["replies"]:
    print(reply)

# >>> 'There is no definitive "best" American actor, as acting skill and talent a# re subjective. However, some of the most acclaimed and influential American act# ors include Tom Hanks, Daniel Day-Lewis, Denzel Washington, Meryl Streep, Rober# t De Niro, Al Pacino, Marlon Brando, Jack Nicholson, Leonardo DiCaprio and John# ny Depp. Choosing a single "best" actor comes down to personal preference.'

or in a pipeline:

from haystack.components.retrievers import InMemoryBM25Retriever
from haystack.components.builders import PromptBuilder
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack import Pipeline

from amazon_bedrock_haystack import AmazonBedrockGenerator

template = """
Given the following information, answer the question.

Context: 
{% for document in documents %}
    {{ document.content }}
{% endfor %}

Question: What's the official language of {{ country }}?
"""

aws_access_key_id="..."
aws_secret_access_key="..."
aws_region_name="eu-central-1"
generator = AmazonBedrockGenerator(model_name="anthropic.claude-v2",aws_access_key_id=aws_access_key_id,aws_secret_access_key=aws_secret_access_key,aws_region_name=aws_region_name)
docstore = InMemoryDocumentStore()

pipe = Pipeline()
pipe.add_component("retriever", InMemoryBM25Retriever(document_store=docstore))
pipe.add_component("prompt_builder", PromptBuilder(template=template))
pipe.add_component("generator", generator)
pipe.connect("retriever", "prompt_builder.documents")
pipe.connect("prompt_builder", "generator")

pipe.run({
    "retriever":{ "query": "France"},
    "prompt_builder": {
        "country": "France"
    }
})

# {'generator': {'replies': ['Based on the context provided, the official language of France is French.']}}
@bilgeyucel bilgeyucel changed the title There is an example available to demonstrate the feature Amazon Bedrock example to demonstrate the feature Jan 4, 2024
@bilgeyucel bilgeyucel self-assigned this Jan 4, 2024
@julian-risch julian-risch changed the title Amazon Bedrock example to demonstrate the feature [Amazon Bedrock] Amazon Bedrock example to demonstrate the feature Jan 8, 2024
@mathislucka mathislucka added this to the 2.0 Generators milestone Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants