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

Smorodinsky, Serj, Kennedy, Brett

  • 出版商: Manning
  • 出版日期: 2026-10-20
  • 售價: $2,250
  • 貴賓價: 9.5 折 $2,137
  • 語言: 英文
  • 頁數: 296
  • 裝訂: Quality Paper - also called trade paper
  • ISBN: 1633435016
  • ISBN-13: 9781633435018
  • 相關分類: Prompt Engineering、Large language model、Chatbot
  • 尚未上市,無法訂購

相關主題

商品描述

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

本書從第一頁起便著重實務,並以專業 AI 工程工作流程為藍本,帶領您從簡易分類器一路學習到複雜的摘要器、進階 RAG,以及具代理能力的系統。DSPy 貢獻者、書評人 Cyrus Nouroozi 指出,本書「以一個連貫一致的核心論點串起整個主題:提示程式設計是一門以資料為驅動的學科,類似於機器學習。」為了強調將提示程式設計視為工程流程,本書介紹基準評估—最佳化迴圈(baseline evaluate optimize loop),消除傳統提示設計中的猜測成分。

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

最後幾章將展示如何把 DSPy 建置成完整的代理式(agentic)管線,整合對話記憶,並透過 MCP 將代理連接至外部環境。本書共 9 章,內容精實,還介紹 DSPy v3 的尖端功能,例如 SIMBA 與 GEPA 最佳化器,協助較小型、成本更低的開放權重語言模型發揮最大效能。對任何想要建置健全、能自我改進且可投入正式環境的生成式 AI 系統的現代程式設計師而言,本書都是不可或缺的資源。

本書內容

- 使用宣告式 Python 簽章建置模組化 LLM 應用程式
- 使用 SIMBA 與 GEPA 自動化提示最佳化
- 建構嚴謹且可重複執行的指標函式,以驗證輸出結果
- 部署可靠的多跳式 RAG 系統與代理

適合讀者

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

關於作者

Serj Smorodinsky 是 DSPy 貢獻者、資料科學家與 AI 工程師,擁有超過十年的經驗,曾帶領團隊為企業客戶建置對話式 AI、對話聊天機器人及代理式工作流程。

Brett Kennedy 是資料科學家,擁有超過三十年的軟體開發經驗。他經常參與開放原始碼專案,也是《Outlier Detection in Python》的作者。

目錄

1 提示程式設計與 DSPy 簡介
2 基礎提示技術與 DSPy
3 分類使用者意圖
4 評估 DSPy 程式
5 最佳化提示範例
6 最佳化提示指令
7 自訂模組
8 摘要與更有效的指標函式
9 建立以代理式 RAG 為基礎的聊天機器人

作者簡介

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、代理式(agentic)工作流程自動化,以及 LLM 評估;他也具備豐富的實務經驗,曾帶領團隊為企業客戶建置聊天機器人與檢索增強生成(retrieval-augmented)系統。此外,他目前在 Nebius Academy(前身為 Y-Data School of Data Science)教授代理式系統與正式環境中的資料科學。

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