Skip to main content

Autogenerate files and folders using ChatGPT API

Project description

CodeGenPT

Version Python Version Support

Autogenerate files or entire projects using ChatGPT API.

Installation

pip install codegenpt

Usage

CodeGenPT looks for .codegenpt files and generate files using its instructions.

Generating individual files

Example: hello_world.py.codegenpt

Create a hello world program

Then:

$ codegenpt helloworld.py.codegenpt
⏳ Generating file: helloworld.py
🍺 File generated: helloworld.py
🍻 Success

Will generate a file named helloworld.py:

print("hello world");

The actual content of the file will be generated by ChatGPT, so it will vary at each run. You can use codegenpt -R . to recursively look for all .codegenpt files and generate them.

Generate entire directories or projects

You can create entire directories or projects using a .dir.codegenpt file. Example: tictactoe.dir.codegenpt

Create a tic-tac-toe game using html, js and css.

Then:

$ codegenpt tic-tac-toe.dir.codegenpt
⏳ Generating directory: tic-tac-toe
🍺 File generated: tic-tac-toe/style.css
🍺 File generated: tic-tac-toe/index.html
🍺 File generated: tic-tac-toe/game.js
🍻 Success

Will create a folder called tic-tac-toe and generate all needed files.

Setup

CodeGenPT expects an environment variable called OPEN_API_KEY.

  1. Get an Open AI API Key
  2. Add the key to your OPEN_API_KEY environment variable:
  • If you use bash:
    echo 'export OPENAI_API_KEY={your api key}' >> ~/.bash_profile && source ~/.bash_profile
    
  • If yu use zsh:
    echo 'export OPENAI_API_KEY={your api key}' >> ~/.zshenv && source ~/.zshenv
    

Commands

Commands are special instructions you can use to instruct the generation process.

All codegenpt commands are placed in a single line in the format:

@command_name args...

@include

Includes one or more files on the context. Included files can be referenced using @filename.ext in the generation instructions

Example:

names.txt:

Diego
Alberto
Daniel

random_name.js.codegenpt:

@include assets/names.txt

Read @names.txt and write a function that returns one of the names

random_name.js:

function getRandomName() {
  const names = [
    'Diego',
    'Alberto',
    'Daniel'
  ];

  const randomIndex = Math.floor(Math.random() * names.length);

  return names[randomIndex];
}

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

codegenpt-0.8.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

codegenpt-0.8.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file codegenpt-0.8.1.tar.gz.

File metadata

  • Download URL: codegenpt-0.8.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Darwin/22.5.0

File hashes

Hashes for codegenpt-0.8.1.tar.gz
Algorithm Hash digest
SHA256 df6e40856570be7f017a4e89ba561ef6a4e3331e461c67ef30333142b5a9d5bc
MD5 d7a9ed77581cb0438fa99e2eb82f1e86
BLAKE2b-256 e8331127f0671ce7352724bc9844c76bd701fd58f76056b51d9d10cf1f2a2a7b

See more details on using hashes here.

File details

Details for the file codegenpt-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: codegenpt-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Darwin/22.5.0

File hashes

Hashes for codegenpt-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c1d0da46eaa87ca8f38720a057276614643b09180693d1d6de7fb02ca0d194d
MD5 9e26cb95f15c83f613e7a8495a5df594
BLAKE2b-256 16db2edca762fb8e5fd74165f2d3a2886d12897fe138593f9de1fff6b35efc6f

See more details on using hashes here.

Supported by

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