Skip to main content

Collection of utilities for use with OpenAI's GPT-3 language model

Project description

gpt-utils

Helper tools for use with OpenAI's GPT-3 API.

The API key can be provided in three ways:

  • In the environment variable OPENAI_API_KEY
  • Via class attribute GPT.api_key of class GPT in module gpt_utils.core
  • Via keyword argument api_key in any method or function which obtains a response from OpenAI's servers

Disclaimer

These don't work perfectly.

gpt_utils.utils

from gpt_utils import utils

utils contains simple functions which transform text in a specific way. Some functions are bidirectional; these take an optional reverse keyword argument which reverses the conversion's input and output.

utils.case

>>> from gpt_utils.utils import case

Contains functions which modify the case of words in a string. These functions are meant to selectively preserve the case of proper nouns, etc. with minimal involvement. The first, title(), takes a str containing a word or phrase with proper capitalization for use in a heading or title:

>>> case.title('the ant: an introduction')
'The Ant: An Introduction'

The second, mid_sentence(), adjusts the case of input words/phrases for insertion mid-sentence:

>>> case.mid_sentence('bicycles on inman street')
'bicycles on Inman Street'
>>> case.mid_sentence('An italian restaurant in somerville')
'an Italian restaurant in Somerville'

utils.location

>>> from gpt_utils.utils import location

Currently contains one function, fix_location(), which takes an unformatted string containing a location and formats it properly for display:

>>> location.fix_location('lenox ma')
'Lenox, MA'

utils.number

>>> from gpt_utils.utils import number

Contains two functions which convert numbers to strings. The first, number_to_str(), takes an int or float and writes out the same number as a str:

>>> number.number_to_str(83)
'eighty-three'
>>> number.number_to_string(3.14)
'three point one four'

The second, number_to_ordinal(), takes an int and returns it in ordinal form as a str:

>>> number.number_to_ordinal(43)
'forty-third'

utils.dechatify()

I have found that GPT tends to produce output of lower quality when it is prompted with text containing Internet/SMS vernacular. As a remedy, dechatify() converts text to standard/written English:

>>> utils.dechatify('how r u')
'How are you?'
>>> utils.dechatify('if the implementation is easy to explain then it might b a good idea')
'If the implementation is easy to explain, then it might be a good idea.'

utils.generate_stem()

This function accepts a str containing a word/phrase and returns a sentence stem pairing the word/phrase with the appropriate form of the verb "to be":

>>> utils.generate_stem('GitHub')
'GitHub is'
>>> utils.generate_stem("pleiades")
'The Pleiades are'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpt_utils-1.4.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpt_utils-1.4.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file gpt_utils-1.4.0.tar.gz.

File metadata

  • Download URL: gpt_utils-1.4.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.2

File hashes

Hashes for gpt_utils-1.4.0.tar.gz
Algorithm Hash digest
SHA256 b342deefa389884a6c848062c17567725f22678c1b76be8e3af5da0fa4e66697
MD5 e7d64bad5263aacb3bc7c725a8331b79
BLAKE2b-256 d17f9bb941c9b83455366b4f9acc835c5d8ebba5a19bff61a7598b861ea8ff9e

See more details on using hashes here.

File details

Details for the file gpt_utils-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: gpt_utils-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.2

File hashes

Hashes for gpt_utils-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65e0ab52130731116a376e9ead7ae1d2ac9fc5a34c73334df439716102202496
MD5 788dbc82e692cb1fbff9c65ea80c87fe
BLAKE2b-256 cd53ca7551c587cae023db9fbdd05c9f74f048a9d157e23e533f45fbb9812231

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page