How ghchinoy/gen works
Project type and purpose
• Type: Command-line application (CLI) written in Go.
• Purpose: Expose a gen command with subcommands (prompt, tokens, interactive, version, etc.) to call Google Cloud’s Vertex AI Generative AI models (Gemini, PaLM) and Model Garden models (Anthropic’s Claude, etc.), manage config, and display results.
File structure
• Top-level files
– main.go: Instantiates and runs the root Cobra command.
– go.mod/go.sum: Go module definitions and dependencies.
– README.md, LICENSE, .gitignore: Project metadata.
• Directories
– internal/cmd: Implements the CLI commands using Cobra (root.go, prompt/interactive/tokens/version commands, flags, help text).
– internal/model: Defines model-specific wrappers and interfaces (Gemini, PaLM, Anthropic), model selection logic, request/response types, config schemas.
– media: Example GIF for README; not part of runtime.
• Scripts
– makedist: Build/release helper.
Extract architecture from README
• Usage patterns:
– Single-shot gen prompt calls.
– Token counting via gen tokens.
– Interactive REPL mode.
– Model-parameterization via --model and --config flags.
• Dependencies & flow:
– Standard Google Cloud auth (ADC).
– HTTP/REST or gRPC calls to Vertex AI endpoint.
– Optional JSON file input/output.
Main components
a. User Interface (CLI):
– STDIN (user types commands) / STDOUT (console output)
– main.go → Cobra root & subcommands (internal/cmd)
b. Command Dispatcher & Flag Parser:
– Flag parsing (--project, --region, --model, --config, --output)
– Subcommands: prompt, tokens, interactive, version
c. Model Abstraction Layer:
– internal/model interface that selects and configures the correct model client (Gemini, PaLM, Anthropic).
– Config loader (JSON → Go structs)
d. Authentication & Environment:
– Google ADC (env var / gcloud CLI)
– Env vars: PROJECT_ID, REGION
e. External Services:
– Google Vertex AI Generative API (Gemini, PaLM)
– Model Garden endpoints (Anthropic Claude)
f. Output Formatter:
– Plain text logger
– JSON serialization (if --output json)
Relationships & data flow
1. User issues gen prompt "..."
2. Cobra parses flags and dispatches to PromptCommand
3. Command code calls Model Abstraction Layer
4. Abstraction layer reads config, selects model client
5. Model client uses HTTP/gRPC to call Vertex AI / Model Garden
6. Response marshaled back through abstraction → Command → STDOUT
Architectural patterns & design principles
• Command pattern (Cobra) for subcommands.
• Adapter/strategy pattern for pluggable model clients.
• Layered separation: CLI → Command logic → Model layer → External API.
• Single Responsibility: each package has a distinct role.
Essential elements to capture
• Clear component names matching directory/package names.
• Notes on flags/env vars that affect routing (project/region/model/config).