在Amazon Bedrock平台上畅享全托管无服务器版DeepSeek-R1引言

1月30日起,DeepSeek-R1模型正式上线Amazon Bedrock Marketplace和Amazon Bedrock Custom Model Import。自发布以来,该模型已被数千名用户部署于Amazon Bedrock中。近期,Amazon进一步优化了DeepSeek-R1的使用体验,推出了全新的无服务器解决方案,使用户能够更便捷地访问这一强大模型。

如今,全托管版DeepSeek-R1模型已正式登陆Amazon Bedrock,Amazon Web Services成为首家提供全托管DeepSeek-R1服务的云计算提供商。这一创新使企业和开发者能够专注于构建生成式AI应用,而无需操心底层基础设施的管理。只需调用Amazon Bedrock的一站式API,用户便可充分利用DeepSeek-R1的强大能力,并结合Amazon丰富的功能与工具,应用于智能决策、软件开发、数学问题求解、科学分析、数据洞察及知识管理等多种场景。

与所有AI解决方案一样,在生产环境中部署时需特别注意严格遵循数据隐私要求、检测输出结果的偏差性并持续监控效果。对于DeepSeek-R1这类公开可用模型的实施,建议重点考虑以下因素:

  • 数据安全方面——可利用Amazon Bedrock的企业级安全防护、监控及成本管控功能,这些功能对实现规模化负责任AI部署至关重要,同时完全掌控自身数据。用户输入内容与模型输出结果不会与任何模型供应商共享。默认情况下即可使用静态与传输中数据加密、细粒度访问控制、安全连接选项等安全功能,以及在Amazon Bedrock平台与DeepSeek-R1模型交互时获取各类合规认证文件。
  • 负责任AI实践——通过Amazon Bedrock Guardrails,可以根据应用需求和负责任的AI政策实施定制化防护措施。该功能包含以下核心特性:内容过滤,筛除不当及有害内容;敏感信息过滤,自动识别并处理隐私数据;可配置安全控制,通过上下文锚定和自动推理检查来防止模型幻觉。也就是说,可以通过预定义策略集,精确控制用户与Bedrock平台中DeepSeek-R1模型的交互,从而在生成式AI应用中有效过滤不良及有害内容。
  • 模型评估——通过Amazon Bedrock的模型评估工具,只需简单几步即可对DeepSeek-R1等模型进行评估和比较,从而确定最适合用例的模型。评估支持两种方式:自动评估,即使用预定义指标;人工评估,即针对主观或定制化指标。该功能提供内置精选数据集,同时也支持导入自己的数据集进行定制化评估。

所以,最好将Amazon Bedrock Guardrails和Amazon Bedrock模型评估功能与DeepSeek-R1模型结合使用,为生成式AI应用程序提供强有力的保护。

开始使用Amazon Bedrock中的DeepSeek-R1模型

如果是初次使用DeepSeek-R1模型,请前往Amazon Bedrock控制台,在左侧导航栏的"Bedrock配置"下选择"模型访问"。要使用全托管DeepSeek-R1模型,需在DeepSeek中申请DeepSeek-R1的访问权限。通过审核后,即可在Amazon Bedrock中访问该模型。

下一步,要在Amazon Bedrock中测试DeepSeek-R1模型,在左侧菜单面板的Playgrounds下选择Chat/Text。然后在左上角选择Select model,选择DeepSeek作为类别,DeepSeek-R1作为模型。最后选择Apply。

比如说使用以下提示词来询问DeepSeek-R1模型:

A family has $5,000 to save for their vacation next year. They can place the money in a savings account earning 2% interest annually or in a certificate of deposit earning 4% interest annually but with no access to the funds until the vacation. If they need $1,000 for emergency expenses during the year, how should they divide their money between the two options to maximize their vacation fund?

可以看到AI很顺利的解答了这个问题。要了解更多提示词使用建议,请参阅 DeepSeek-R1 模型提示指南。不仅如此,通过选择 View API request,还可以使用Amazon命令行界面和Amazon SDK中的代码示例来访问该模型。这里可以使用us.deepseek.r1-v1:0作为模型ID。以下是一个Amazon CLI命令示例:

aws bedrock-runtime invoke-model \
       --model-id us.deepseek.r1-v1:0 \
       --body "{\"prompt\": \"<|begin_of_sentence|><|User|>Type_Your_Prompt_Here<|Assistant|><think>\n\", \"max_tokens\": 512, \"temperature\": 0.5, \"top_p\": 0.9}" \
       --cli-binary-format raw-in-base64-out \
       --region us-west-2 \
       invoke-model-output.txt

该模型同时支持InvokeModel和Converse API。下面的Python代码示例展示了如何使用Amazon Bedrock Converse API向DeepSeek-R1模型发送文本消息以生成文本。

import boto3
from botocore.exceptions import ClientError

# Create a Bedrock Runtime client in the AWS Region you want to use.
client = boto3.client("bedrock-runtime", region_name="us-west-2")

# Set the model ID, e.g., DeepSeek-R1 Model.
model_id = "us.deepseek.r1-v1:0"

# Start a conversation with the user message.
user_message = "Type_Your_Prompt_Here"
conversation = [
    {
        "role": "user",
        "content": [{"text": user_message}],
    }
]

try:
    # Send the message to the model, using a basic inference configuration.
    response = client.converse(
        modelId=model_id,
        messages=conversation,
        inferenceConfig={"maxTokens": 512, "temperature": 0.5, "topP": 0.9},
    )

    # Extract and print the response text.
    response_text = response["output"]["message"]["content"][0]["text"]
    print(response_text)

except (ClientError, Exception) as e:
    print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}")
    exit(1)

详细细节,请访问文档亚马逊云科技文档中的DeepSeek model inference parameters and responses。

如果要在DeepSeek-R1模型上启用Amazon Bedrock Guardrails,请在左侧导航面板的Safeguards下选择Guardrails,并通过配置所需数量的过滤器来创建guardrail。比如说要过滤"politics"一词,guardrails将能识别提示中的该词并显示被拦截的消息。

我们可以通过测试不同的输入来评估 guardrail 的性能。也可以通过设置禁止话题、词语过滤器、敏感信息过滤器和拦截消息来优化guardrail,直到它符合需求。

总结

Amazon Bedrock提供了一个强大、便捷且安全的环境,使企业能够轻松部署和管理DeepSeek-R1模型。通过全托管服务,开发者无需担心底层基础设施的复杂性,可专注于创新AI应用。此外,结合Amazon Bedrock Guardrails与模型评估工具,用户可以确保AI模型的可靠性、安全性和合规性。若想了解更多详情,可访问亚马逊云科技官方文档或Amazon Machine Learning Blog频道,获取最新的技术指南和实践案例。

猜你喜欢

转载自blog.csdn.net/m0_73367097/article/details/146505414
今日推荐