You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromamazon_bedrock_haystackimportAmazonBedrockGeneratoraws_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?")
forreplyinresult["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:
fromhaystack.components.retrieversimportInMemoryBM25Retrieverfromhaystack.components.buildersimportPromptBuilderfromhaystack.document_stores.in_memoryimportInMemoryDocumentStorefromhaystackimportPipelinefromamazon_bedrock_haystackimportAmazonBedrockGeneratortemplate="""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.']}}
The text was updated successfully, but these errors were encountered:
julian-risch
changed the title
Amazon Bedrock example to demonstrate the feature
[Amazon Bedrock] Amazon Bedrock example to demonstrate the feature
Jan 8, 2024
Something along the lines of:
or in a pipeline:
The text was updated successfully, but these errors were encountered: