Generative AI Apps with LangChain and Python A Project-Based Approach to Building Real-World LLM Apps (Rabi Jay)(Z-Library)
code
No Description
230
Views
0
Downloads
0.00
Total Donations
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
Generative AI Apps with LangChain and Python A Project-Based Approach to Building Real-World LLM Apps — Rabi Jay
Page
2
Generative AI Apps with LangChain and Python A Project-Based Approach to Building Real-World LLM Apps Rabi Jay
Page
3
Generative AI Apps with LangChain and Python: A Project-Based Approach to Building Real-World LLM Apps ISBN-13 (pbk): 979-8-8688-0881-4 ISBN-13 (electronic): 979-8-8688-0882-1 https://doi.org/10.1007/979-8-8688-0882-1 Copyright © 2024 by Rabi Jay This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Melissa Duffy Development Editor: James Markham Coordinating Editor: Gryffin Winkler Cover designed by eStudioCalamar Cover image by Rawpixel.com on Freepik Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub (https://github.com/Apress). For more detailed information, please visit https://www.apress.com/gp/services/source-code. If disposing of this product, please recycle the paper Rabi Jay Pennington, NJ, USA
Page
4
(This page has no text content)
Page
5
(This page has no text content)
Page
6
(This page has no text content)
Page
7
(This page has no text content)
Page
8
(This page has no text content)
Page
9
(This page has no text content)
Page
10
(This page has no text content)
Page
11
(This page has no text content)
Page
12
(This page has no text content)
Page
13
(This page has no text content)
Page
14
(This page has no text content)
Page
15
(This page has no text content)
Page
16
(This page has no text content)
Page
17
xvii About the Author Rabi Jay has over 15 years of experience driving digital transformation with a unique ‘‘acumen. His background as a Java and SAP ABAP developer provides insights into the enterprise systems LLMs often needed to integrate with. As a leader in Deloitte’s Dig’ital/Cloud Native practice, he has gained cross-industry experience applying AI solutions, positioning him to identify where LLMs offer the greatest potential for business impact. He is passionate about making complex technology accessible, leading him to authoring the books SAP NetWeaver Portal Technology and Enterprise AI in the Cloud along with regular contributions to industry publications. His role as a technical reviewer for Large Language Model–Based Solutions and as Vice President at HCL America, focused on digital transformation, demonstrates his active engagement in the LLM field. Additionally, he runs a LinkedIn newsletter ("Enterprise AI Transformation") and free LinkedIn course (“Generative AI for Business Innovation”).
Page
18
xix Murali Krishnan is a hands-on software leader and startup founder with a passion for building efficient and revenue-generating businesses. He has 20+ years of experience at Microsoft (B2B, B2C) followed by an executive stint at Starbucks (B2C). As a cofounder, Murali led fundraising, product, customer success, marketing, and sales effort at RapL, a mobile-first and AI-driven adaptive microlearning platform. With 30+ US patents, he has a proven ability to innovate in cutting-edge tech (cloud, AI/ML, mobile, big data). Murali also mentors, assists, and advises startup founders. He lives in Seattle with his family. He enjoys running, biking, reading, and cooking. Shivakumar Gopalakrishnan has over 25 years of experience in software development, DevOps, SRE, and platform engineering. He has worked in various industries, from healthcare enterprises to consumer-facing web-scale companies. He founded a startup, was a key architect within a Fortune 1000 company, and is currently a Principal Architect at BD. He is a coauthor of Hands-on Kubernetes on Azure and the author of Kubernetes for Job Seekers and Modern Python Programming using ChatGPT. About the Technical Reviewers
Page
19
xx Keerthi Bharath is an accomplished thought leader in the AI industry. He has experience running numerous startups and leading AI projects in MNCs. He is also an investor and mentor to companies. He is an alumnus of Syracuse University, New York, and College of Engineering, Guindy, Chennai. abouT The TeChniCal RevieweRs
Page
20
1© Rabi Jay 2024 R. Jay, Generative AI Apps with LangChain and Python, https://doi.org/10.1007/979-8-8688-0882-1_1 CHAPTER 1 Introduction to LangChain and LLMs Welcome to the world of LangChain and LLMs, where you will learn how to build generative AI applications using one of the most popular generative AI application development frameworks, namely, LangChain. You will learn how to tap into the vast knowledge of these highly capable large language models, or LLMs, as we often call them. Together, we are going to explore how powerful LLMs like GPT-4, PaLM, and Gemini can be accessed with LangChain to develop some amazing, intelligent, and real-world applications that feel almost human-like. The power of LangChain lies in its ability to make the power of large language models (LLMs) easily accessible to us to build real-world applications. Whether you are a veteran coder or just starting out, you are going to find LangChain refreshingly easy to use. It is that ease of coding that got me hooked onto LangChain. I hope you will be attracted to it as well once you start discovering how easy it is, as you start learning from practical examples throughout the book. The beauty of it is that you don’t even need to be a machine learning guru or data science expert to leverage its capabilities.
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# Generative AI Apps with LangChain and Python: A Project-Based Approach to Building Real-World LLM Apps
## 【One-Line Pitch】
A hands-on, project-driven guide for Python developers who want to build production-ready generative AI applications using LangChain, covering everything from LLM API integration to advanced agent architectures—no machine learning PhD required.
## 【Book Arc】
- **Opening (~0%–11%)**: Introduces LangChain and LLMs, explaining why the framework makes powerful models like GPT-4, PaLM, and Gemini accessible to everyday developers. Covers the LLM application development workflow and sets up the project-based learning approach.
- **Early (~11%–30%)**: Dives into integrating LLM APIs with LangChain, comparing direct API usage versus the framework approach. Discusses business and technical benefits, development complexity, scalability challenges, and common error handling. Introduces development playgrounds (LangChain Playground, OpenAI API Playground, Hugging Face Spaces, Colab, Kaggle).
- **Early (~30%–37%)**: Explores open-source models including Meta AI models (LLaMA via Hugging Face and PyTorch), plus an overview of open-source model capabilities and key concepts.
- **Middle (~37%–55%)**: Covers prompt engineering for creative content—why it matters, scalability needs, and step-by-step methodology. Introduces LangChain chains: LCEL chains, legacy chains, and their components. Includes practical applications like conversational apps (ConversationChain), Q&A apps (RetrievalQA), document processing (MapReduceChain), and complex workflows using SequentialChain (customer support, content generation, fraud detection).
- **Late (~55%–78%)**: Focuses on text splitting techniques (recursive splitting, CodeTextSplitter, token-based splitting), vector stores, text embedding models with caching, building information retrieval systems, and retrievers. Transitions into agents—building with LangGraph, agent types, and criteria for choosing between Tool Calling, OpenAI Tools, Structured Chat, ReAct, and Self-Ask agents.
- **Ending (~78%–100%)**: Wraps up with advanced agent capabilities and final considerations for production deployment, closing with author background and technical reviewer notes.
## 【Key Takeaways】
- **LangChain lowers the barrier to LLM app development** (Opening): You don't need to be a machine learning expert or data scientist to build capable generative AI applications—practical examples throughout the book demonstrate this accessibility.
- **Direct LLM API vs. LangChain is a strategic trade-off** (Early): Direct APIs offer simplicity but introduce development complexity, integration challenges, and generic response issues; LangChain streamlines data integration and scalability.
- **Open-source models are viable alternatives** (Early): LLaMA and other open-source models can be called via Hugging Face and PyTorch, offering flexibility beyond proprietary APIs like GPT-4 and PaLM.
- **Prompt engineering is a scalable discipline** (Middle): Following structured prompt engineering steps ensures consistent, high-quality outputs—critical when moving from single prompts to production-scale applications.
- **Chains compose LLM capabilities into workflows** (Middle): Understanding LCEL versus legacy chains and their components enables building everything from simple conversational apps to multi-step pipelines like fraud detection and content generation.
- **Text splitting and embeddings are the backbone of RAG** (Late): Recursive splitting, CodeTextSplitter, and token-based approaches, combined with vector stores and cached embeddings, power effective information retrieval systems.
- **Agent selection depends on use case criteria** (Late): Choosing between Tool Calling, ReAct, Structured Chat, and Self-Ask agents requires understanding their strengths—LangGraph enables enhanced agent capabilities for complex scenarios.
## 【Reading Tips】
- **Skim the early chapters if you're already familiar with LLM APIs**: Chapters 1–2 cover fundamentals and API comparisons; focus on the playground sections and error-handling code if you're experienced.
- **Deep-read the chains and agents chapters**: These are the core value—the SequentialChain use cases (customer support, content generation, fraud detection) are particularly instructive for real-world architecture.
- **Pay attention to code walk-throughs**: The text splitting, embeddings, and information retrieval sections include fully working code examples—reproduce them rather than just reading.
- **Use the review questions and glossaries**: Each chapter includes review questions with answers, key takeaways, and glossaries—these are excellent for reinforcing learning and quick reference.
- **Note that excerpts are table-of-contents heavy**: The sample chunks are mostly TOC fragments, so actual code and explanations will be richer in the full book—expect more depth than the excerpts suggest.
## 【Coverage Limits】
This guide is based on table-of-contents excerpts and chapter overviews; detailed code implementations, specific API examples, and full project walk-throughs are not covered in the source material.
##
Passage locations
Page 3
s or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Melissa Duffy Developmen...
View in text
Excerpt 4
174 Table of ConTenTs viii Few-Shot Prompt Template181 Crafting a Few-Shot Prompt Template for Question Answering 182 Output Parsers 191 Types of Output Pars...
View in text
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later
Tip the Site
Scan the WeChat Pay or Alipay code to tip. No login required.
WeChat Pay
Alipay