Skip to main content

Ask ChatGPT to implement your existing python functions.

Project description

GPTImpl

Ask ChatGPT to implement your Python functions for you.

Installation


A distribution is available on PyPI.

pip install gptimpl

Usage


Since we interact with OpenAI, the OpenAI API key is a run-time dependency for gptimpl. You can either provide it per-invocation, i.e.

OPENAI_API_KEY="<key>" gptimpl -v example.py

or you can export it before running any gptimpl commands with:

export OPENAI_API_KEY="<key>"
gptimpl --help
usage: gptimpl [-h] [-v] [-w] [-m MODEL] FILE [FILE ...]

Generate implementations for Python functions based on docstrings and function signature using OpenAI.

positional arguments:
  FILE                  The Python files to process.

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Specify the verbosity of the output.
  -w, --overwrite       If specified, the generated files will be overwritten instead of logging to stdout.
  -m MODEL, --model MODEL
                        Select the backend model to use. Defaults to gpt-3.5-turbo

DISCLAIMER: Please use the -w flag only if you want to overwrite your source files and they are already version controlled! The GPT generated code can be garbage sometimes so it is recommended to overwrite only if you have a way to revert the changes.

Updating the function body in-place

Suppose you have a Python file called example.py that contains unimplemented functions as follows:

def fibonacci(n: int) -> int:
    """
    Return the n-th fibonacci number.
    """

def estimate_pi(n: int) -> float:
    """
    Estimate Pi using Gregory-Leibniz series
    using the first n terms.
    """

Then we can pass this file through gptimpl to generate the implementations for us.

Note: Without --overwrite, it defaults to printing the replacement contents to stdout.

gptimpl example.py -v --overwrite

This overwrites the file with the following patch:

-def fibonacci(n: int) -> int:
+def fibonacci(n: int) ->int:
     """
     Return the nth fibonacci number.
     """
+    if n <= 1:
+        return n
+    else:
+        return fibonacci(n - 1) + fibonacci(n - 2)
 
 
-def estimate_pi(n: int) -> float:
+def estimate_pi(n: int) ->float:
     """
     Estimate Pi using Gregory-Leibniz series
     using the first n terms.
     """
+    pi = 0
+    for i in range(n):
+        pi += (-1) ** i / (2 * i + 1)
+    return pi * 4

resulting in an example.py that looks like:

def fibonacci(n: int) ->int:
    """
    Return the nth fibonacci number.
    """
    if n <= 1:
        return n
    else:
        return fibonacci(n - 1) + fibonacci(n - 2)


def estimate_pi(n: int) ->float:
    """
    Estimate Pi using Gregory-Leibniz series
    using the first n terms.
    """
    pi = 0
    for i in range(n):
        pi += (-1) ** i / (2 * i + 1)
    return pi * 4

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

gptimpl-0.1.1.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

gptimpl-0.1.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file gptimpl-0.1.1.tar.gz.

File metadata

  • Download URL: gptimpl-0.1.1.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for gptimpl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4865aa221b8dc06c8530502c52dbaa052a90d2cb49a1ed7179ccd5b33ce744aa
MD5 4363c1dcbcba6eac7cb8c5c139043f7d
BLAKE2b-256 a12dd3061045ee6847000772a5290792257028ee002cd513cc41cb1a54d72b11

See more details on using hashes here.

File details

Details for the file gptimpl-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gptimpl-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for gptimpl-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 82823bce869ba5598ef7e0c7a2998ce24a086bb4c20dfd89d5d59ba17ec79823
MD5 a8bdbbdbaeaf23acf773a2e1644c79e0
BLAKE2b-256 ccfa426904e4b08670b82fccdee51a26d606775f6cf9f176346af4f636a596b0

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