VOOZH about

URL: https://deepwiki.com/guanguans/ai-commit/5-ai-generator-system

⇱ AI Generator System | guanguans/ai-commit | DeepWiki


Loading...
Menu

AI Generator System

This page provides an overview of the AI generator subsystem in ai-commit: its purpose, the types of generators available, and how the pieces relate to each other. It is the parent page for:

For configuration of individual generators (API keys, model parameters, binary paths), see Generator-Specific Configuration. For how the CommitCommand selects and invokes a generator at runtime, see Commit Command Workflow.


Purpose

The generator subsystem is responsible for taking a formatted prompt string (containing the git diff and commit type instructions) and returning a raw AI-generated commit message string. Every generator implements a single method contract: generate(string $prompt): string.

The system supports two categories of generators:

CategoryMechanismExamples
API-basedHTTP requests via a custom clientOpenAI, OpenAI Chat, Moonshot, ErnieBot, ErnieBotTurbo
CLI-basedShell subprocess via Symfony ProcessBito CLI, GitHub Copilot CLI, GitHub Models CLI

Key Components

ComponentFileRole
GeneratorContractapp/Contracts/GeneratorContract.phpInterface: defines generate(string $prompt): string
AbstractGeneratorapp/Generators/AbstractGenerator.phpBase class: config injection, output, process helpers
GeneratorManagerapp/GeneratorManager.phpLaravel Manager: resolves and instantiates generator drivers
OpenAIGeneratorapp/Generators/OpenAIGenerator.phpAPI generator for OpenAI completions endpoint
OpenAIChatGeneratorapp/Generators/OpenAIChatGenerator.phpAPI generator for OpenAI chat completions endpoint
MoonshotGeneratorapp/Generators/MoonshotGenerator.phpAPI generator for Moonshot AI
ErnieBotGeneratorapp/Generators/ErnieBotGenerator.phpAPI generator for Baidu ErnieBot
ErnieBotTurboGeneratorapp/Generators/ErnieBotTurboGenerator.phpAPI generator for ErnieBot Turbo variant
BitoCliGeneratorapp/Generators/BitoCliGenerator.phpCLI generator using Bito CLI (stdin prompt)
GithubCopilotCliGeneratorapp/Generators/GithubCopilotCliGenerator.phpCLI generator using GitHub Copilot CLI (argument prompt)
GithubModelsCliGeneratorapp/Generators/GithubModelsCliGenerator.phpCLI generator using GitHub Models CLI (stdin prompt)

Sources: app/GeneratorManager.php1-78 app/Generators/AbstractGenerator.php1-106 app/Generators/BitoCliGenerator.php1-33 app/Generators/GithubCopilotCliGenerator.php1-29 app/Generators/GithubModelsCliGenerator.php1-33 app/Generators/OpenAIChatGenerator.php1-52


Class Hierarchy

Class hierarchy of the generator subsystem:


Sources: app/GeneratorManager.php32-78 app/Generators/AbstractGenerator.php28-106 app/Generators/OpenAIChatGenerator.php19-52 app/Generators/BitoCliGenerator.php18-33 app/Generators/GithubCopilotCliGenerator.php18-29 app/Generators/GithubModelsCliGenerator.php18-33


Driver Resolution Flow

GeneratorManager extends Illuminate\Support\Manager. When generate() is called, it delegates to the active driver, which is resolved by createDriver().

Driver resolution flow from config key to generator instance:


The class name is built in app/GeneratorManager.php70-73 using:

$studlyName = str($config->get('driver', $driver))->replace('openai', 'OpenAI')->studly();
$class = "App\\Generators\\{$studlyName}Generator";

The driver name (e.g., openai_chat) comes from either the --generator CLI option or the ai-commit.generator config key.

Sources: app/GeneratorManager.php41-77


Two Generator Strategies

Data flow for API-based vs CLI-based generators:


Sources: app/Generators/BitoCliGenerator.php22-32 app/Generators/GithubCopilotCliGenerator.php22-28 app/Generators/GithubModelsCliGenerator.php22-32 app/Generators/OpenAIChatGenerator.php29-41


CLI Generator: Prompt Delivery Methods

The three CLI-based generators differ in how the prompt is passed to the subprocess:

GeneratorBinary config keyPrompt deliveryMethod
BitoCliGeneratorbinarystdin (setInput($prompt))mustRunProcess()
GithubCopilotCliGeneratorbinarycommand argumentmustRun($callback)
GithubModelsCliGeneratorbinary + modelstdin (setInput($prompt))mustRunProcess()

All three use ensureWithOptions() app/Generators/AbstractGenerator.php89-92 to append any configured CLI options from options in their config block.


AbstractGenerator Responsibilities

AbstractGenerator app/Generators/AbstractGenerator.php28-106 provides shared infrastructure that all generators rely on:

Method / PropertyDescription
$config (Repository)Illuminate config repository scoped to the generator's config block
$output (OutputStyle)Console output stream set to VERBOSITY_DEBUG
$helperSet (HelperSet)Symfony console helper set from the Artisan kernel
mustRunProcess()Runs a Process via ProcessHelper, throws ProcessFailedException on non-zero exit
runProcess()Runs a Process via ProcessHelper without throwing on failure
runningCallback()Returns a callback that writes stdout/stderr to the output stream
ensureWithOptions()Appends hydratedOptions() to a command array
hydratedOptions()Converts the options config map to a flat CLI option list

The constructor app/Generators/AbstractGenerator.php36-40 clones the global OutputStyle instance and retrieves the HelperSet from the running Artisan instance.

Sources: app/Generators/AbstractGenerator.php28-106


Subpage Navigation

TopicPage
AbstractGenerator, GeneratorContract, GeneratorManager internalsGenerator Architecture
OpenAI, Moonshot, ErnieBot HTTP generatorsAPI-Based Generators
Bito, GitHub Copilot, GitHub Models CLI generatorsCLI-Based Generators
How to implement a new generatorAdding New Generators
Config keys per generator (API key, model, binary)Generator-Specific Configuration
How GeneratorManager is registered as a singletonApplication Foundation
Architecture overview of the full driver resolution systemGenerator System Architecture