选择合适的模型
学习目标
使用 SAP Cloud SDK for AI 评估不同的模型。
我们已经对提示进行了优化,甚至用多模态输入对其进行了增强。现在,是时候选择最佳模型来驱动我们的解决方案了。在本课中,我们将不再局限于评估提示,而是进一步评估**模型本身。**您将学习如何使用 SAP Cloud SDK for AI 系统性地测试生成式 AI 中枢中可用的各种模型,在我们的 Facility Solutions Company 场景中比较它们的结果,从而做出有依据的、由业务驱动的选择。
现在,让我们针对正在解决的 Facility Solutions 问题来评估不同的模型。
使用不同模型的解决方案
继续我们的场景,我们已经学习了创建和优化提示,为客户消息分配紧急程度、情感和类别。我们还评估了这些高级提示技术,以分析它们的结果。
现在,我们将了解这些提示在生成式 AI 中枢提供的不同模型上表现如何。这对于构建稳健的解决方案非常重要,因为模型的选择会显著影响应用程序的准确性、效率和总体成本。
以下关键原因说明为什么评估和选择正确的模型对您的业务问题至关重要:
评估模型的原因 |
|
|---|---|
专精化: |
不同的模型针对特定任务进行了优化。有些擅长创意文本生成,另一些则擅长精确分类、摘要,甚至处理多模态输入(如文本和图像)。 |
性能: |
并非所有模型在每项任务上的表现都相同。比较它们有助于您找到最准确或最适合您特定需求的模型。 |
成本效益: |
通过选择恰好适合您任务的模型,您可以节省成本。有时,一个更简单、更经济的模型就能提供必要的准确性,让您在并非严格需要时避免使用更强大模型所带来的更高成本。 |
灵活性: |
不同的模型提供各不相同的能力,包括支持各种输入类型或生成多样的输出格式,从而为复杂需求提供更全面的解决方案。 |
冗余与可靠性: |
对于关键的企业应用,依赖单一模型会带来风险。评估多个模型可提供经过测试的备选方案,增强解决方案的稳健性并最大限度地减少停机时间。 |
生成式 AI 中枢代码中的不同模型
mistralai AI 模型
我们从 mistralai AI 模型开始,并使用基本提示。这些模型是生成式 AI 中枢上可用的较经济的开源、由 SAP 托管的模型。
overall_result["basic--mixtral-large-instruct"] = evalulation_full_dataset(test_set_small, f_8, _model='mistralai--mistral-large-instruct')
pretty_print_table(overall_result)
这段代码评估一个数据集并打印结果。它计算某个特定模型在小测试集上的表现,并将结果存储在 “overall_result” 字典的某个键下。随后 “pretty_print_table” 函数会格式化并打印这些结果,使评估数据清晰易读。
您将看到以下输出。
0%| | 0/20 [00:00<?, ?it/s]
is_valid_json correct_categories correct_sentiment correct_urgency
===========================================================================================================
basic--llama3.1-70b 100.0% 83.5% 30.0% 70.0%
few_shot--llama3.1-70b 100.0% 84.0% 50.0% 90.0%
metaprompting--llama3.1-70b 100.0% 90.0% 30.0% 95.0%
metaprompting_and_few_shot--llama3.1-70b 100.0% 88.5% 50.0% 90.0%
basic--mixtral-large-instruct 40.0% 34.5% 25.0% 20.0%
类似地,让我们使用 few-shot 与 meta-prompting 的组合来评估同一模型的结果。
overall_result["metaprompting_and_few_shot--mixtral-large-instruct"] = evalulation_full_dataset(test_set_small, f_13, _model='mistralai--mistral-large-instruct')
pretty_print_table(overall_result)
您将看到评估结果。
Open AI 模型
我们对 Open AI 模型执行类似的步骤。这些模型是生成式 AI 中枢上可用的最佳专有 OpenAI 模型之一。
overall_result["basic--gpt4o"] = evalulation_full_dataset(test_set_small, f_8, _model='gpt-4o')
pretty_print_table(overall_result)
0%| | 0/20 [00:00<?, ?it/s]
is_valid_json correct_categories correct_sentiment correct_urgency
=====================================================================================================================
basic--llama3.1-70b 100.0% 83.5% 30.0% 70.0%
few_shot--llama3.1-70b 100.0% 84.0% 50.0% 90.0%
metaprompting--llama3.1-70b 100.0% 90.0% 30.0% 95.0%
metaprompting_and_few_shot--llama3.1-70b 100.0% 88.5% 50.0% 90.0%
basic--mixtral-large-instruct 40.0% 34.5% 25.0% 20.0%
metaprompting_and_few_shot--mixtral-large-instruct 80.0% 71.0% 40.0% 75.0%
类似地,让我们使用 few-shot 与 meta-prompting 的组合来评估同一模型的结果。
overall_result["metaprompting_and_few_shot--gpt4o"] = evalulation_full_dataset(test_set_small, f_13, _model='gpt-4o')
pretty_print_table(overall_result)
您将看到评估结果。
Gemini 模型
我们对 Gemini 模型执行类似的步骤。这些模型是生成式 AI 中枢上可用的最佳 Google 模型。
overall_result["basic--gemini-2.5-flash"] = evalulation_full_dataset(test_set_small, f_8, _model='gemini-2.5-flash')
pretty_print_table(overall_result)
您将看到以下输出:
0%| | 0/20 [00:00<?, ?it/s]
is_valid_json correct_categories correct_sentiment correct_urgency
=====================================================================================================================
basic--llama3.1-70b 100.0% 83.5% 30.0% 70.0%
few_shot--llama3.1-70b 100.0% 84.0% 50.0% 90.0%
metaprompting--llama3.1-70b 100.0% 90.0% 30.0% 95.0%
metaprompting_and_few_shot--llama3.1-70b 100.0% 88.5% 50.0% 90.0%
basic--mixtral-large-instruct 40.0% 34.5% 25.0% 20.0%
metaprompting_and_few_shot--mixtral-large-instruct 80.0% 71.0% 40.0% 75.0%
basic--gpt4o 100.0% 89.0% 35.0% 55.0%
metaprompting_and_few_shot--gpt4o 100.0% 91.5% 60.0% 100.0%
basic--gemini-2.5-flash 100.0% 91.0% 30.0% 60.0%
您可以看到这些输出的结果。
类似地,让我们使用 few-shot 与 meta-prompting 的组合来评估同一模型的结果。
overall_result["metaprompting_and_few_shot--gemini-2.5-flash"] = evalulation_full_dataset(test_set_small, f_13, _model='gemini-2.5-flash')
pretty_print_table(overall_result)
您可以看到评估结果。
0%| | 0/20 [00:00<?, ?it/s]
is_valid_json correct_categories correct_sentiment correct_urgency
=====================================================================================================================
basic--llama3.1-70b 100.0% 83.5% 30.0% 70.0%
few_shot--llama3.1-70b 100.0% 84.0% 50.0% 90.0%
metaprompting--llama3.1-70b 100.0% 90.0% 30.0% 95.0%
metaprompting_and_few_shot--llama3.1-70b 100.0% 88.5% 50.0% 90.0%
basic--mixtral-large-instruct 40.0% 34.5% 25.0% 20.0%
metaprompting_and_few_shot--mixtral-large-instruct 80.0% 71.0% 40.0% 75.0%
basic--gpt4o 100.0% 89.0% 35.0% 55.0%
metaprompting_and_few_shot--gpt4o 100.0% 91.5% 60.0% 100.0%
basic--gemini-2.5-flash 100.0% 91.0% 30.0% 60.0%
metaprompting_and_few_shot--gemini-2.5-flash 100.0% 92.5% 55.0% 90.0%
注意
您可能会得到与这里所示响应略有不同的响应,本学习旅程中展示的所有其余模型响应也是如此。
当您在自己的机器上执行相同的提示时,由于模型的概率性本质、温度设置以及非确定性架构,模型会产生不同的输出,即使设置稍有变化或内部状态发生偏移,也会导致不同的响应。
练习
在后续练习中,您将探索如何利用 SAP 生成式 AI 中枢中的模型库,为您的业务需求选择最优模型。
不同模型的评估指南
在 SAP 生成式 AI 中枢中选择模型时,定价和各种因素起着关键作用。主要考虑因素包括:
成本效益: 评估一个更小、更经济的模型能否为您的特定任务提供所需的性能。将模型成本与预期投资回报进行权衡至关重要,因为有效的解决方案并不总是需要最昂贵的模型。有关生成式 AI 中枢中的定价详情,请参阅 SAP 注释 3437766 - 生成式 AI 模型的可用性 和 3505347 - 编排 以了解生成式 AI 中枢中的定价详情。
模型更新和新能力: 使用 3437766 注释分析可用模型的技术细节,包括 token 换算率、速率限制和弃用计划。该注释还列出了最新的生成式 AI 中枢模型,例如 Claude 和 SAP-RPT-1 模型,帮助您将行业标准能力集成到 AI 解决方案中。
可扩展性: 考虑模型的定价和基础设施能多容易地随着应用程序的增长而扩展。生成式 AI 中枢中提供的基于订阅的模型可提供可预测的成本,并旨在支持可扩展的 AI 开发与部署。
性能与成本的平衡: 高性能模型通常成本更高。组织必须评估更强大模型带来的增量性能提升是否真正值得为其特定应用及其业务价值付出额外费用。有时,性能略低但便宜得多的模型能提供更好的总体价值。
灵活性: 寻找能够根据波动的使用模式或不断演变的 AI 需求进行调整的定价和模型选项。这种适应性对于在动态的企业环境中优化支出至关重要。
通过考虑这些指南,企业可以就部署哪些生成式 AI 模型做出明智决策,在成本、性能以及与其 SAP 集成解决方案的战略契合度之间实现最佳平衡。
评估小结
我们了解了生成式 AI 中枢如何解决业务问题,并学习了它用于支持自定义构建的 AI 解决方案的功能和选项。
在整个课程中,您已对这一流程有了全面的理解。我们踏上了一段迭代之路:
从在 SAP AI Launchpad 中创建基本提示开始。
通过使用 SAP Cloud SDK for AI 重新创建提示和交互来扩展我们的解决方案。
通过系统性评估建立基线。
使用诸如 Few-shot Prompting 和 Meta-prompting 等高级技术(甚至结合多模态输入)提升提示的准确性和有效性。
最后,我们评估了生成式 AI 中枢提供的各种模型,比较它们的性能、成本以及对我们的特定业务需求的适用性。
例如,在我们的 Facility Solutions Company 场景中,评估清楚地表明,将 few-shot 提示与高效、易于获取的模型相结合,在为客户电子邮件分配紧急程度、情感和类别方面,实现了准确性、成本和可扩展性的最佳平衡。这确保了输出精确,并可供组织内的其他应用程序直接使用,从而显著提升客户服务和运营效率。
SAP 生成式 AI 中枢使您能够开发、部署和管理自定义构建的 AI 解决方案,以编程方式增强您现有的业务应用程序,推动整个企业的创新。
延续前面讨论的场景,我们创建了可为客户消息分配紧急程度、情感和类别的提示和提示模板,这些提示可在软件中使用。
我们使用了 few-shot 技术来获得更好的提示。
我们使用了提示模板来帮助扩展解决方案。
任务 1:使用模型库访问不同模型
我们将从探索模型库开始。
步骤
导航到**模型库。您将看到模型库界面。 模型库提供生成式 AI 中枢中可用模型的全面信息,以支持明智的决策。要探索可用模型及其元数据,请使用目录模式。要利用基准数据来指导决策,请使用排行榜模式。**有关特定模型的详细信息(包括数据输入类型、成本详情以及可用的指标),请参阅其模型卡片。
您可以应用筛选器,例如能力、输入类型、模型提供者等。
选择排行榜。
根据您的业务需求选择任意条件。例如,选择 **ChatBot Arena 得分。**您可以将鼠标悬停在任意列上以了解它们。
选择该列并点击降序排序。 您可以看到**模型评分。**类似地,您可以在“图表”选项中比较不同基准的评分。
注意
您可以看到生成式 AI 中枢中提供的所有模型。不过,本系统配置为仅允许少数选定的模型。这些模型是:GP4.1 nano、GPT4o-mini、Gemini 2.0 Flash Lite 和 Mistral Small Instruct
返回目录模式,并在“目录”选项卡中搜索并选择 GPT 4.1 nano。
将显示模型卡片。这些卡片提供有关模型的所有详细信息,包括指标、成本和属性。
您可以直接从模型库部署模型或使用已部署的模型。根据您的需要选择 Use in Chat 或 Use in Prompt Editor 选项。这里我们将选择 Use in Chat 选项。
在聊天中使用以下提示:
"<System role>
You are an expert customer service analyst for a facility management company. Your task is to analyze incoming customer messages and extract specific attributes for automated processing.
For 'urgency', classify the message as one of: `low`, `medium`, or `high`.
For 'sentiment', classify the message as one of: `positive`, `neutral`, or `negative`.
For 'categories', assign a list of the best matching support tags from the following predefined list:
`facility_management_issues`, `cleaning_services_scheduling`, `general_inquiries`, `specialized_cleaning_services`, `routine_maintenance_requests`, `emergency_repair_services`, `sustainability_and_environmental_practices`, `training_and_support_requests`, `quality_and_safety_concerns`, `customer_feedback_and_complaints`.
Your complete response MUST be a valid JSON string, ready for parsing by an application. It should contain ONLY the keys 'urgency', 'sentiment', and 'categories'. Do not include any other text, explanations, or formatting like markdown code blocks (e.g., ```json). Ensure there are no newlines or unnecessary white spaces outside the JSON structure.
<User role>.
Analyze the following message:
Subject: Urgent HVAC System Repair Needed
Dear Support Team,
I hope this message finds you well. My name is [Sender], and I am reaching out to you from [Residential Complex Name], where I have been residing for the past few years. I have always appreciated the meticulous care and attention your team provides in maintaining our facilities.
However, I am currently facing a pressing issue with the HVAC system in my apartment. Over the past few days, the system has been malfunctioning, resulting in inconsistent temperatures and, at times, complete shutdowns. Given the current weather conditions, this has become quite unbearable and is affecting my daily routine significantly.
I have attempted to troubleshoot the problem by resetting the system and checking the thermostat settings, but these efforts have not yielded any improvement. The situation seems to be beyond my control and requires professional intervention.
I kindly request that a repair team be dispatched immediately to address this urgent issue. The urgency of the matter cannot be overstated, as it is impacting not only my comfort but also my ability to carry out daily activities effectively.
Thank you for your prompt attention to this matter. I look forward to your swift response and resolution.
Best regards,
[Sender]"
复制该消息并粘贴到聊天中,然后点击“发送”。您将看到响应。
您可以利用聊天界面进一步分析响应,例如使用以下提示。
"Analyze this response further to add a field for "key concern" in JSON. Ensure correct JSON format."
您将看到响应。 类似地,您可以查看其他模型的结果,并为您的用例选择最佳模型。
任务 2:使用提示编辑器访问不同模型
我们将使用在前面练习中创建的提示模板的最新版本。这是带有变量及其默认值的最新 few-shot 提示版本。我们将用不同的模型执行该提示模板。
步骤
确保您已登录到生成式 AI 中枢。
选择 Prompt Management,然后选择 Templates。
选择 All 按钮。您可以在此处看到您的模板。您也可以搜索您的模板。
选择该模板的最新版本,即 5.0.0。确保您选择了您的模板以及模板中正确的时间戳。一个好的做法是在使用模板之前先阅读它。
选择提示模板,然后点击 **Open in Prompt Editor。**您的提示已可使用。
滚动到 Model Configuration 选项卡。
点击 Selected Model。
将显示 Model Selection 对话框。
选择 GPT-4o Mini。
运行提示。注意响应中的差异。 类似地,选择 Mistral AI 和 GPT4o nano 模型并评估结果。
注意
如果某个特定模型运行不正常,您可以使用其他模型继续该练习。 您已经在生成式 AI 中枢中测试了各种模型,并使用一致的提示模板从成本、性能、可扩展性和灵活性方面评估 LLM。您可以在一致的框架内评估结果,并评估企业生成式 AI 任务的成本与性能。 您需要权衡使用高级模型的成本与预期投资回报。 有关生成式 AI 中枢中的定价详情,请参阅 SAP 注释 3437766 - 生成式 AI 模型的可用性 和 3505347 - 编排。
本课其余配图










本课其余配图










本课其余配图










本课其余配图









