Skip to main content

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

Metadata

Release files for gptimpl 0.1.1

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

Source distribution (sdist)

Source distribution for gptimpl 0.1.1
File Size Uploaded
gptimpl-0.1.1.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gptimpl 0.1.1
File Interpreter ABI Platform
gptimpl-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 33.2 kB

Release files / gptimpl-0.1.1.tar.gz

Download URL gptimpl-0.1.1.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4865aa221b8dc06c8530502c52dbaa052a90d2cb49a1ed7179ccd5b33ce744aa
BLAKE2b-256 checksum
How to use checksums
a12dd3061045ee6847000772a5290792257028ee002cd513cc41cb1a54d72b11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release files / gptimpl-0.1.1-py3-none-any.whl

Download URL gptimpl-0.1.1-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82823bce869ba5598ef7e0c7a2998ce24a086bb4c20dfd89d5d59ba17ec79823
BLAKE2b-256 checksum
How to use checksums
ccfa426904e4b08670b82fccdee51a26d606775f6cf9f176346af4f636a596b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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