Skip to Content
Databricks 上生成式人工智能的实用 MLflow 指南 (Chinese Edition)
book

Databricks 上生成式人工智能的实用 MLflow 指南 (Chinese Edition)

by Nuwan Ganganath, Julie Nguyen, Chang Shi Lim
August 2026
Intermediate
336 pages
4h 30m
Chinese
O'Reilly Media, Inc.
Content preview from Databricks 上生成式人工智能的实用 MLflow 指南 (Chinese Edition)

第 8 章. 使用 MLflow部署 生成式人工智能 (GenAI) 应用程序

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

在上一章中,我们将 Unity Airways 助手从一个基本的工具调用代理升级为功能更强大的代理,并将其注册到 Unity Catalog 中。现在,我们的代理已经构建完成并安全存储,是时候将其推向现实世界,让它真正开始为用户提供帮助了。

本章将重点介绍下一步:部署。我们将探讨 MLflow 如何管理您的 AI 应用程序的生命周期。在此过程中,MLflow 用于在 Databricks 上部署、管理和版本控制您所开发代理的特定组件将大显身手,并帮助您将应用程序可靠地从开发环境迁移到生产环境。

在将我们的 Unity Airways 助手“ ”投入运营的过程中,我们将逐步讲解正确实现代理生产化所需的各个步骤(参见图 8-1):

  1. 将代理部署到端点以供下游使用

  2. 配置 Unity AI Gateway 以实现端点访问控制和速率限制

  3. 添加 AI 防护措施,以监控与 Unity Airways 助手相关的查询

  4. 根据生产环境最佳实践,为代理、工具和数据配置身份验证方法

  5. 采用 LLMOps 最佳实践来应对生产环境中的各类挑战

这些步骤将确保您为项目做出正确的架构决策,从而使部署既高效又安全,并符合相关规范。

Diagram illustrating the steps for deploying an AI application, highlighting the inclusion of an AI gateway and guardrails for security before generating a response from a traveler query.
图 8-1. 使用生产级组件将我们的代理投入生产
注意

鉴于代理的开发具有迭代性,这一多步骤流程将根据需要重复执行,以确保在投入生产环境使用前建立起适当的安全防护层。部署是获得首个可用的AI应用程序的第一步,但随着我们对AI应用程序进行更多增强,重新部署是必然的。

部署到 Databricks 模型服务

既然我们在前几章中已经完成了代理的注册和测试,接下来就将其部署到 Databricks 上。我们可以使用 Mosaic AI Agent Framework 中的函数agents.deploy(),仅需一行代码即可完成代理的部署。Mosaic AI Agent Framework是一套工具集,旨在帮助从业者构建和部署高质量的生成式 AI 应用程序,确保其输出结果经过持续测量和评估,具有准确性、安全性并受有效治理。以下是我们的示例:

from databricks import agents
agents.deploy(
   model_name=UC_MODEL_NAME,
   model_version=uc_registered_model_info.version,
   scale_to_zero=True,
   environment_vars={
	"API_TOKEN": "{{secrets/my_scope/api_token}}",
	"APP_ENV": "dev"
   },
   deploy_feedback_model=True
)

agents.deploy()函数具有以下参数:

model_name

这是该模型在 Unity Catalog 中的注册名称。

model_version

此参数指定要部署的已注册模型的版本号。

scale_to_zero

当设置为True 时,模型服务端点在空闲时会自动缩减至零,从而降低成本,但随后进行查询时会导致短暂的启动延迟。建议在开发部署中使用此设置,而在生产工作负载中应将其设为 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

人工智能系统性能工程 (Chinese Edition)

人工智能系统性能工程 (Chinese Edition)

Chris Fregly

Publisher Resources

ISBN: 0642572444167