Giter Site home page Giter Site logo

vscodewithchatgpt's Introduction

Maccarone: AI-managed code blocks in Python ⏪⏩

PyPI version

Maccarone lets you delegate sections of your Python program to AI ownership.

Here's what it looks like in the VS Code extension:

screencap-20230629

Example

You might write some code like this:

def main(path: str):
    #<<filenames = a list of filenames under path>>

    for fn in filenames:
        #<<size = size of fn in bytes>>

        print(fn, size)

#<<use argparse and call main>>

Maccarone then fills in the sections you've delegated:

def main(path: str):
    #<<filenames = list of filenames under path; no dirs>>
    import os
    filenames = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
    #<</>>

    for fn in filenames:
        #<<size = size of fn in bytes>>
        size = os.path.getsize(os.path.join(path, fn))
        #<</>>
        print(fn, size)

#<<use argparse and call main>>
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("path", type=str)
args = parser.parse_args()
main(args.path)
#<</>>

Make a change in your code, like adding an extension parameter to main, and Maccarone keeps its sections up to date:

def main(path: str, extension: str | None = None):
    #<<filenames = list of filenames under path; no dirs>>if extension:
        filenames = [f for f in filenames if f.endswith(extension)]
    #<</>>#<<use argparse and call main>>parser.add_argument("--extension", type=str, default=None)
args = parser.parse_args()
main(args.path, args.extension)
#<</>>

Quickstart

Prerequisites

  • Python 3.8+
  • OpenAI API key with GPT-4 (export OPENAI_API_KEY)

Easy Mode - VS Code Extension

Easy mode is the free extension from the VS Code marketplace.

Install it in VS Code and you're done (if you have the prerequisites above).

Other Option - Command Line

If you don't use VS Code, you can still install Maccarone directly from PyPI:

  • pip install maccarone

Then run maccarone to generate code and update your source file:

$ maccarone --rewrite examples/file_sizes.py

Usage notes

Running maccarone on a directory

Maccarone can rewrite all files in a directory:

$ maccarone --rewrite --suffix .py examples/

Be careful! You should probably run this only on files in source control, for example.

Related work

FAQs

It needs my OpenAI API key?

Maccarone prompts GPT-4 to write code. It will make OpenAI API calls using your key and you will be charged by OpenAI.

API calls are made every time Maccarone preprocesses a new version of a source file.

The number of tokens consumed is proportional to the size of your completed code. You cannot accurately predict that number in advance. A small source module might cost $0.01–0.10 to preprocess.

What prevents my program from behaving differently after each preprocessing run?

The strength of your faith in GPT-4.

What about non-English languages?

They are likely to work, but less likely than English.

What does "maccarone" mean?

https://en.wikipedia.org/wiki/Macaronic_language

vscodewithchatgpt's People

Contributors

bsilverthorn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.