Developing Apps with GPT-4 and ChatGPT, 2nd Edition

Book description

This book provides an ideal guide for Python developers who want to learn how to build applications with large language models. Authors Olivier Caelen and Marie-Alice Blete cover the main features and benefits of GPT-4 and GPT-3.5 models and explain how they work. You'll also get a step-by-step guide for developing applications using the OpenAI Python library, including text generation, Q&A, and smart assistants.

Written in clear and concise language, Developing Apps with GPT-4 and ChatGPT includes easy-to-follow examples to help you understand and apply the concepts to your projects. Python code examples are available in a GitHub repository, and the book includes a glossary of key terms. Ready to harness the power of large language models in your applications? This book is a must.

You'll learn:

  • Fundamentals and benefits of GPT-4 and GPT-3.5 models, including the main features and how they work
  • How to integrate these models into Python-based applications, leveraging natural language processing capabilities and overcoming specific LLM-related challenges
  • Examples of applications demonstrating the OpenAI API in Python for tasks including text generation, question answering, content summarization, classification, and more
  • Advanced LLM topics such as prompt engineering, fine-tuning models for specific tasks, RAG, plug-ins, LangChain, LlamaIndex, GPTs, and assistants

Olivier Caelen is a machine learning researcher at Worldline and teaches machine learning courses at the University of Brussels.

Marie-Alice Blete, a software architect and data engineer in Worldline's R&D department, is interested in performance and latency issues associated with AI solutions.

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. O’Reilly Online Learning
    4. How to Contact Us
    5. Acknowledgments
  2. 1. GPT-4 and ChatGPT Essentials
    1. Introducing Large Language Models
      1. Exploring the Foundations of Language Models and NLP
      2. Understanding the Transformer Architecture and Its Role in LLMs
      3. Demystifying the Tokenization and Prediction Steps in GPT Models
      4. Integrating Vision into an LLM
    2. A Brief History: From GPT-1 to GPT-4
      1. GPT-1
      2. GPT-2
      3. GPT-3
      4. From GPT-3 to InstructGPT
      5. GPT-3.5, ChatGPT, Codex
      6. GPT-4
      7. The Evolution of AI Toward Multimodality
    3. LLM Use Cases and Example Products
      1. Be My Eyes
      2. Morgan Stanley
      3. Khan Academy
      4. Duolingo
      5. Yabble
      6. Waymark
      7. Inworld AI
    4. Beware of AI Hallucinations: Limitations and Considerations
    5. Unlocking GPT Potential with Advanced Features
    6. Summary
  3. 2. A Deep Dive into the OpenAI API
    1. Essential Concepts
    2. Models Available in the OpenAI API
      1. GPT Base
      2. InstructGPT (Legacy)
      3. GPT-3.5
      4. GPT-4
    3. Trying GPT Models with the OpenAI Playground
    4. Getting Started: The OpenAI Python Library
      1. OpenAI Access and API Key
      2. “Hello World” Example
    5. Using Chat Completion Models
      1. Input Options for the Chat Completion Endpoint
      2. Playing with temperature and top_p
      3. Output Result Format for the Chat Completion Endpoint
      4. Vision
      5. Requiring a JSON Output
    6. Using Other Text Completion Models
      1. Input Options for the Text Completion Endpoint
      2. Output Result Format for the Text Completion Endpoint
    7. Considerations
      1. Pricing and Token Limitations
      2. Security and Privacy: Caution!
    8. Other OpenAI APIs and Functionalities
      1. Embeddings
      2. Moderation
      3. Text-to-Speech
      4. Speech-to-Text
      5. Images API
    9. Summary (and Cheat Sheet)
  4. 3. Navigating LLM-Powered Applications: Capabilities and Challenges
    1. App Development Overview
      1. API Key Management
      2. Security and Data Privacy
    2. Software Architecture Design Principles
    3. Integrating LLM Capabilities into Your Projects
      1. Conversational Capabilities
      2. Language Processing Capabilities
      3. Human-Computer Interaction Capabilities
      4. Combining Capabilities
    4. Example Projects
      1. Project 1: Building a News Generator Solution—Language Processing
      2. Project 2: Summarizing YouTube Videos—Language Processing
      3. Project 3: Creating an Expert for Zelda BOTW—Language Processing and Conversations
      4. Project 4: Having a Personal Assistant—Human-Computer Interface
      5. Project 5: Organizing Documents—Language Processing
      6. Project 6: Analyzing Sentiments—Language Processing
    5. Cost Management
    6. LLM-Powered App Vulnerabilities
      1. Analyzing Inputs and Outputs
      2. The Inevitability of Prompt Injection
    7. Working with an External API
      1. Handling Errors and Unexpected Latency Issues
      2. Rate Limits
      3. Improving Responsiveness and User Experience
    8. Summary
  5. 4. Advanced LLM Integration Strategies with OpenAI
    1. Prompt Engineering
      1. Designing Effective Prompts with Roles, Contexts, and Tasks
      2. Thinking Step by Step
      3. Implementing Few-Shot Learning
      4. Iterative Refinement with User Feedback
      5. Improving Prompt Effectiveness
    2. Fine-Tuning
      1. Getting Started
      2. Fine-Tuning with the OpenAI API
      3. Fine-Tuning with the Web Interface of OpenAI
      4. Fine-Tuning Applications
      5. Generating and Fine-Tuning Synthetic Data for an Email Marketing Campaign
      6. Cost of Fine-Tuning
    3. RAG
      1. Naive RAG
      2. Advanced RAG
      3. RAG Limitations
    4. Choosing Between Strategies
      1. Strategy Comparison
      2. Evaluations
    5. From a Standard Application to an LLM-Powered Solution
      1. Prompt Sensitivity
      2. Nondeterminism
      3. Hallucinations
    6. Summary
  6. 5. Advancing LLM Capabilities with Frameworks, Plug-Ins, and More
    1. The LangChain Framework
      1. LangChain Libraries
      2. Dynamic Prompts
      3. Agents and Tools
      4. Memory
      5. Embeddings
    2. The LlamaIndex Framework
      1. Demonstration: RAG in 10 Lines of Code
      2. LlamaIndex Principles
      3. Customization
    3. GPT-4 Plug-Ins
      1. Overview
      2. The API
      3. The Plug-In Manifest
      4. The OpenAPI Specification
      5. Descriptions
    4. GPTs
    5. The Assistant API
      1. Creating an Assistant API
      2. Managing a Conversation with Your Assistant API
      3. Function Calling
      4. The Assistants on the OpenAI Web Platform
    6. Summary
  7. 6. Putting It All Together
    1. Key Takeaways
    2. Putting It All Together: The Assistant Use Case
      1. Step 1: Ideation
      2. Step 2: Defining the Requirements
      3. Step 3: Building a Prototype
      4. Step 4: Improving, Iterating
      5. Step 5: Making the Solution Robust
    3. Lessons Learned
  8. Glossary of Key Terms
  9. A. Tools, Libraries, and Frameworks
  10. Index
  11. About the Authors

Product information

  • Title: Developing Apps with GPT-4 and ChatGPT, 2nd Edition
  • Author(s): Olivier Caelen, Marie-Alice Blete
  • Release date: July 2024
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098168100