📘 **TELUS Agriculture & Consumer Goods** 如何通过 **Haystack Agents** 转变促销交易
由 deepset 维护

集成:Amazon Sagemaker

通过 Amazon Sagemaker 和 Haystack 使用 Huggingface、Anthropic、AI21 Labs、Cohere、Meta 和 Amazon 的模型

作者
deepset

目录

概述

Amazon Sagemaker 是一个全面、完全托管的机器学习服务,使数据科学家和开发人员能够高效地构建、训练和部署机器学习模型。有关更多信息,请参阅 文档页面

安装

安装 Amazon Sagemaker 集成

pip install amazon-sagemaker-haystack

使用

安装后,您将可以使用一个支持来自各种提供商模型的 SagemakerGenerator。要了解支持哪些模型,请查看 Sagemaker 的文档

要使用此集成进行文本生成,请使用模型名称和 AWS 凭据初始化一个 SagemakerGenerator

import os
haystack_integrations.components.generators.amazon_sagemaker import SagemakerGenerator

os.environ["AWS_ACCESS_KEY_ID"] = "..."
os.environ["AWS_SECRET_ACCESS_KEY"] = "..."
# This one is optional
os.environ["AWS_REGION_NAME"] = "..."

model = # Your Sagemaker endpoint name, such as "jumpstart-dft-hf-llm-falcon-7b-instruct-bf16"

generator = SagemakerGenerator(model=model)
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 are subjective.
However, some of the most acclaimed and influential American actors 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.'

请注意,不同的模型可能需要不同的参数。一个显著的例子是 Llama2 系列模型,它应该使用 {'accept_eula': True} 作为自定义属性进行初始化

generator = SagemakerGenerator(model="jumpstart-dft-meta-textgenerationneuron-llama-2-7b", aws_custom_attributes={"accept_eula": True})