OpenAI GPT-3 examples

from nbdev.showdoc import *
import os
import openai
 
openai.api_key = os.environ["OPENAI_API_KEY"]

Lets see what GPT-3 says

Here we’ll write some prompts to see what the GPT3 text-davinci-001 model replies.

First we’ll write a prompt for it:

prompt = "Write a tagline for a coffee shop"

Next we’ll run the prompt through the GPT-3 text-davinci-001 model

response = openai.Completion.create(engine="text-davinci-001", prompt=prompt, max_tokens=6)
str(response["choices"][0]["text"])[2:]
'A caffeinated haven'

Let’s Try another prompt

Wine Shop Prompt

prompt = "Write a tagline for a wine shop"
response = openai.Completion.create(engine="text-davinci-001", prompt=prompt, max_tokens=25)
str(response["choices"][0]["text"])[2:]
'libations for all occasions'
'libations for all occasions'

Ask GPT3 Function

def ask_gpt3(prompt,openai=openai):
    response = openai.Completion.create(engine="text-davinci-001", prompt=prompt, max_tokens=20)
    text_response = str(response["choices"][0]["text"])[2:]
    return text_response

Test Function with Champaign Prompt

prompt = 'Whats a good tagline for champaign'
text_response = ask_gpt3(prompt)
print(text_response)
"Celebrate life"
"Celebrate life"