Building LLM Applications with Dspy: Replacing Manual Prompts with Systematic Optimization (Paperback)
暫譯: 使用 DSPy 建構 LLM 應用程式:以系統化最佳化取代手動提示詞

Smorodinsky, Serj, Kennedy, Brett

買這商品的人也買了...

相關主題

商品描述

Get the eBook free when you register your print book at Manning.

"An essential, forward-looking guide."
--Dhyey Mavani, Amherst College

DSPy (Declarative Self-improving Python), an innovative framework for prompt programming, replaces fragile and unpredictable manual prompts with clean, modular Python code that declares what a model should do, defines the inputs and response formats, and establishes clear evaluation metrics. In Building LLM Applications with DSPy, authors Serj Smorodinsky and Brett Kennedy present a systematic approach for treating prompts as programmatic artifacts rather than loose text strings, so you can build, scale, maintain, and improve complex AI applications with the structural integrity of traditional software.

Practical from page one, this book mirrors a professional AI engineering workflow, taking you from simple classifiers to complex summarizers, advanced RAG, and agentic systems. Reviewer Cyrus Nouroozi, a DSPy contributor, notes that the book "frames the whole subject around a single coherent thesis: prompt programming is a data-driven discipline analogous to machine learning." To support its strong focus on prompt programming as an engineering process, the book introduces the baseline evaluate optimize loop that eliminates the guesswork of traditional prompt design.

Production applications require verifiable, consistent metrics, which are difficult to establish with conventional prompts. This book guides you through constructing custom evaluation metrics, setting up multi-threaded test runners, and calibrating LLM-as-a-judge protocols to gather hard data. Instead of deploying prompts on a whim, you compile and optimize them against structured validation sets. The resulting programs are mathematically proven to be more accurate, more cost-effective, and remarkably resilient to underlying model drift.

The final chapters show you how to build DSPy into fully agentic pipelines, integrating conversation memories, and connecting agents to external environments via MCP. This focused 9-chapter book also introduces cutting-edge DSPy v3 features like SIMBA and GEPA optimizers to squeeze maximum performance out of smaller, cheaper open-weight language models. It is an indispensable resource for any modern programmer wanting to build robust, self-improving, and production-ready generative AI systems.

What's inside

- Build modular LLM applications using declarative Python signatures
- Automate prompt optimization using SIMBA and GEPA
- Construct rigorous, repeatable metric functions to verify outputs
- Deploy reliable, multi-hop RAG systems and agents

About the reader

This book is designed for software developers, data scientists, and AI engineers with basic Python skills.

About the author

Serj Smorodinsky is a DSPy contributor, data scientist, and AI engineer with over ten years of experience leading teams to build conversational AI, conversational chatbots, and agentic workflows for enterprise clients. Brett Kennedy is a data scientist with over thirty years of software development experience. He is a regular contributor to open-source projects and the author of Outlier Detection in Python.

Table of Contents

1 Introduction to prompt programming and DSPy
2 Basic prompting and DSPy
3 Classifying user intent
4 Evaluating DSPy programs
5 Optimizing prompt examples
6 Optimizing prompt instructions
7 Custom modules
8 Summarization and more effective metric functions
9 Creating an agentic RAG-based chatbot

註冊您在 Manning 購買的紙本書,即可免費取得電子書。

「一本不可或缺且著眼未來的指南。」
--Dhyey Mavani,Amherst College

DSPy(Declarative Self-improving Python)是一個創新的 prompt programming framework,以簡潔、模組化的 Python 程式碼取代脆弱且難以預測的手動 prompts。它能宣告模型應執行的工作、定義輸入與回應格式,並建立明確的評估指標。在《Building LLM Applications with DSPy》中,作者 Serj Smorodinsky 與 Brett Kennedy 提出一套系統化方法,將 prompts 視為程式化產物,而非鬆散的文字字串。如此一來,您便能以傳統軟體的結構完整性,建置、擴充、維護及改進複雜的 AI 應用程式。

