Leanpub Header

Skip to main content

OpenAI GPT For Python Developers

The art and science of building AI-powered apps with GPT-4, Whisper, Weaviate, and beyond

Explore the fascinating world of Artificial Intelligence and solve real-world problems!

In this practical guide, you will build intelligent real-world applications using GPT-4, Embeddings, Whisper, Weaviate, and more tools from the OpenAI ecosystem.

You don't need to be a data scientist or machine learning engineer to follow this guide!

The author is letting you choose the price you pay for this book!

Pick Your Price...

Buying multiple copies for your team? See below for a discount!

PDF
EPUB
WEB
322
Pages
57,342Words
About

About

About the Book

The knowledge you'll acquire from this guide will be applicable to the current families of GPT models (GPT-3, GPT-3.5, GPT-4, etc.) and will likely also be relevant to GPT-5, should it ever be released.

OpenAI provides APIs (Application Programming Interfaces) to access their AI. The goal of an API is to abstract the underlying models by creating a universal interface for all versions, allowing users to use GPT regardless of its version.

This guide aims to provide a comprehensive, step-by-step tutorial on how to utilize GPT-3.5 and GPT-4 in your projects via this API. It also covers other models, such as Whisper and Text-to-Speech.

If you're developing a chatbot, an AI assistant, or a web application that utilizes AI-generated data, this guide will assist you in achieving your objectives.

If you have a basic understanding of the Python programming language and are willing to learn a few additional techniques, such as using Pandas Dataframes and some NLP methods, you possess all the necessary tools to start building intelligent systems with OpenAI tools.

Rest assured, you don't need to be a data scientist, machine learning engineer, or AI expert to comprehend and implement the concepts, techniques, and tutorials presented in this guide. The explanations provided are straightforward and easy to understand, featuring simple Python code, examples, and hands-on exercises.

This guide emphasizes practical, hands-on learning and is designed to assist readers in building real-world applications. It is example-driven and provides numerous practical examples to help readers understand the concepts and apply them to real-life scenarios to solve real-world problems.

By the end of your learning journey, you will have developed applications such as:

  • Fine-tuned, domain-specific chatbots.
  • An intelligent conversational system with memory and context.
  • A semantic modern search engine using RAG and other techniques.
  • An intelligent coffee recommendation system based on your taste.
  • A chatbot assistant to assist with Linux commands
  • A fine-tuned news category prediction system.
  • An AI-to-AI autonomous discussion system to simulate human-like conversations or solve problems
  • An AI-based mental health coach trained on a large dataset of mental health conversations
  • and more!

By reading this guide and following the examples, you will be able to:

  • Understand the different models available, and how and when to use each one.
  • Generate human-like text for various purposes, such as answering questions, creating content, and other creative uses.
  • Control the creativity of GPT models and adopt the best practices to generate high-quality text.
  • Transform and edit the text to perform translation, formatting, and other useful tasks.
  • Optimize the performance of GPT models using various parameters and options such as max_tokens, temperature, top_p, n, stream, logprobs, stop, presence_penalty, frequency_penalty, best_of, and others.
  • Stem, lemmatize and reduce your costs when using the API.
  • Understand Context Stuffing, chaining, and practice prompt engineering.
  • Implement a chatbot with memory and context.
  • Create prediction algorithms and zero-shot techniques and evaluate their accuracy.
  • Understand, practice, and improve few-shot learning.
  • Understand fine-tuning and leverage its power to create your own fine-tuned models.
  • Understand and use fine-tuning best practices
  • Practice training and classification techniques using GPT.
  • Understand embedding and how companies such as Tesla and Notion are using it.
  • Understand and implement semantic search, RAG, and other advanced tools and concepts.
  • Integrate a Vector Database (e.g.: Weaviate) with your intelligent systems.

Price

Pick Your Price...

Minimum price

$27.00

$35.00

You pay

$35.00

Author earns

$28.00
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 2)

2
The author will earn $24.00 from your purchase!
You can get credits monthly with a Reader Membership

Team Discounts

Team Discounts

Get a team discount on this book!

  • Up to 3 members

    Minimum price
    $67.00
    Suggested price
    $87.00
  • Up to 5 members

    Minimum price
    $108.00
    Suggested price
    $140.00
  • Up to 10 members

    Minimum price
    $189.00
    Suggested price
    $245.00
  • Up to 15 members

    Minimum price
    $270.00
    Suggested price
    $350.00
  • Up to 25 members

    Minimum price
    $405.00
    Suggested price
    $525.00

Author

About the Author

Aymen El Amri

Aymen El Amri is an author, entrepreneur, trainer, and polymath software engineer who has excelled in a range of roles and responsibilities in the field of technology including DevOps & Cloud Native, Cloud Architecture, Python, NLP, Data Science, and more.

Aymen has trained hundreds of software engineers and written multiple books and courses read by thousands of other developers and software engineers.

Aymen El Amri has a practical approach to teaching based on breaking down complex concepts into easy-to-understand language and providing real-world examples that resonate with his audience.

Some projects he founded are FAUN, eralabs.io, and Marketto. You can find Aymen on Twitter and Linkedin.

Leanpub Podcast

Episode 88

