Statistics
3
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-04-08
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
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.

Generative AI Apps with LangChain and Python A Project-Based Approach to Building Real-World LLM Apps — Rabi Jay
Generative AI Apps with LangChain and Python A Project-Based Approach to Building Real-World LLM Apps Rabi Jay
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
iii Table of Contents About the Author ��������������������������������������������������������������������������������xv About the Technical Reviewers ��������������������������������������������������������xvii Chapter 1: Introduction to LangChain and LLMs ����������������������������������1 Understanding LangChain �������������������������������������������������������������������������������������2 A Simple Generative App Using LangChain �����������������������������������������������������3 What Are LLMs, and Why Are They Important? ������������������������������������������������6 Examples of LLMs �������������������������������������������������������������������������������������������7 Why Is LangChain Important? �������������������������������������������������������������������������������8 Simplifies LLM App Development and Boosts Productivity �����������������������������8 Modular and Scalable Architecture �����������������������������������������������������������������9 Open Source Support and Community Collaboration ������������������������������������10 No Cost Barrier ����������������������������������������������������������������������������������������������11 Real-World Examples of LangChain ��������������������������������������������������������������������11 Personalized Responses Through Prompt Engineering ���������������������������������11 Building Data-Aware Decision-Making Apps �������������������������������������������������13 Building Context-Aware Applications ������������������������������������������������������������14 Developing RAG-Based Apps �������������������������������������������������������������������������15 Building Agentic Apps ������������������������������������������������������������������������������������17 Why These Features Matter ���������������������������������������������������������������������������19 Integrating LLMs with LangChain �����������������������������������������������������������������������20 Simplified Integration with Multiple LLMs �����������������������������������������������������22 Exploring Core Components of LangChain ����������������������������������������������������������23
iv LLM Application Development Workflow �������������������������������������������������������������26 Key Takeaways ����������������������������������������������������������������������������������������������������31 Review Questions �����������������������������������������������������������������������������������������������32 Answers ���������������������������������������������������������������������������������������������������������34 Looking Ahead ����������������������������������������������������������������������������������������������������35 Bring Your Ideas to Life with LangChain ��������������������������������������������������������35 Glossary of Technical Terms ��������������������������������������������������������������������������������36 Further Reading ��������������������������������������������������������������������������������������������������38 Chapter 2: Integrating LLM APIs with LangChain �������������������������������39 Understanding LLM APIs �������������������������������������������������������������������������������������40 Business Benefits of Using LLM APIs for Generative AI ���������������������������������40 Technical Benefits of Using LLM APIs ������������������������������������������������������������42 Addressing Challenges in LLM API Integration ����������������������������������������������43 Additional Things to Consider ������������������������������������������������������������������������46 Using Direct LLM API vs� LangChain �������������������������������������������������������������������48 Development Complexity �������������������������������������������������������������������������������48 Integration and Scalability Challenges ����������������������������������������������������������49 Generic Response Issue ��������������������������������������������������������������������������������49 Streamlining Data Integration �����������������������������������������������������������������������51 Choosing Between Direct LLM API Use and LangChain ���������������������������������51 Using LangChain ��������������������������������������������������������������������������������������������53 Preparing Your Dev Environment ������������������������������������������������������������������������55 Step 1: Obtaining OpenAI API Keys ����������������������������������������������������������������55 Step 2: Setting Up the Python Development Environment �����������������������������57 Congratulations! ��������������������������������������������������������������������������������������������61 Exercise 1: Calling an LLM API Directly ���������������������������������������������������������������61 Exercise 2: Using LangChain for Enhanced Flexibility �����������������������������������65 Table of ConTenTs
v Key Takeaways ����������������������������������������������������������������������������������������������������70 Start Creating with LangChain �����������������������������������������������������������������������72 Glossary of Technical Terms ��������������������������������������������������������������������������������72 Further Reading ��������������������������������������������������������������������������������������������������73 Chapter 3: Building Q&A and Chatbot Apps ����������������������������������������75 LangChain Framework Components �������������������������������������������������������������������75 Development �������������������������������������������������������������������������������������������������76 Production �����������������������������������������������������������������������������������������������������82 Deployment Using LangServe �����������������������������������������������������������������������84 LangChain Ecosystem �����������������������������������������������������������������������������������������84 Using LangChain Models with LLMs �������������������������������������������������������������������89 Model IO: The Core Functionality of LangChain ���������������������������������������������89 Large Language Models (LLMs) with LangChain �������������������������������������������90 Building a Simple Q&A Application ���������������������������������������������������������������������91 Full End-to-End Working Code �����������������������������������������������������������������������93 Building a Conversational App ����������������������������������������������������������������������������94 Difference Between the Q&A and Chatbot Example��������������������������������������������98 Error Handling and Troubleshooting ��������������������������������������������������������������������99 Understanding Common Errors �������������������������������������������������������������������100 Implementing Error Handling in Code����������������������������������������������������������100 Diagnosing and Resolving Common Issues �������������������������������������������������101 Development Playground ����������������������������������������������������������������������������������103 LangChain Playground ���������������������������������������������������������������������������������103 OpenAI API Playground ��������������������������������������������������������������������������������104 Hugging Face Spaces ����������������������������������������������������������������������������������104 Colab Notebooks������������������������������������������������������������������������������������������104 Kaggle Notebooks����������������������������������������������������������������������������������������105 Maximize Your Learning Through Experimenting ����������������������������������������������105 Table of ConTenTs
vi Experiment Freely ����������������������������������������������������������������������������������������105 Document Your Findings ������������������������������������������������������������������������������105 Share and Collaborate ���������������������������������������������������������������������������������106 Review Questions ���������������������������������������������������������������������������������������������106 Answers �������������������������������������������������������������������������������������������������������108 Additional Review ����������������������������������������������������������������������������������������108 Key Takeaways ��������������������������������������������������������������������������������������������������109 Glossary ������������������������������������������������������������������������������������������������������������110 Further Reading ������������������������������������������������������������������������������������������������111 Chapter 4: Exploring Large Language Models (LLMs) ����������������������113 OpenAI’s Models �����������������������������������������������������������������������������������������������114 GPT: The Next-Generation Language Models �����������������������������������������������114 Getting Started with GPT (Code Snippet) �����������������������������������������������������114 Codex: Your AI Coding Assistant ������������������������������������������������������������������115 DALL-E 2: The Image Generation Wizard �����������������������������������������������������116 Google’s AI Model Overview ������������������������������������������������������������������������������120 Language and Chat Models �������������������������������������������������������������������������120 Codey Suite for Code-Related Tasks ������������������������������������������������������������131 Text and Image Processing Models �������������������������������������������������������������132 Multimodal and Security Models �����������������������������������������������������������������132 Speech Models ��������������������������������������������������������������������������������������������133 Anthropic’s Claude AI Models����������������������������������������������������������������������������133 Claude 3 Model Family: Claude 3 Opus, Sonnet, and Haiku ������������������������134 Key Features of Claude 3 Models ����������������������������������������������������������������134 Getting Started with Code ���������������������������������������������������������������������������135 Overview of Cohere AI Models ��������������������������������������������������������������������������139 Practical Example: Using Cohere’s Command Model (Code Snippet) ����������140 Table of ConTenTs
vii Meta AI Models �������������������������������������������������������������������������������������������������143 Calling the LLaMA Model Using Hugging Face ��������������������������������������������144 PyTorch ��������������������������������������������������������������������������������������������������������152 Review Questions ���������������������������������������������������������������������������������������������152 Answers �������������������������������������������������������������������������������������������������������155 Key Learnings ���������������������������������������������������������������������������������������������������155 Glossary ������������������������������������������������������������������������������������������������������������156 Overview and Capabilities of Open Source Models �������������������������������������156 Definitions of Key Terms and Concepts �������������������������������������������������������158 Further Reading ������������������������������������������������������������������������������������������������160 Chapter 5: Mastering Prompts for Creative Content �������������������������161 Importance of Prompt Engineering �������������������������������������������������������������������161 Why Prompt Engineering? ���������������������������������������������������������������������������162 Need for Scalability �������������������������������������������������������������������������������������163 Prompt Engineering Steps ��������������������������������������������������������������������������������164 What Is the Goal?�����������������������������������������������������������������������������������������164 Composing Your Prompts ����������������������������������������������������������������������������165 Selecting Your Examples �����������������������������������������������������������������������������167 Testing Your Prompts �����������������������������������������������������������������������������������167 Reviewing the Outputs ��������������������������������������������������������������������������������167 Fine-Tuning Your Prompts ���������������������������������������������������������������������������167 Embracing Iteration �������������������������������������������������������������������������������������169 Deploying Your Prompts ������������������������������������������������������������������������������169 Monitoring and Maintaining ������������������������������������������������������������������������169 Components of a Prompt ����������������������������������������������������������������������������������169 Prompt Templates ����������������������������������������������������������������������������������������170 Advantages of Using Prompt Templates ������������������������������������������������������173 Example Selectors ���������������������������������������������������������������������������������������174 Table of ConTenTs
viii Few-Shot Prompt Template�������������������������������������������������������������������������������181 Crafting a Few-Shot Prompt Template for Question Answering ������������������182 Output Parsers ��������������������������������������������������������������������������������������������������191 Types of Output Parsers ������������������������������������������������������������������������������192 Practical Example: Using PydanticOutputParser for Movie Data �����������������193 OutputFixingParser ��������������������������������������������������������������������������������������198 ChatPrompt Templates ��������������������������������������������������������������������������������������199 Building the Chat Prompt Template �������������������������������������������������������������199 Case Study: Streamlining Customer Service �����������������������������������������������������203 Initial Design and Customization of Prompts �����������������������������������������������205 Initial Design ������������������������������������������������������������������������������������������������205 Advanced Engineering ���������������������������������������������������������������������������������206 Impact ���������������������������������������������������������������������������������������������������������206 Key Takeaways ��������������������������������������������������������������������������������������������������207 Review Questions ���������������������������������������������������������������������������������������������207 Answers �������������������������������������������������������������������������������������������������������209 Further Reading ������������������������������������������������������������������������������������������������210 Chapter 6: Building Intelligent Chatbots and Automated Analysis Systems Using Chains ��������������������������������������������������������211 Introduction to LangChain Chains ���������������������������������������������������������������������211 What Are LangChain Chains? ����������������������������������������������������������������������212 Why Are Chains Important in Generative AI? �����������������������������������������������213 Understanding the Components of Chains ��������������������������������������������������������214 Higher-Level Components of a Chain App ���������������������������������������������������214 Internal Components in a Step ��������������������������������������������������������������������216 Types of Chains �������������������������������������������������������������������������������������������������216 LCEL Chains �������������������������������������������������������������������������������������������������217 Legacy Chains ���������������������������������������������������������������������������������������������217 Table of ConTenTs
ix Difference Between LCEL and Legacy Chains ���������������������������������������������������218 LCEL Chain Example ������������������������������������������������������������������������������������218 Legacy Chain Example���������������������������������������������������������������������������������218 When to Use Different Types of Chains �������������������������������������������������������������219 LCEL Chains �������������������������������������������������������������������������������������������������219 Legacy Chains ���������������������������������������������������������������������������������������������220 Building with LCEL Chains ��������������������������������������������������������������������������������220 Constructing LCEL Chains ���������������������������������������������������������������������������221 Customizing LCEL Chains ����������������������������������������������������������������������������222 Executing LCEL Chains ��������������������������������������������������������������������������������224 Types of LCEL Chains ����������������������������������������������������������������������������������������226 Command Generation Using Query Constructor Chain ��������������������������������227 Building with Legacy Chains �����������������������������������������������������������������������������228 Constructing Legacy Chains ������������������������������������������������������������������������229 Executing Legacy Chains �����������������������������������������������������������������������������229 Types of Legacy Chains �������������������������������������������������������������������������������������230 Building Real-World Apps with Legacy Chains �������������������������������������������������231 Document Chatbot App Using ConversationalRetrievalChain ����������������������232 Building Text Generation Apps Using LLMChain ������������������������������������������233 Building Conversational Apps with ConversationChain �������������������������������233 Building Q&A Apps Using RetrievalQA ���������������������������������������������������������234 Document Processing App with MapReduceChain ��������������������������������������235 More Complex Workflow Apps Using Chain Composition Strategies ����������������236 Data Summarization App with Sequential Chains ���������������������������������������237 SequentialChain Use Case Example 1: Customer Support Chatbot App ������238 SequentialChain Use Case Example 2: Content Generation Pipeline App ����239 SequentialChain Use Case Example 3: Automated Fraud Detection in Finance ��������������������������������������������������������������������������������������������������������240 Table of ConTenTs
x Task Allocation App Using Router Chains ����������������������������������������������������240 Sentiment Analysis App Using Conditional Chains ��������������������������������������243 Advanced Chain Techniques �����������������������������������������������������������������������������245 Handling Large Datasets with Chains ����������������������������������������������������������245 Dealing with Errors and Exceptions in Chains ���������������������������������������������247 Optimizing Chain Performance ��������������������������������������������������������������������248 Testing and Debugging Chains ��������������������������������������������������������������������249 Key Takeaways ��������������������������������������������������������������������������������������������������250 Recap of Key Concepts ��������������������������������������������������������������������������������250 Future Possibilities with LangChain Chains�������������������������������������������������251 Glossary ������������������������������������������������������������������������������������������������������������252 Review Questions ���������������������������������������������������������������������������������������������253 Answers �������������������������������������������������������������������������������������������������������256 Further Reading ������������������������������������������������������������������������������������������������257 Chapter 7: Building Advanced Q&A and Search Applications Using Retrieval-Augmented Generation (RAG) ����������������������������������259 Importance of RAG ��������������������������������������������������������������������������������������������260 How Does RAG Work? ���������������������������������������������������������������������������������������262 RAG Use Case Example �������������������������������������������������������������������������������264 Try It Yourself �����������������������������������������������������������������������������������������������265 LangChain Components �������������������������������������������������������������������������������266 Document Loaders ��������������������������������������������������������������������������������������������266 Document Loaders in Action ������������������������������������������������������������������������267 Working with PDFs ��������������������������������������������������������������������������������������269 Dealing with CSV Files ���������������������������������������������������������������������������������270 Working with JSON Files �����������������������������������������������������������������������������273 Text Splitters �����������������������������������������������������������������������������������������������������275 Table of ConTenTs
xi Fully Working Code Example for Text Splitting ��������������������������������������������276 Recursive Splitting ��������������������������������������������������������������������������������������279 CodeTextSplitter ������������������������������������������������������������������������������������������281 Splitting by Token ����������������������������������������������������������������������������������������283 Vector Stores �����������������������������������������������������������������������������������������������������285 Text Embedding Models ������������������������������������������������������������������������������������287 Code Walk-Through for Text Embeddings ����������������������������������������������������289 Caching the Embeddings �����������������������������������������������������������������������������292 Building the Information Retrieval System ��������������������������������������������������296 Calling the Vector Store Asynchronously �����������������������������������������������������299 Retrievers ����������������������������������������������������������������������������������������������������������300 Code Walk-Through for Information Retrieval ���������������������������������������������302 Indexing ������������������������������������������������������������������������������������������������������������303 Key Takeaways ��������������������������������������������������������������������������������������������������305 Review Questions ���������������������������������������������������������������������������������������������305 Answers �������������������������������������������������������������������������������������������������������308 Glossary ������������������������������������������������������������������������������������������������������������309 References ��������������������������������������������������������������������������������������������������������312 Chapter 8: Your First Agent App �������������������������������������������������������315 Introduction �������������������������������������������������������������������������������������������������������315 What Are Agents? ����������������������������������������������������������������������������������������315 Example of an Agent’s Workflow �����������������������������������������������������������������318 Agent’s Thought Process �����������������������������������������������������������������������������319 Why Agents Matter ��������������������������������������������������������������������������������������������321 Agents for Content Generation ��������������������������������������������������������������������322 Agents As Task Managers ����������������������������������������������������������������������������324 How Do Chains Differ from Agents? ������������������������������������������������������������325 Choosing Your Approach ������������������������������������������������������������������������������327 Table of ConTenTs
xii Your First End-to-End Working Agent App ���������������������������������������������������������328 Code Explanation �����������������������������������������������������������������������������������������332 Results After Running the Code �������������������������������������������������������������������334 Interpreting the Results �������������������������������������������������������������������������������336 Key Takeaways ��������������������������������������������������������������������������������������������������338 Review Questions ���������������������������������������������������������������������������������������������339 Answers �������������������������������������������������������������������������������������������������������342 Further Reading ������������������������������������������������������������������������������������������������342 Chapter 9: Building Different Types of Agents ����������������������������������345 Learning Objectives ������������������������������������������������������������������������������������������346 Designing and Implementing an Agent �������������������������������������������������������������347 Defining the Agent’s Objective ���������������������������������������������������������������������347 Concepts ������������������������������������������������������������������������������������������������������350 Agent �����������������������������������������������������������������������������������������������������������352 Agent Inputs ������������������������������������������������������������������������������������������������353 Agent Outputs ����������������������������������������������������������������������������������������������353 AgentExecutor ���������������������������������������������������������������������������������������������355 Tools and Toolkits ����������������������������������������������������������������������������������������356 Considerations ���������������������������������������������������������������������������������������������362 Building an Agent Using LangGraph for Enhanced Capabilities ������������������362 Agent Types �������������������������������������������������������������������������������������������������������366 Criteria for Choosing Agent Types ����������������������������������������������������������������366 Types of LangChain Agents ��������������������������������������������������������������������������367 Tool Calling Agent ����������������������������������������������������������������������������������������373 OpenAI Tools ������������������������������������������������������������������������������������������������378 Structured Chat Agent ���������������������������������������������������������������������������������382 ReAct Agent �������������������������������������������������������������������������������������������������387 Self-Ask Agents �������������������������������������������������������������������������������������������391 Table of ConTenTs
xiii Autonomous Decision-Making Capability ����������������������������������������������������393 Intelligent Agent Performing Tasks with Multiple Tools �������������������������������397 Creating a Retriever Tool �����������������������������������������������������������������������������399 Putting It All Together ����������������������������������������������������������������������������������400 Choosing the LLM ���������������������������������������������������������������������������������������400 Selecting the Prompt �����������������������������������������������������������������������������������401 Initializing the Agent ������������������������������������������������������������������������������������401 Creating the AgentExecutor �������������������������������������������������������������������������402 Differences Between LangChain v0�1 and v0�2 Agents �������������������������������406 Key Takeaways ��������������������������������������������������������������������������������������������������409 Review Questions ���������������������������������������������������������������������������������������������410 Answers �������������������������������������������������������������������������������������������������������412 Further Reading ������������������������������������������������������������������������������������������������413 Chapter 10: Projects: Building Agent Apps for Common Use Cases �415 Creating a Custom Agent ����������������������������������������������������������������������������������415 Loading the Language Model ����������������������������������������������������������������������416 Defining Tools ����������������������������������������������������������������������������������������������416 Creating the Prompt ������������������������������������������������������������������������������������417 Binding Tools to the Language Model ����������������������������������������������������������417 Creating the Agent ���������������������������������������������������������������������������������������418 Testing Your Agent ���������������������������������������������������������������������������������������419 Adding Memory �������������������������������������������������������������������������������������������419 Practical Use Cases for Agents �������������������������������������������������������������������������421 Customer Support Automation ��������������������������������������������������������������������421 Personalized Recommendations �����������������������������������������������������������������428 Real-Time Data Analysis and Decision- Making �������������������������������������������439 Key Takeaways ��������������������������������������������������������������������������������������������������447 Review Questions ���������������������������������������������������������������������������������������������447 Table of ConTenTs
xiv Answers �������������������������������������������������������������������������������������������������������448 Further Reading ������������������������������������������������������������������������������������������������449 Chapter 11: Building and Deploying a ChatGPT-like App Using Streamlit �����������������������������������������������������������������������451 Setting Up Your Development Environment ������������������������������������������������������452 Installing Streamlit Library ��������������������������������������������������������������������������452 Installing Python ������������������������������������������������������������������������������������������452 Installing Required Dependencies ���������������������������������������������������������������457 Building the Streamlit LangChain UI App ����������������������������������������������������������457 Components of the Streamlit App ����������������������������������������������������������������458 Steps Involved in Building the App ��������������������������������������������������������������458 Indentation Error in the Code �����������������������������������������������������������������������461 Run Your Streamlit Application ��������������������������������������������������������������������462 Testing the App ��������������������������������������������������������������������������������������������464 Deploying the LangChain Application ����������������������������������������������������������������465 Installing Git on Your System �����������������������������������������������������������������������465 Setting Up Your Identity �������������������������������������������������������������������������������468 Set Up the OpenAI Key As an Environmental Variable ���������������������������������469 Resolving Sensitive Information Issues in Your Repository �������������������������472 Preventing Email Privacy–Related Issues ����������������������������������������������������474 Deploying the App in GitHub ������������������������������������������������������������������������476 Providing Access to GitHub ��������������������������������������������������������������������������477 Deploying in the Streamlit Cloud �����������������������������������������������������������������480 Other Cloud Deployment Options �����������������������������������������������������������������482 Key Takeaways ��������������������������������������������������������������������������������������������������484 Review Questions ���������������������������������������������������������������������������������������������485 Answers �������������������������������������������������������������������������������������������������������488 Further Reading ������������������������������������������������������������������������������������������������489 Table of ConTenTs
xv Setting Up Your Development Environment �������������������������������������������������489 Running Streamlit in Your Desktop ��������������������������������������������������������������489 Installing Streamlit Library ��������������������������������������������������������������������������489 Creating and Using the Language Model �����������������������������������������������������490 Handling User Input �������������������������������������������������������������������������������������490 Chat History Initialization �����������������������������������������������������������������������������490 Deploying the Application ����������������������������������������������������������������������������491 GitHub Integration����������������������������������������������������������������������������������������491 Index �������������������������������������������������������������������������������������������������493 Table of ConTenTs
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”).
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
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
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.