Skip to content
forked from molbal/ai-phpdoc

AI PHPDocs is a tool that uses GPT-3 to automatically add missing PHPDoc comments to your PHP code.

License

Notifications You must be signed in to change notification settings

acseo/ai-phpdoc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI PHPDocs

AI PHPDocs is a tool that uses LLM (OpenAI or any other OpenAI compatible API) to automatically add missing PHPDoc comments to your PHP code.

Prerequisites

If you want to user OpenAI, you will need to have an OpenAI API key set as an environment variable.

export OPENAI_KEY=...

If you want to use another API endpoint, for example Ollama, you need to export other environment variables.

Example with Ollama that runs locally

export BASE_URI=http://localhost:11434/v1
export MODEL=mistral

You can choose the model with an environment variable.

export MODEL=...

Installation

To install AI PHPDocs, run the following command:

composer global require acseo/ai-phpdoc

Usage

To add missing PHPDoc comments to a single file, use the following command:

aiphpdocs file  /path/to/file.php

To add missing PHPDoc comments to a directory of files, use the following command. By default it iterates through the current directory for all files, but does not go into subdirectories:

aiphpdocs dir

You may set the --recursive flag, or -r for short for it to go into subdirectories.

If you pass another variable (regardless of the recursive flag) it will treat it as another directory to sweep through instead of the working directory.

aiphpdocs dir -r /somewhere/else

Docker usage

You can use the Docker image acseo/ai-phpdoc to use ai-phpdoc via docker

$ docker run -it -e OPENAI_KEY=sk-xxx -v /path/to/your/code:/code acseo/ai-phpdoc dir -r /code/src

Example

Original PHP File

// file : example.php
<?php

class Calculator
{
    public function add(int $a, int $b) : int
    {
        return $a + $b;
    }
}
$ export OPENAI_KEY=sk-...
$ php bin/aiphpdocs file example.php 

Result

// file : example.php
<?php

class Calculator
{
    /**
     * Adds two integers and returns the sum.
     *
     * @param int $a The first integer to be added.
     * @param int $b The second integer to be added.
     * @return int The sum of the two integers.
    */
    public function add(int $a, int $b) : int
    {
        return $a + $b;
    }
}

License

AI PHPDocs is licensed under the AGPL-3.0 license. See LICENSE for more information.

About

AI PHPDocs is a tool that uses GPT-3 to automatically add missing PHPDoc comments to your PHP code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 97.0%
  • Dockerfile 3.0%