Skip to main content

gpt3-simple-primer

Simple GPT-3 primer using openai.

Background

Generative Pre-trained Transformer 3 (GPT-3) is an autoregressive language model that uses deep learning to produce human-like text. For more information, visit https://openai.com/blog/openai-api/.

The OpenAI Python library is the official Python wrapper for the OpenAI API. The purpose of this library is to simplify the priming process by providing easy to use methods for setting the instructions and adding examples.

Priming

Priming is the practice of providing an initial prompt to the language model to improve subsequent model predictions.

GPT-3 generally does very well even with short instructions and a few examples of your intended use case. Examples are typically delimited based on input and output. For instance, GPT-3 can be used to predict food ingredients based on the following prompt:

Given the name of a food, list the ingredients used to make this meal.

Food: apple pie
Ingredients: apple, butter, flour, egg, cinnamon, crust, sugar

Food: guacamole
Ingredients: avocado, tomato, onion, lime, salt

Requirements

You will need an API key from OpenAI to access GPT-3.

Installation

To install, run:

pip install gpt3-simple-primer

Usage

input_text and output_text determines how input and output are delimited in the examples. The default is to use Input and Output.

from gpt3_simple_primer import GPT3Generator, set_api_key

KEY = 'sk-xxxxx'  # openai key
set_api_key(KEY)

generator = GPT3Generator(input_text='Food',
                          output_text='Ingredients')

generator.set_instructions('List the ingredients for this meal.')
generator.add_example('apple pie', 'apple, butter, flour, egg, cinnamon, crust, sugar')
generator.add_example('guacamole', 'avocado, tomato, onion, lime, salt')

# Ingredients: cream, egg yolk, sugar, lime, key lime juice
generator.generate(prompt='key lime pie',
                   engine='davinci',
                   max_tokens=20,
                   temperature=0.5,
                   top_p=1)

To see the prompt used for priming:

generator.get_prompt()

To remove an example from the prompt:

generator.remove_example('apple pie')

Examples

The library includes examples of GPT-3 applications based off of specific prompts.

from gpt3_simple_primer import set_api_key
from gpt3_simple_primer.examples import idiom_explainer

KEY = 'sk-xxxxx'  # openai key
set_api_key(KEY)

idiom_explainer.generate('hill to die on', max_tokens=15, engine='davinci')

Metadata

Release files for gpt3-simple-primer 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpt3-simple-primer 0.1.2
File Size Uploaded
gpt3_simple_primer-0.1.2.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gpt3-simple-primer 0.1.2
File Interpreter ABI Platform
gpt3_simple_primer-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / gpt3_simple_primer-0.1.2.tar.gz

Download URL gpt3_simple_primer-0.1.2.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c9f997a6e0d69988ee4e02a70ec1cf34c5041555603bd4d21b46a892a1b0d252
BLAKE2b-256 checksum
How to use checksums
93b747e32af4f928a355c2f87697ba5fd030939e1b2f9e795761c9fe93ee0db8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

Release files / gpt3_simple_primer-0.1.2-py3-none-any.whl

Download URL gpt3_simple_primer-0.1.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c1a656f513fa9a9739b17099c7a6d66e54050c1059557aff0cf4971658a9f5f
BLAKE2b-256 checksum
How to use checksums
9c54e83b8c912a8bb3bc291a1cdb6cd68ab4e5754ab5d28af011b6f63af5917e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.36

2 release files

0.0.5

2 release files

0.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page