GPT-3 wrapper for Python
Project description
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.
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
key = 'sk-xxxxx'
generator = GPT3Generator(engine='davinci',
max_tokens=20,
temperature=0.5,
top_p=1,
input_text='Food',
output_text='Ingredients')
generator.set_key(key)
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')
# key lime, egg, sugar, butter, graham cracker, cream
generator.generate('key lime pie')
To see the prompt used for priming:
generator.get_prompt()
To remove an example from the prompt:
generator.remove_example('apple pie')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for gpt3_simple_primer-0.0.29.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6bfdc410efc521f3d63009cb1748cd9a251d9c6631b6ccdf6f1d9dc55beb8ed |
|
MD5 | 5d2728f589a4b01b3668e223c3192225 |
|
BLAKE2b-256 | 4ac5eb8bb50ebde641435e54655276bbe77d915905d794aabbc63c9d901ca4c5 |
Hashes for gpt3_simple_primer-0.0.29-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bc3aa8128594711de5071014126c57b24786e10cd2199a708c57f07533c4810 |
|
MD5 | d6bff9a79fcd88cd2e87c425af6d7f14 |
|
BLAKE2b-256 | 67bcb29409da0b6e4659bd3f178845fb90f455a4d25cd4a5ade3fc3858ec9685 |