Skip to main content

Autogenerate files and folders using ChatGPT API

Project description

CodeGenPT

Version Python Version Support

Autogenerate files using ChatGPT API.

Installation

pip install codegenpt

Usage

CodeGenPT looks for .codegenpt files within the source tree and generate files using its instructions.

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 name 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 also recursevily generate all files within a directory:

$ codegenpt -R .
🔎 Searching files...
⏳ Generating file: helloworld.py
🍺 File generated: helloworld.py
⏳ Generating file: README.md
🍺 File generated: README.md
⏳ Generating file: tests/tests.py
🍺 File generated: tests/tests.py
🍻 Success

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:

@cogenpt.command_name args...

@codegenpt.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:

@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.3.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

codegenpt-0.3.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: codegenpt-0.3.1.tar.gz
  • Upload date:
  • Size: 6.3 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.3.1.tar.gz
Algorithm Hash digest
SHA256 2020645104922b35b6c44f7f2f9097b6b3989467196c49b24e3320af2477331b
MD5 25995198c8f014c135f3fd7eb774d30e
BLAKE2b-256 587e78e9b054bb7fb374445bf66e18c5e63c6e50ea0096fceff5a0ecd2302a0c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: codegenpt-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a2d3ab8394b0fbf466e94b0aa71235f6245d8e74e1813af05192e6f5227ff0c
MD5 e14324b19786bf51ce4b46fd6981b998
BLAKE2b-256 6d44e919078c653245228bd8dd10384866cfe95554dc88872a490c43fde0271e

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