Mastering Generative AI with OpenAI

Getting Started with OpenAI

OpenAI Playground

Before you begin, make sure you have an OpenAI account and have configured your API key.

Note

Set your API key in the environment to authenticate requests:

export OPENAI_API_KEY="your_api_key_here"

Once in your account, click Playground in the top navigation to access the interface.

Playground Interface Overview

The Playground is organized into three main sections:

  • Getting Started panel (left): Usage guidelines, best practices, and limitations.
  • Presets toolbar (top): Quickly load common tasks like Classification, Chat, and more.
  • Editor & Controls (center and right): Write prompts and adjust parameters such as temperature and max_tokens.

Classification Preset: Company Category Labeling

Select the Classification preset to label items by category. By default, you’ll see examples like Apple, Facebook, and FedEx. Let’s classify “Apple”:

The image shows the OpenAI API Playground interface with a classification task, categorizing companies like Apple under "Technology."

It correctly labels Apple as a technology company.

Below the editor, click View Code to examine the underlying API request in languages such as Python, Node.js, or raw JSON. For example, here’s the Python snippet:

import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.Completion.create(
    model="text-davinci-003",
    prompt="The following is a list of companies and the categories they belong to:",
    temperature=0,
    max_tokens=6,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0,
    stop=["\n"]
)
print(response.choices[0].text.strip())

Experimenting with Models & Parameters

Beyond presets, the Playground lets you switch between models—such as text-davinci-003 and gpt-3.5-turbo—and fine-tune parameters. Hover over any label to view its description and experiment to see how changes affect output.

Warning

Adjusting parameters like max_tokens and temperature directly impacts response quality, token usage, and billing. Monitor your usage in the OpenAI Dashboard.

Modes Overview

The Playground offers four modes to suit different tasks:

ModeUse CaseExample Prompt
CompleteGenerate finished textWrite a tagline for an online bicycle shop.
ChatConversational interactionsSystem/User messages for a Q&A session
InsertFill in placeholders[Insert the body of an announcement email…]
EditRevise or correct textFix the grammar mistakes in the paragraph…

1. Complete Mode

In Complete mode, you get free-form text completions. For instance, ask for a tagline:

Write a tagline for an online bicycle shop.

Click Submit, and you might see:

The Right Bike for Any Ride!

The image shows the OpenAI API Playground interface with a prompt to write a tagline for an online bicycle shop, resulting in the suggestion: "The Right Bike For Any Ride!"

2. Chat Mode

Switch to Chat to leverage conversational models like GPT-3.5 Turbo. For example, role-play a history professor:

  • System prompt: “You are an expert in world history.”
  • User prompt: “When did America become independent?”

Submit to receive a detailed response:

The image shows the OpenAI API Playground interface with a chat interaction about when America became independent. The assistant provides a detailed response about the Declaration of Independence and the Treaty of Paris.

3. Insert Mode

Use Insert mode to tell the model where to fill in text. Example:

[Insert the body of an announcement email recognizing sales teams for their performance.]

Submit to generate a complete email section:

The image shows the OpenAI API Playground interface with a text completion task. The left side contains instructions, while the right side displays a text prompt and its AI-generated completion.

4. Edit Mode

In Edit mode, paste existing text and ask the model to improve or correct it:

Fix the grammar mistakes in the following paragraph:
"Last night i went to the movie blah blah blah..."

After submission, you’ll receive a polished version:

The image shows the OpenAI API Playground interface with a text input about a movie theater visit, and a corrected version of the text on the right. The instruction given is to fix grammar mistakes.


You now have an overview of the OpenAI Playground’s presets, models, modes, and parameter controls. Continue experimenting to uncover best practices and optimize your prompts.

Further Reading

Watch Video

Watch video content

Previous
Setting Up OpenAI Account