from nbdev.showdoc import *
import os
import openai
= os.environ["OPENAI_API_KEY"] openai.api_key
OpenAI GPT-3 examples
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:
= "Write a tagline for a coffee shop" prompt
Next we’ll run the prompt through the GPT-3 text-davinci-001 model
= openai.Completion.create(engine="text-davinci-001", prompt=prompt, max_tokens=6)
response str(response["choices"][0]["text"])[2:]
'A caffeinated haven'
Let’s Try another prompt
Wine Shop Prompt
= "Write a tagline for a wine shop" prompt
= openai.Completion.create(engine="text-davinci-001", prompt=prompt, max_tokens=25)
response str(response["choices"][0]["text"])[2:]
'libations for all occasions'
'libations for all occasions'
Ask GPT3 Function
def ask_gpt3(prompt,openai=openai):
= openai.Completion.create(engine="text-davinci-001", prompt=prompt, max_tokens=20)
response = str(response["choices"][0]["text"])[2:]
text_response return text_response
Test Function with Champaign Prompt
= 'Whats a good tagline for champaign'
prompt = ask_gpt3(prompt)
text_response print(text_response)
"Celebrate life"
"Celebrate life"