本書從第一頁開始便著重實務,模擬專業 AI 工程工作流程,帶領您從簡單的分類器,逐步進展到複雜的摘要器、進階 RAG,以及 agentic systems。DSPy 貢獻者、書評人 Cyrus Nouroozi 指出,本書「以一個連貫一致的核心論點來闡述整個主題:prompt programming 是一門以資料為驅動的學科,其性質類似於 machine learning。」為了強調將 prompt programming 視為工程流程,本書介紹 baseline evaluate optimize loop,消除傳統 prompt 設計中的臆測與摸索。

正式上線的應用程式需要可驗證且一致的指標,但使用傳統 prompts 很難建立這類指標。本書將引導您建構自訂評估指標、設定多執行緒測試執行器,以及校準 LLM-as-a-judge 協定,以蒐集可靠的實際資料。您不再隨意部署 prompts,而是針對結構化驗證集編譯並最佳化 prompts。由此產生的程式經數學證明,能提供更高的準確度、更具成本效益的執行方式,並且對底層模型漂移具有顯著的韌性。

最後幾章將示範如何把 DSPy 建置成完整的 agentic pipelines,整合對話記憶,並透過 MCP 將 agents 連接至外部環境。本書共 9 章,內容精實,還介紹 DSPy v3 中的 SIMBA 與 GEPA optimizers 等尖端功能,協助較小型、成本較低的 open-weight language models 發揮最大效能。對於任何想要建置健壯、能自我改進且適合正式上線的 generative AI systems 的現代程式設計師而言,本書都是不可或缺的資源。

內容特色

- 使用 declarative Python signatures 建置模組化 LLM applications
- 使用 SIMBA 與 GEPA 自動化 prompt optimization
- 建構嚴謹且可重複執行的 metric functions,以驗證輸出結果
- 部署可靠的 multi-hop RAG systems 與 agents

適合讀者

本書適合具備 Python 基礎技能的軟體開發人員、資料科學家與 AI 工程師。

關於作者

Serj Smorodinsky 是 DSPy 貢獻者、資料科學家與 AI 工程師,擁有超過十年的經驗,曾帶領團隊為企業客戶建置 conversational AI、conversational chatbots 與 agentic workflows。Brett Kennedy 是資料科學家,擁有超過三十年的軟體開發經驗。他經常參與 open-source projects,也是《Outlier Detection in Python》一書的作者。

目錄

1 Prompt programming 與 DSPy 簡介
2 基本 prompting 與 DSPy
3 分類使用者意圖
4 評估 DSPy programs
5 最佳化 prompt examples
6 最佳化 prompt instructions
7 自訂 modules
8 摘要與更有效的 metric functions
9 建立以 agentic RAG 為基礎的 chatbot

以上中文內容由 AI 翻譯

作者簡介

Serj Smorodinsky is a contributor to DSPy, a data scientist, and an AI engineer with over ten years of combined experience in software development and data science. His work spans NLP for customer-service related conversational AI, agentic workflow automation, and LLM evaluation, with hands-on experience leading teams to build chatbots and retrieval-augmented systems for enterprise clients. He also teaches agentic systems and data science in production at Nebius Academy (formerly Y-Data School of Data Science).

Brett Kennedy is a data scientist with over thirty years' experience in software development and data science. He has worked in outlier detection related to financial auditing, fraud detection, and social media analysis. He previously led a research team focusing on outlier detection.

Serj Smorodinsky 是 DSPy 的貢獻者、資料科學家及 AI 工程師,在軟體開發與資料科學領域累積超過十年的經驗。他的工作涵蓋客服相關對話式 AI 的 NLP、代理式工作流程自動化,以及 LLM 評估;他也具備豐富的實務經驗,曾帶領團隊為企業客戶建置聊天機器人與檢索增強系統。他目前也在 Nebius Academy(前身為 Y-Data School of Data Science)教授代理式系統與生產環境中的資料科學。

Brett Kennedy 是資料科學家,在軟體開發與資料科學領域擁有超過三十年的經驗。他曾從事與財務稽核、詐欺偵測及社群媒體分析相關的離群值偵測工作。此前,他曾帶領一個專注於離群值偵測的研究團隊。

以上中文內容由 AI 翻譯