liveBook · Manning

GPT model

As explained in Generative AI in Action

A family of generative pretrained transformer language models developed by OpenAI.

GPT (Generative Pre-trained Transformer) is OpenAI’s family of foundation language models. Trained on large amounts of text and code, GPT models can generate and translate text, answer questions, and help write code. GPT-4 was also described as able to handle language and images. section 2.1

For developers, a GPT model is useful for producing a function or routine from a prompt, not for assuming an entire application will be ready to deploy. A request can specify the programming language, SDK, and desired output. Responses can vary between runs, so inspect generated code and test it against the task. section 1.3.4

Listing 1.1 “Hello, World!” calling OpenAI service
import os
from openai import OpenAI

gpt_model = "gpt-3.5-turbo"

# Replace with your actual OpenAI API key
client = OpenAI(api_key='your-api-key')

# Generate English text
response_english = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[
      {
        "role": "user",
        "content": "Hello, World!"
      }
    ],
    max_tokens=50
)
english_text = response_english.choices[0].message.content.strip()
print(english_text)

# Translate English text to French
response_french = client.chat.completions.create(
    model="gpt-3.5-turbo",

    messages=[
      {
        "role": "user",
        "content": "Translate the following English 
          text to French: " + english_text
      }
    ],
    max_tokens=100
)

# This prints the translation to French
print(response_french.choices[0].message.content.strip())

The Python listing calls GPT-3.5 Turbo through the OpenAI API, then makes a second call to translate the first response into French. It is illustrative: its API key is embedded in code, which is not an established best practice. section 1.3.4

If prompting alone does not meet a specific requirement, fine-tuning is another option. For example, GPT-3.5 Turbo can be adapted to reply only with emoji names in Microsoft Teams format. Define evaluation criteria, compare the base model with the task’s baseline, prepare training data, and evaluate the fine-tuned result. Prompt engineering and retrieval-augmented generation can still be used alongside fine-tuning; training and repeated revisions take time. section 9.2 section 9.3

How Generative AI in Action covers it

How deep it goes
Defines the model family, demonstrates API calls, and outlines fine-tuning evaluation without deriving transformer internals.
Examples
Uses a Python OpenAI API generation-and-translation listing and a Microsoft Teams-format emoji fine-tuning task.
What it assumes
Introduces GPT as a foundation-model family and illustrates API use for a developer new to OpenAI.
What you can do after
Apply it via the OpenAI API for short generation tasks, or evaluate task-specific fine-tuning against a base model and baseline.
How it connects
Connects GPT to foundation models, large language models, prompt engineering, retrieval-augmented generation, and fine-tuning.

Also explained in

Compare how 18 books explain GPT model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.