diff --git a/Helper/GptHelper.php b/Tools/AutoGpt/GptHelper.php similarity index 84% rename from Helper/GptHelper.php rename to Tools/AutoGpt/GptHelper.php index 2006162..b134c75 100644 --- a/Helper/GptHelper.php +++ b/Tools/AutoGpt/GptHelper.php @@ -1,6 +1,6 @@ getBody()); } - public static function handleFile(string $inPath, string $outPath, string $behavior, \Closure $fileReader) : string + public static function handleFile(string $inPath, string $outPath, string $behavior, \Closure $fileReader, bool $bulk = true) : string { $response = ''; @@ -78,7 +78,16 @@ class GptHelper $lines = ''; while (($line = $fileReader($in, $inPath)) !== false) { - if (\strlen($lines) > self::MAX_STRLEN) { + $line = \str_replace(' ', "\t", $line); + if (\strlen($line) > self::MAX_STRLEN) { + continue; + } + + if (!$bulk) { + $lines = $line; + } + + if (!$bulk || \strlen($lines) + \strlen($line) > self::MAX_STRLEN) { $response = self::aiRequest($behavior, $lines); if ($response === '' || $response === false) { @@ -92,10 +101,12 @@ class GptHelper $lines = ''; } - $lines .= $line . "\n"; + if ($bulk) { + $lines .= $line . "\n"; + } } - if (\trim($lines) !== '') { + if (\trim($lines) !== '' && \strlen($lines) <= self::MAX_STRLEN) { $response = self::aiRequest($behavior, $lines); if ($response !== '' && $response !== false) { @@ -111,7 +122,7 @@ class GptHelper } if ($inPath === $outPath) { - if (\ftell($out) / \ftell($in) < 0.9) { + if (\ftell($in) === 0 || \ftell($out) / \ftell($in) < 0.9) { \unlink($outPath . '.out'); } else { \unlink($outPath); diff --git a/Tools/AutoGpt/autoDocblock.php b/Tools/AutoGpt/autoDocblock.php new file mode 100644 index 0000000..10aa2e5 --- /dev/null +++ b/Tools/AutoGpt/autoDocblock.php @@ -0,0 +1,67 @@ + 1300) { + return false; + } + + $lines = ''; + $isFirstLine = true; + + while (($line = \fgets($in)) !== false) { + $isFirstLine = false; + $lines .= $line; + } + + if ($isFirstLine && empty($lines)) { + return false; + } + + return $lines; +}; + +foreach ($globs as $glob) { + $files = \glob($glob); + + foreach ($files as $file) { + if (\stripos($file, 'Test.php')) { + continue; + } + + GptHelper::handleFile($file, $file, $behaviour, $fileReader); + } +} diff --git a/Helper/autoGpt.php b/Tools/AutoGpt/autoGpt.php similarity index 96% rename from Helper/autoGpt.php rename to Tools/AutoGpt/autoGpt.php index 1861fb6..c96e175 100644 --- a/Helper/autoGpt.php +++ b/Tools/AutoGpt/autoGpt.php @@ -2,13 +2,13 @@ use Build\Helper\GptHelper; -include __DIR__ . '/../../phpOMS/Autoloader.php'; +include __DIR__ . '/../../../phpOMS/Autoloader.php'; // fix docblocks $globs = [ - __DIR__ . '/../../phpOMS/**/*.php', - __DIR__ . '/../../Modules/*/Models/*.php', - __DIR__ . '/../../Modules/*/Controller/*.php', + __DIR__ . '/../../../phpOMS/**/*.php', + __DIR__ . '/../../../Modules/*/Models/*.php', + __DIR__ . '/../../../Modules/*/Controller/*.php', ]; $behaviour = <<