OpenAI GPT For Python Developers
Minimum price
Suggested price

OpenAI GPT For Python Developers

The art and science of developing intelligent apps with OpenAI GPT-3 (and GPT-4 very soon), DALL·E 2, CLIP, and Whisper. A comprehensive and example-rich guide suitable for learners of all levels

About the Book

The knowledge you gain from this guide will be applicable to GPT-3 and will likely also be relevant to GPT-4, 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.

The goal is to provide a step-by-step guide to using GPT-3 in your projects through this API but not only - many other tools and models built by OpenAI such as Whisper (an automatic speech recognition (ASR) system trained on 680,000 hours of multilingual and multitask supervised data), CLIP (Contrastive Language-Image Pre-Training), a neural network trained on a variety of (image, text) pairs and DALL·E 2, a new AI system that can create realistic images and art from a description in natural language.

Whether you’re building a chatbot, an AI (voice) assistant, a semantic search engine, a classification system, a recommendation engine a web app providing AI-generated data, or any other sort of natural language/image/voice processing and generation platform, this guide will help you reach your goals.

If you have the basics of Python programming language and are open to learning a few more techniques like using Pandas Dataframes and some NLP techniques, you have all the necessary tools to start building intelligent systems using OpenAI tools.

Rest assured, you don't need to possess the title of a data scientist, machine learning engineer, or AI expert to comprehend the concepts, techniques, and tutorials presented in this guide. Our explanations are crystal clear and easy to understand, employing simple Python code, examples, and hands-on exercises.

This guide is focused on practical, hands-on learning and is designed to help the reader build real-world applications. The guide is example-driven and provides a lot of practical examples to help the reader 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 built applications such as:

  • A fine-tuned medical chatbot assistant
  • An intelligent coffee recommendation system
  • An intelligent conversational system with memory and context
  • An AI voice assistant like Alexa but smarter
  • A Chatbot assistant to help with Linux commands
  • A semantic search engine
  • A news category prediction system
  • An image recognition intelligent system (image to text)
  • An image generator (text to image)
  • 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 the various parameters and options such as suffix, max_tokens, temperature, top_p, n, stream, logprobs, echo, stop, presence_penalty, frequency_penalty, best_of, and others.
  • Stem, lemmatize, and reduce your bills when using the API
  • Understand Context Stuffing, chaining, and practice using advanced techniques
  • Understand text embedding and how companies such as Tesla and Notion are using it
  • Understand and implement semantic search and other advanced tools and concepts.
  • Creating prediction algorithms and zero-shot techniques and evaluating their accuracy
  • Understand, practice, and improve few-shot learning.
  • Understand fine-tuning and leveraging its power to create your own models.
  • Understand and use the best practices to create your own models.
  • Practice training and classification techniques using GPT.
  • Create advanced fine-tuned models.
  • Use OpenAI Whisper and other tools to create intelligent voice assistants.
  • Implement image classification using OpenAI CLIP.
  • Generate and edit images using OpenAI DALL-E 2.
  • Draw inspiration from other images to create yours.
  • Reverse engineer images’ prompts from Stable Diffusion (image to text)

About the Author

Aymen El Amri  @eon01
Aymen El Amri @eon01

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,, and Marketto. You can find Aymen on Twitter and Linkedin.

Aymen El Amri  @eon01

Episode 88

Table of Contents

  • Preface
  • About the Author
  • ChatGPT, GPT, GPT-3, DALL·E, Codex?
    • About This Guide
    • Keep in Touch
  • How Does GPT Work?
  • Preparing the Development Environment
    • Installing Python, pip, and a Virtual Environment for Development
    • Get Your OpenAI API Keys
    • Installing the Official Python Bindings
    • Testing our API Keys
  • Available Models
    • The Three Main Models
    • GPT-3: Processing and Generating Natural Language
    • Codex: Understanding and Generating Computer Code
    • Content Filter
    • Listing all Models
    • Which Model to Use?
    • What’s next?
  • Using GPT Text Completions
    • A Basic Completion Example
    • Controlling the Output’s Token Count
    • Logprobs
    • Controlling Creativity: The Sampling Temperature
    • Sampling with “top_p”
    • Streaming the Results
    • Controlling Repetitivity: Frequency and Presence Penalties
    • Controlling the Number of Outputs
    • Getting the “best of”
    • Controlling When the Completion Stops
    • Using Suffix After Text Completion
    • Example: Extracting keywords
    • Example: Generating Tweets
    • Example: Generating a Rap Song
    • Example: Generating a Todo List
    • Conclusion
  • Editing Text Using GPT
    • Example: Translating Text
    • Instruction is Required, Input is Optional
    • Editing Using the Completions Endpoint and Vice Versa
    • Formatting the Output
    • Creativity vs. Well-Defined Answers
    • Generating Multiple Edits
  • Advanced Text Manipulation Examples
    • Chaining Completions and Edits
    • Apple the Company vs. Apple the Fruit (Context Stuffing)
    • Getting Cryptocurrency Information Based on a User-Defined Schema (Context stuffing)
    • Creating a Chatbot Assistant to Help with Linux Commands
  • Embedding
    • Overview of Embedding
    • Use Cases
    • Requirements
    • Understanding Text Embedding
    • Embeddings for Multiple Inputs
    • Semantic Search
    • Cosine Similarity
  • Advanced Embedding Examples
    • Predicting your Preferred Coffee
    • Making a “fuzzier” Search
    • Predicting News Category Using Embedding
    • Evaluating the Accuracy of a Zero-Shot Classifier
  • Fine Tuning & Best Practices
    • Few Shot Learning
    • Improving Few Shot Learning
    • Fine Tuning in Practice
    • Datasets, Prompts, and Completions: What are the Best Practices?
  • Advanced Fine Tuning: Drug Classification
    • Dataset Used in the Example
    • Preparing the Data and Launching the Fine Tuning
    • Testing the Fine Tuned Model
  • Advanced Fine Tuning: Creating a Chatbot Assistant
    • Interactive Classification
    • How Will Everything Work?
    • Creating a Conversational Web App
  • Intelligent Speech Recognition Using OpenAI Whisper
    • What is Whisper?
    • How to Get Started?
    • Transcribe and Translate
  • Context & Memory: Making AI More Real
    • The Problem
    • No Context = Chaos of Randomness
    • History = Context
    • The Problem with Carrying Over History
    • Last in First out (LIFO) Memory
    • The Problem with Last in First out Memory
    • Selective Context
  • Building Your AI-Based Alexa
    • Introduction
    • Recording the audio
    • Transcribing the Audio
    • Replying to User Request
    • The Main Function
    • Putting Everything Together
    • Generating Better Answers
  • Image Classification with OpenAI CLIP
    • What is CLIP?
    • How to Use CLIP
    • Reverse Stable Diffusion: Image to Text
  • Generating Images Using DALL-E
    • Introduction
    • A Basic Example of Image Generation From a Prompt
    • Generating Multiple Images
    • Using Different Sizes
    • Better Image Prompts
    • Building a Random Image Generator
  • Editing Images Using DALL-E
    • An example of Editing an Image
  • Drawing Inspiration From Other Images
    • How to Create a Variation of a Given Image.
    • Use Cases for Image Variations
  • What’s Next

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.

See full terms

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

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

In fact, authors have earnedover $12 millionwriting, 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