وبلاگ بلیان

Generative AI Apps with LangChain and Python: A Project-Based Approach to Building Real-World LLM Apps for Beginners

معرفی کتاب «Generative AI Apps with LangChain and Python: A Project-Based Approach to Building Real-World LLM Apps for Beginners» نوشتهٔ Clear، James و Rabi Jay، منتشرشده توسط نشر Apress L. P. در سال 2024. این کتاب در فرمت pdf، زبان انگلیسی ارائه شده است.

Future-proof your programming career through practical projects designed to grasp the intricacies of LangChain's components, from core chains to advanced conversational agents. This hands-on book provides Python developers with the necessary skills to develop real-world Large Language Model (LLM)-based Generative AI applications quickly, regardless of their experience level. Projects throughout the book offer practical LLM solutions for common business issues, such as information overload, internal knowledge access, and enhanced customer communication. Meanwhile, you'll learn how to optimize workflows, enhance embedding efficiency, select between vector stores, and other optimizations relevant to experienced AI users. The emphasis on real-world applications and practical examples will enable you to customize your own projects to address pain points across various industries. Developing LangChain-based Generative AI LLM Apps with Python employs a focused toolkit (LangChain, Pinecone, and Streamlit LLM integration) to practically showcase how Python developers can leverage existing skills to build Generative AI solutions. By addressing tangible challenges, you'll learn-by-be doing, enhancing your career possibilities in today's rapidly evolving landscape. What You Will Learn Understand different types of LLMs and how to select the right ones for responsible AI. Structure effective prompts. Master LangChain concepts, such as chains, models, memory, and agents. Apply embeddings effectively for search, content comparison, and understanding similarity. Setup and integrate Pinecone vector database for indexing, structuring data, and search. Build Q & A applications for multiple doc formats. Develop multi-step AI workflow apps using LangChain agents. Who This Book Is For Python programmers who aim to develop a basic understanding of AI concepts and move from LLM theory to practical Generative AI application development using LangChain; those seeking a structured guide to enhance their careers by learning to create robust, real-world LLM-powered Generative AI applications; data scientists, analysts, and experienced developers new to LLMs. Table of Contents About the Author About the Technical Reviewers Chapter 1: Introduction to LangChain and LLMs Understanding LangChain A Simple Generative App Using LangChain What Are LLMs, and Why Are They Important? Examples of LLMs Why Is LangChain Important? Simplifies LLM App Development and Boosts Productivity Modular and Scalable Architecture Open Source Support and Community Collaboration No Cost Barrier Real-World Examples of LangChain Personalized Responses Through Prompt Engineering Building Data-Aware Decision-Making Apps Building Context-Aware Applications Why Does It Matter? Developing RAG-Based Apps Examples of RAG in Action Building Agentic Apps Example: Transforming Customer Support Systems Example: Automated Content Scheduler Why These Features Matter Integrating LLMs with LangChain Simplified Integration with Multiple LLMs Exploring Core Components of LangChain LLM Application Development Workflow Key Takeaways Review Questions Answers Looking Ahead Bring Your Ideas to Life with LangChain Glossary of Technical Terms Further Reading Chapter 2: Integrating LLM APIs with LangChain Understanding LLM APIs Business Benefits of Using LLM APIs for Generative AI Technical Benefits of Using LLM APIs Addressing Challenges in LLM API Integration Security Concerns Managing LLM API Deprecation Debugging and Troubleshooting Overcoming Latency Addressing Rate Limiting and Cost Management Additional Things to Consider Choosing the Right Use Case Choosing the Right Model Prepare Your Data Evaluate Your Model Performance Using Direct LLM API vs. LangChain Development Complexity Integration and Scalability Challenges Generic Response Issue Streamlining Data Integration Choosing Between Direct LLM API Use and LangChain Direct LLM API Use Using LangChain Preparing Your Dev Environment Step 1: Obtaining OpenAI API Keys Create/Open an Account Billing Information API Key Step 2: Setting Up the Python Development Environment Google Colaboratory Install OpenAI Library Configure API Key Test the Setup Securing the API Key Using Environment Variables Securing the API Keys Using the Configuration Files Congratulations! Exercise 1: Calling an LLM API Directly Exercise 2: Using LangChain for Enhanced Flexibility Key Takeaways Start Creating with LangChain Glossary of Technical Terms Further Reading Chapter 3: Building Q&A and Chatbot Apps LangChain Framework Components Development Production Deployment Using LangServe LangChain Ecosystem Using LangChain Models with LLMs Model IO: The Core Functionality of LangChain Large Language Models (LLMs) with LangChain Types of LangChain Models Building a Simple Q&A Application Full End-to-End Working Code Building a Conversational App Difference Between the Q&A and Chatbot Example Error Handling and Troubleshooting Understanding Common Errors Implementing Error Handling in Code Diagnosing and Resolving Common Issues Development Playground LangChain Playground OpenAI API Playground Hugging Face Spaces Colab Notebooks Kaggle Notebooks Maximize Your Learning Through Experimenting Experiment Freely Document Your Findings Share and Collaborate Review Questions Answers Additional Review Key Takeaways Glossary Further Reading Chapter 4: Exploring Large Language Models (LLMs) OpenAI’s Models GPT: The Next-Generation Language Models Getting Started with GPT (Code Snippet) Codex: Your AI Coding Assistant DALL-E 2: The Image Generation Wizard Google’s AI Model Overview Language and Chat Models Gemini 1.0 Pro Code Example: Calling Google Cloud Natural Language API for Text Generation Gemini 1.0 Pro Vision PaLM 2 Codey Suite for Code-Related Tasks Text and Image Processing Models Multimodal and Security Models Speech Models Anthropic’s Claude AI Models Claude 3 Model Family: Claude 3 Opus, Sonnet, and Haiku Key Features of Claude 3 Models Getting Started with Code Overview of Cohere AI Models Practical Example: Using Cohere's Command Model (Code Snippet) Meta AI Models Calling the LLaMA Model Using Hugging Face Passing the Access Token to Hugging Face Code Explanation Code to Use LLaMA Model from Hugging Face Platform Large Running Time PyTorch Review Questions Answers Key Learnings Glossary Overview and Capabilities of Open Source Models Definitions of Key Terms and Concepts Further Reading Chapter 5: Mastering Prompts for Creative Content Importance of Prompt Engineering Why Prompt Engineering? Need for Scalability Prompt Engineering Steps What Is the Goal? Composing Your Prompts Selecting Your Examples Testing Your Prompts Reviewing the Outputs Fine-Tuning Your Prompts Embracing Iteration Deploying Your Prompts Monitoring and Maintaining Components of a Prompt Prompt Templates Creating a Multi-string Prompt Template Calling the LLM Using the Prompt Template Advantages of Using Prompt Templates Example Selectors Choosing the Right Examples for Your Prompts Defining the BaseExampleSelector Class Creating a List of Examples Implementing a Custom Example Selector Using the Custom Example Selector Using the Example Selector in a Prompt Choosing the Right Example Selector Few-Shot Prompt Template Crafting a Few-Shot Prompt Template for Question Answering Step 1: Prepare Example Set Step 2: Format Few-Shot Examples Step 3: Create Few-Shot Prompt Template Step 4 (Optional): Select Examples with Example Selector Step 5 (Optional): Integrate Example Selector into Prompt Template Testing the Prompt Templates Reviewing the Output Conclusion Output Parsers Types of Output Parsers Practical Example: Using PydanticOutputParser for Movie Data Importing Required Libraries Defining the Movie Data Model Initializing the Output Parser Creating a Prompt Template Setting Up the OpenAI API Key Choosing the Language Model and Its Settings Generating Movie Information Parsing the Language Model’s Response OutputFixingParser ChatPrompt Templates Building the Chat Prompt Template Importing Required Libraries Setting Up the OpenAI API Key Creating a Chat Model Instance Defining the Chat Template Creating a Prompt Template Getting User Input Formatting the Prompt with User Input Printing the Formatted Prompt Generating the Chat Completion Printing the Assistant’s Response Case Study: Streamlining Customer Service Initial Design and Customization of Prompts Initial Design Advanced Engineering Impact Key Takeaways Review Questions Answers Further Reading Chapter 6: Building Intelligent Chatbots and Automated Analysis Systems Using Chains Introduction to LangChain Chains What Are LangChain Chains? Why Are Chains Important in Generative AI? Understanding the Components of Chains Higher-Level Components of a Chain App Internal Components in a Step Types of Chains LCEL Chains Legacy Chains Difference Between LCEL and Legacy Chains LCEL Chain Example Legacy Chain Example When to Use Different Types of Chains LCEL Chains Legacy Chains Building with LCEL Chains Constructing LCEL Chains Customizing LCEL Chains Executing LCEL Chains Streaming Execution Async Execution Batch Execution Observability in LCEL Chains Types of LCEL Chains Command Generation Using Query Constructor Chain Building with Legacy Chains Constructing Legacy Chains Executing Legacy Chains Types of Legacy Chains Building Real-World Apps with Legacy Chains Document Chatbot App Using ConversationalRetrievalChain Building Text Generation Apps Using LLMChain Building Conversational Apps with ConversationChain Building Q&A Apps Using RetrievalQA Document Processing App with MapReduceChain More Complex Workflow Apps Using Chain Composition Strategies Data Summarization App with Sequential Chains SequentialChain Use Case Example 1: Customer Support Chatbot App SequentialChain Use Case Example 2: Content Generation Pipeline App SequentialChain Use Case Example 3: Automated Fraud Detection in Finance Task Allocation App Using Router Chains Sentiment Analysis App Using Conditional Chains Advanced Chain Techniques Handling Large Datasets with Chains Dealing with Errors and Exceptions in Chains Optimizing Chain Performance Testing and Debugging Chains Key Takeaways Recap of Key Concepts Future Possibilities with LangChain Chains Glossary Review Questions Answers Further Reading Chapter 7: Building Advanced Q&A and Search Applications Using Retrieval-Augmented Generation (RAG) Importance of RAG How Does RAG Work? RAG Use Case Example Try It Yourself LangChain Components Document Loaders Document Loaders in Action Working with PDFs Dealing with CSV Files Working with JSON Files Text Splitters Fully Working Code Example for Text Splitting Recursive Splitting CodeTextSplitter Splitting by Token Vector Stores Text Embedding Models Code Walk-Through for Text Embeddings Caching the Embeddings Code Walk-Through for Cache Embeddings Building the Information Retrieval System Calling the Vector Store Asynchronously Retrievers Code Walk-Through for Information Retrieval Indexing Key Takeaways Review Questions Answers Glossary References Chapter 8: Your First Agent App Introduction What Are Agents? Types of LangChain Agents and Their Capabilities Example of an Agent’s Workflow Agent’s Thought Process Why Agents Matter Agents for Content Generation Agents As Task Managers How Do Chains Differ from Agents? Choosing Your Approach Your First End-to-End Working Agent App Code Explanation Results After Running the Code Interpreting the Results Key Takeaways Review Questions Answers Further Reading Chapter 9: Building Different Types of Agents Learning Objectives Designing and Implementing an Agent Defining the Agent's Objective Concepts Agent Agent Inputs Agent Outputs AgentExecutor Tools and Toolkits Tools Toolkits Considerations Building an Agent Using LangGraph for Enhanced Capabilities What Is LangGraph? Setting Up LangGraph Creating a Simple LangGraph Agent Types Criteria for Choosing Agent Types Types of LangChain Agents Zero-Shot-React Agent Example Tool Calling Agent Setup Initializing Tools Creating the Agent Running the Agent Using Chat History OpenAI Tools Initializing Tools Creating the Agent Running the Agent Using Chat History Structured Chat Agent Initializing Tools Creating the Agent Defining a Helper Function Running the Agent Using Chat History ReAct Agent Initializing Tools Creating the Agent Running the Agent Using Chat History Self-Ask Agents Initializing Tools Creating the Agent Running the Agent Autonomous Decision-Making Capability Intelligent Agent Performing Tasks with Multiple Tools Defining Tools Creating a Retriever Tool Putting It All Together Choosing the LLM Selecting the Prompt Initializing the Agent Creating the AgentExecutor Differences Between LangChain v0.1 and v0.2 Agents Simplified Agent Initialization in LangChain v0.2 Key Takeaways Review Questions Answers Further Reading Chapter 10: Projects: Building Agent Apps for Common Use Cases Creating a Custom Agent Loading the Language Model Defining Tools Creating the Prompt Binding Tools to the Language Model Creating the Agent Testing Your Agent Adding Memory Practical Use Cases for Agents Customer Support Automation Personalized Recommendations Real-Time Data Analysis and Decision-Making Key Takeaways Review Questions Answers Further Reading Chapter 11: Building and Deploying a ChatGPT-like App Using Streamlit Setting Up Your Development Environment Installing Streamlit Library Installing Python Installing Required Dependencies Building the Streamlit LangChain UI App Components of the Streamlit App Steps Involved in Building the App Indentation Error in the Code Run Your Streamlit Application View Your Streamlit Application in a Web Browser Interact with Your Streamlit Application Stop the Streamlit Server (When Needed) Testing the App Deploying the LangChain Application Installing Git on Your System Setting Up Your Identity Set Up the OpenAI Key As an Environmental Variable Resolving Sensitive Information Issues in Your Repository Preventing Email Privacy–Related Issues Deploying the App in GitHub Providing Access to GitHub Deploying in the Streamlit Cloud Other Cloud Deployment Options Key Takeaways Review Questions Answers Further Reading Setting Up Your Development Environment Running Streamlit in Your Desktop Installing Streamlit Library Creating and Using the Language Model Handling User Input Chat History Initialization Deploying the Application GitHub Integration Index
دانلود کتاب Generative AI Apps with LangChain and Python: A Project-Based Approach to Building Real-World LLM Apps for Beginners