semvec/pypi-packages huggingface dataset:
codegenpt 0.8.1
Autogenerate files and folders using ChatGPT API
License: MIT
Requires Python: >=3.10

# CodeGenPT
![Version](https://img.shields.io/pypi/v/codegenpt)
![Python Version Support](https://img.shields.io/pypi/pyversions/codegenpt)

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:
```bash
$ codegenpt helloworld.py.codegenpt
⏳ Generating file: helloworld.py
🍺 File generated: helloworld.py
🍻 Success
```

Will generate a file named `helloworld.py`:
```python
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:
```bash
$ 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](https://github.com/Significant-Gravitas/Auto-GPT#:~:text=Get%20an%20OpenAI-,API%20Key,-Download%20the%20latest)
2. Add the key to your `OPEN_API_KEY` environment variable:
  - If you use `bash`:
    ```bash
    echo 'export OPENAI_API_KEY={your api key}' >> ~/.bash_profile && source ~/.bash_profile
    ```
  - If yu use `zsh`:
    ```bash
    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`:
```js
function getRandomName() {
  const names = [
    'Diego',
    'Alberto',
    'Daniel'
  ];

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

  return names[randomIndex];
}
```