Documentation
¶
Overview ¶
Package cli provides a generic command-line interface framework for Zerfoo. This framework uses the plugin registry system to enable extensible, configurable CLI tools.
Index ¶
- func SignalContext(parent context.Context, coord *shutdown.Coordinator) (context.Context, context.CancelFunc)
- type BaseConfig
- type CLI
- type Command
- type CommandRegistry
- type PredictCommand
- type PredictCommandConfig
- type PredictionResult
- type PullCommand
- type RunCommand
- type ServeCommand
- type TokenizeCommand
- func (c *TokenizeCommand) Description() string
- func (c *TokenizeCommand) Examples() []string
- func (c *TokenizeCommand) Name() string
- func (c *TokenizeCommand) Run(_ context.Context, args []string) error
- func (c *TokenizeCommand) Tok() *tokenizer.WhitespaceTokenizer
- func (c *TokenizeCommand) Usage() string
- type WorkerCommand
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SignalContext ¶
func SignalContext(parent context.Context, coord *shutdown.Coordinator) (context.Context, context.CancelFunc)
SignalContext returns a context that is canceled when SIGINT or SIGTERM is received. If a non-nil shutdown.Coordinator is provided, its Shutdown method is called before the context is canceled. The returned cancel function should be deferred by the caller to release signal resources.
Types ¶
type BaseConfig ¶
type BaseConfig struct {
// Common options
Verbose bool `json:"verbose"`
Output string `json:"output"`
Format string `json:"format"` // "json", "yaml", "csv", "text"
ConfigFile string `json:"configFile"`
// Plugin configuration
Plugins map[string]interface{} `json:"plugins"`
// Extension point for command-specific configuration
Extensions map[string]interface{} `json:"extensions"`
}
BaseConfig provides common configuration options for CLI commands.
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
CLI provides the main command-line interface.
func (*CLI) RegisterCommand ¶
RegisterCommand adds a command to the CLI.
type Command ¶
type Command interface {
// Name returns the command name
Name() string
// Description returns the command description
Description() string
// Run executes the command with the given arguments
Run(ctx context.Context, args []string) error
// Usage returns usage information
Usage() string
// Examples returns usage examples
Examples() []string
}
Command represents a generic CLI command with pluggable functionality.
type CommandRegistry ¶
type CommandRegistry struct {
// contains filtered or unexported fields
}
CommandRegistry manages available CLI commands.
func NewCommandRegistry ¶
func NewCommandRegistry() *CommandRegistry
NewCommandRegistry creates a new command registry.
func (*CommandRegistry) Get ¶
func (r *CommandRegistry) Get(name string) (Command, bool)
Get retrieves a command by name.
func (*CommandRegistry) List ¶
func (r *CommandRegistry) List() []string
List returns all registered command names.
func (*CommandRegistry) Register ¶
func (r *CommandRegistry) Register(cmd Command)
Register adds a command to the registry.
type PredictCommand ¶
PredictCommand implements model prediction using the plugin system.
func NewPredictCommand ¶
func NewPredictCommand[T tensor.Numeric](registry *model.ModelRegistry[T], fromFloat64 func(float64) T, toFloat64 func(T) float64) *PredictCommand[T]
NewPredictCommand creates a new predict command. fromFloat64 converts a float64 CSV value to type T. toFloat64 converts a prediction value of type T back to float64 for output.
func (*PredictCommand[T]) Description ¶
func (c *PredictCommand[T]) Description() string
Description implements Command.Description
func (*PredictCommand[T]) Examples ¶
func (c *PredictCommand[T]) Examples() []string
Examples implements Command.Examples
func (*PredictCommand[T]) Name ¶
func (c *PredictCommand[T]) Name() string
Name implements Command.Name
func (*PredictCommand[T]) Run ¶
func (c *PredictCommand[T]) Run(ctx context.Context, args []string) error
Run implements Command.Run
func (*PredictCommand[T]) Usage ¶
func (c *PredictCommand[T]) Usage() string
Usage implements Command.Usage
type PredictCommandConfig ¶
type PredictCommandConfig struct {
BaseConfig
// Model configuration
ModelPath string `json:"modelPath"`
ModelProvider string `json:"modelProvider"` // Registry key for model provider
ModelConfig map[string]interface{} `json:"modelConfig"`
// Data configuration
DataPath string `json:"dataPath"`
DataProvider string `json:"dataProvider"` // Registry key for data provider
FeatureColumns []string `json:"featureColumns"`
IDColumn string `json:"idColumn"`
GroupColumn string `json:"groupColumn"`
// Prediction configuration
BatchSize int `json:"batchSize"`
IncludeProbs bool `json:"includeProbs"`
Overwrite bool `json:"overwrite"`
}
PredictCommandConfig configures model prediction.
type PredictionResult ¶
type PredictionResult struct {
ModelPath string `json:"modelPath"`
DataPath string `json:"dataPath"`
OutputPath string `json:"outputPath"`
Timestamp time.Time `json:"timestamp"`
Config *PredictCommandConfig `json:"config"`
NumSamples int `json:"numSamples"`
NumFeatures int `json:"numFeatures"`
Predictions []float64 `json:"predictions,omitempty"`
IDs []string `json:"ids,omitempty"`
Duration time.Duration `json:"duration"`
Success bool `json:"success"`
}
PredictionResult contains prediction results and metadata.
type PullCommand ¶
type PullCommand struct {
// contains filtered or unexported fields
}
PullCommand implements the "pull" CLI command for downloading and caching a model from a remote registry.
func NewPullCommand ¶
func NewPullCommand(reg registry.ModelRegistry, out io.Writer) *PullCommand
NewPullCommand creates a new PullCommand. If reg is nil, a default LocalRegistry will be created when the command runs.
func (*PullCommand) Description ¶
func (c *PullCommand) Description() string
Description implements Command.Description.
func (*PullCommand) Examples ¶
func (c *PullCommand) Examples() []string
Examples implements Command.Examples.
type RunCommand ¶
type RunCommand struct {
// contains filtered or unexported fields
}
RunCommand implements the "run" CLI command for interactive prompt-response generation.
func NewRunCommand ¶
func NewRunCommand(in io.Reader, out io.Writer) *RunCommand
NewRunCommand creates a new RunCommand using the given I/O streams.
func (*RunCommand) Description ¶
func (c *RunCommand) Description() string
Description implements Command.Description.
func (*RunCommand) Examples ¶
func (c *RunCommand) Examples() []string
Examples implements Command.Examples.
type ServeCommand ¶
type ServeCommand struct {
// contains filtered or unexported fields
}
ServeCommand implements the "serve" CLI command for starting an OpenAI-compatible HTTP inference server.
func NewServeCommand ¶
func NewServeCommand(coord *shutdown.Coordinator, out io.Writer) *ServeCommand
NewServeCommand creates a new ServeCommand.
func (*ServeCommand) Description ¶
func (c *ServeCommand) Description() string
Description implements Command.Description.
func (*ServeCommand) Examples ¶
func (c *ServeCommand) Examples() []string
Examples implements Command.Examples.
type TokenizeCommand ¶
type TokenizeCommand struct {
// contains filtered or unexported fields
}
TokenizeCommand implements text tokenization.
func NewTokenizeCommand ¶
func NewTokenizeCommand() *TokenizeCommand
NewTokenizeCommand creates a new tokenize command.
func (*TokenizeCommand) Description ¶
func (c *TokenizeCommand) Description() string
Description implements Command.Description
func (*TokenizeCommand) Examples ¶
func (c *TokenizeCommand) Examples() []string
Examples implements Command.Examples
func (*TokenizeCommand) Run ¶
func (c *TokenizeCommand) Run(_ context.Context, args []string) error
Run implements Command.Run
func (*TokenizeCommand) Tok ¶
func (c *TokenizeCommand) Tok() *tokenizer.WhitespaceTokenizer
Tok returns the underlying tokenizer for testing.
func (*TokenizeCommand) Usage ¶
func (c *TokenizeCommand) Usage() string
Usage implements Command.Usage
type WorkerCommand ¶
type WorkerCommand struct {
// contains filtered or unexported fields
}
WorkerCommand implements the "worker" CLI command for starting a distributed training worker.
func NewWorkerCommand ¶
func NewWorkerCommand(coord *shutdown.Coordinator) *WorkerCommand
NewWorkerCommand creates a new WorkerCommand. The shutdown coordinator is used to register the worker node for orderly shutdown on signal.
func (*WorkerCommand) Description ¶
func (c *WorkerCommand) Description() string
Description implements Command.Description.
func (*WorkerCommand) Examples ¶
func (c *WorkerCommand) Examples() []string
Examples implements Command.Examples.
func (*WorkerCommand) Run ¶
func (c *WorkerCommand) Run(ctx context.Context, args []string) error
Run implements Command.Run. It parses flags, creates a WorkerNode, starts it, and blocks until the context is canceled (e.g. by SIGTERM).
func (*WorkerCommand) Usage ¶
func (c *WorkerCommand) Usage() string
Usage implements Command.Usage.