Skip to main content

A CLI tool for refactoring Python code using OpenAI's text-davinci-003 model

Project description

Codegpt

A tool for using GPT just a little quicker. A nearly truly automated footgun. Learn how to revert with git before trying please.

Posting about progress here:

Twitter Follow

Getting Started

pip install codegpt

And set your openapi API key as an environment variable like they recommend: In their docs here

Windows users can also use setx like:

$ setx OPENAI_SECRET_KEY=<YOUR_API_KEY>

from an admin console.

Be careful! But let's go.

Now with 10% less footgun!

Try this new command to see how it works:

codegpt todo do app.py

It'll prompt you for what needs done, and give you an option to edit the todo list before we attempt to refactor it.

The rest

The fun stuff is in the unsafe command.

Find a file you hate (Back it up! Don't do it live!) and give it a shot.

codegpt unsafe edit .\helper.py "Break this up into smaller functions where you can. Add google style docstrings. Feel free to rewrite any code doesn't make sense."

You'll see something like:

This prompt is 254 tokens, are you sure you want to continue?
The most GPT-3 can return in response is 3843. [y/N]: y

(and after a short wait...)

Explanation: The code has been refactored into smaller functions to improve readability, and Google style docstrings have been added.

Other things to try:

  • codegpt unsafe edit - Try it with anything. Markdown blog posts, js, yaml, python, whatever.
  • codegpt unsafe varnames - Changes variable names (and supposed to only be variable names...) to be readable
  • codegpt unsafe comment - Automatically add comments to a file.

Propose endpoints as issues, I've got a few ideas:

  • Explain file
  • Write tests for file
  • Generate SQL query from table spec files
  • Generate new file
  • Generate documentation from a file

Just remember this is paid - 2 cents per 1k tokens is a lot when you're working on files with a few hundred lines.

And remember to break up what you're working on - Results will be better with less moving parts and things to do.

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

codegpt-0.1.4.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

codegpt-0.1.4-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file codegpt-0.1.4.tar.gz.

File metadata

  • Download URL: codegpt-0.1.4.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.6 Windows/10

File hashes

Hashes for codegpt-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ef5b552a9ec4ddb38d4a5358a8035a1fcfcec448ed40bf0b1994c664af27593b
MD5 3165219921553e6fdc956b1d9a6287cf
BLAKE2b-256 889894b6a961713344474040b34ef1138fa0c86f78ada20ac73efedbc64622ab

See more details on using hashes here.

File details

Details for the file codegpt-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: codegpt-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.6 Windows/10

File hashes

Hashes for codegpt-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 93652a483c77265743617824c70ac1afa2bb55a5002c4b5ad9812c83b6aca74c
MD5 7d2f0328583dc5201a170a23b710c0d1
BLAKE2b-256 132897dd013bb7b43914a32873d6e3e19222c99a3bac8b8ed851c2f79e5417d5

See more details on using hashes here.

Supported by

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