An Interview with Aymen El Amri

Contents

Table of Contents

Preface

  1. About the Author

The Story of OpenAI and ChatGPT

  1. About This Guide
  2. The Companion Toolkit
  3. Stay Connected

How Does GPT Work?

Setting Up the Development Environment

  1. Notes
  2. Installing Python, pip, and a Virtual Development Environment
  3. Obtain Your OpenAI API Keys
  4. Install the Official Python Bindings
  5. Test our API Keys

Understanding the Available Models and Which One to Use

  1. OpenAI Available Models and Important Considerations
  2. Which Model to Use?
  3. OpenAI Model Series
  4. GPT-4 Series
  5. GPT-3.5 Series
  6. InstructGPT-3 Series
  7. Base GPT-3 Series
  8. Codex Series
  9. Content Filter
  10. DALL-E Series
  11. TTS Series
  12. Whisper Model
  13. Embedding Model
  14. OpenAI Models and Pricing
  15. What’s Next?

Using GPT Chat Completions

  1. An Introductory Example
  2. System, User, and Assistant Roles
  3. The System Role
  4. The User Role
  5. The Assistant Role
  6. Few-shot Learning with Chat Completions
  7. Formatting the Output
  8. Controlling the Output’s Token Count
  9. Controlling When the Completion Output Stops
  10. Temperature and Hallucination
  11. Sampling with Top_p
  12. Temperature vs Top_p: What’s the Difference? Which One Should I Use?
  13. Streaming the API Response
  14. Controlling Repetitiveness: Frequency and Presence Penalties
  15. Frequency vs. Presence Penalty
  16. Controlling the Number of Results from the API
  17. Conclusion

Advanced Examples and Prompt Engineering

  1. What is Prompt Engineering?
  2. Few Shot Learning: A Key Prompt Engineering Technique
  3. Overgeneration and Selection
  4. General Knowledge Prompting (GKP): Generating a Rap Song
  5. Context Stuffing: Is Apple a Fruit or a Company?
  6. Dynamic Max Tokens
  7. Creating an Interactive CLI-Based Assistant
  8. What’s Next?

Embedding

  1. What is an Embedding?
  2. Use Cases: From Modern Search Engines to Self-Driving Cars
  3. Tesla: How Embeddings Are Used in Self-Driving Cars
  4. Kalendar AI: The Power of Embeddings in Sales Outreach
  5. Notion: Enhanced Search Capabilities
  6. DALL·E 2: Text-to-Image Conversion
  7. Understanding Text Embedding
  8. Embeddings for Multiple Inputs
  9. Use case: Semantic Search
  10. Cosine Similarity: A Deeper Look
  11. Semantic Search and OpenAI’s Text Embeddings
  12. Behind the Scenes: How Embeddings Work

Advanced Embedding Examples

  1. Predicting Your Preferred Coffee
  2. Creating a “Fuzzier” Search
  3. Predicting News Category: Zero-Shot Classification with Embeddings
  4. Evaluating the Accuracy of a Zero-Shot Classifier
  5. Precision in Zero-Shot Classifier Applications: Examples

Fine-Tuning and Best Practices

  1. Few-Shot Learning
  2. Enhancing Few-Shot Learning
  3. Practical Application of Fine-Tuning
  4. Fine-Tuning Best Practices
  5. Choosing the Model
  6. Validating the Dataset
  7. Token Limit
  8. Dataset Size
  9. Testing and Improving Training (Hyperparameters)
  10. Epochs
  11. Learning Rate Multiplier
  12. Batch Size
  13. Consider Estimated Costs
  14. Dataset Quality
  15. Combining Fine-Tuning with Other Techniques
  16. Experiment and Learn
  17. Use a Validation Set
  18. Test the Model
  19. Analyze the Results

Advanced Fine-Tuning: Mental Health Coach

  1. Dataset Used in the Example
  2. Preparing the Data
  3. Using the Model in Real-World Applications and Challenges

Context & Memory: Making AI More Real

  1. The Problem: No Memory
  2. No Context = Chaos of Randomness and Confusion
  3. History = Context
  4. The Problem with Carrying Over History
  5. Last In First Out (LIFO) Memory
  6. The Problem with Last In, First Out Memory
  7. Selective Context

Using a Vector Database with OpenAI

  1. Introduction
  2. What is a Vector Database?
  3. Example 1: Using Weaviate to Make Our Model More Context-Aware
  4. Example 2: Using Weaviate and OpenAI in Semantic Search
  5. Example 3: Using Weaviate and OpenAI for Generative Search

Speech Recognition and Translation Using Whisper

  1. What is Whisper?
  2. How to Get Started?
  3. Transcribe and Translate
  4. Using Whisper SDK in Python
  5. Using OpenAI Speech to Text API
  6. Transcription API
  7. Translation API
  8. Improving Whisper Transcription
  9. Cleaning the Audio
  10. Using the Prompt Parameter
  11. Post-Processing the Transcription

Text-to-Speech with OpenAI TTS Models

Autonomous AI-to-AI Discussion Using OpenAI, Weaviate, and AI Avatars

  1. Generating the Audio Files
  2. Using AI Avatar Models
  3. What’s Next?

Afterword

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub