cli/internal/cmd/ml/cmd_worker.go
Claude e025577092
refactor: split CLI from monorepo, import core/go as library
- Change module from forge.lthn.ai/core/go to forge.lthn.ai/core/cli
- Remove pkg/ directory (now served from core/go)
- Add require + replace for forge.lthn.ai/core/go => ../go
- Update go.work to include ../go workspace module
- Fix all internal/cmd/* imports: pkg/ refs → forge.lthn.ai/core/go/pkg/
- Rename internal/cmd/sdk package to sdkcmd (avoids conflict with pkg/sdk)
- Remove SDK library files from internal/cmd/sdk/ (now in core/go/pkg/sdk/)
- Remove duplicate RAG helper functions from internal/cmd/rag/
- Remove stale cmd/core-ide/ (now in core/ide repo)
- Update IDE variant to remove core-ide import
- Fix test assertion for new module name
- Run go mod tidy to sync dependencies

core/cli is now a pure CLI application importing core/go for packages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 14:22:18 +00:00

80 lines
2.7 KiB
Go

package ml
import (
"time"
"forge.lthn.ai/core/go/pkg/cli"
"forge.lthn.ai/core/go/pkg/ml"
)
var (
workerAPIBase string
workerID string
workerName string
workerAPIKey string
workerGPU string
workerVRAM int
workerLangs string
workerModels string
workerInferURL string
workerTaskType string
workerBatchSize int
workerPoll time.Duration
workerOneShot bool
workerDryRun bool
)
var workerCmd = &cli.Command{
Use: "worker",
Short: "Run a distributed worker node",
Long: "Polls the LEM API for tasks, runs local inference, and submits results.",
RunE: runWorker,
}
func init() {
workerCmd.Flags().StringVar(&workerAPIBase, "api", ml.EnvOr("LEM_API", "https://infer.lthn.ai"), "LEM API base URL")
workerCmd.Flags().StringVar(&workerID, "id", ml.EnvOr("LEM_WORKER_ID", ml.MachineID()), "Worker ID")
workerCmd.Flags().StringVar(&workerName, "name", ml.EnvOr("LEM_WORKER_NAME", ml.Hostname()), "Worker display name")
workerCmd.Flags().StringVar(&workerAPIKey, "key", ml.EnvOr("LEM_API_KEY", ""), "API key")
workerCmd.Flags().StringVar(&workerGPU, "gpu", ml.EnvOr("LEM_GPU", ""), "GPU type")
workerCmd.Flags().IntVar(&workerVRAM, "vram", ml.IntEnvOr("LEM_VRAM_GB", 0), "GPU VRAM in GB")
workerCmd.Flags().StringVar(&workerLangs, "languages", ml.EnvOr("LEM_LANGUAGES", ""), "Comma-separated language codes")
workerCmd.Flags().StringVar(&workerModels, "models", ml.EnvOr("LEM_MODELS", ""), "Comma-separated model names")
workerCmd.Flags().StringVar(&workerInferURL, "infer", ml.EnvOr("LEM_INFER_URL", "http://localhost:8090"), "Local inference endpoint")
workerCmd.Flags().StringVar(&workerTaskType, "type", "", "Filter by task type")
workerCmd.Flags().IntVar(&workerBatchSize, "batch", 5, "Tasks per poll")
workerCmd.Flags().DurationVar(&workerPoll, "poll", 30*time.Second, "Poll interval")
workerCmd.Flags().BoolVar(&workerOneShot, "one-shot", false, "Process one batch and exit")
workerCmd.Flags().BoolVar(&workerDryRun, "dry-run", false, "Fetch tasks but don't run inference")
}
func runWorker(cmd *cli.Command, args []string) error {
if workerAPIKey == "" {
workerAPIKey = ml.ReadKeyFile()
}
cfg := &ml.WorkerConfig{
APIBase: workerAPIBase,
WorkerID: workerID,
Name: workerName,
APIKey: workerAPIKey,
GPUType: workerGPU,
VRAMGb: workerVRAM,
InferURL: workerInferURL,
TaskType: workerTaskType,
BatchSize: workerBatchSize,
PollInterval: workerPoll,
OneShot: workerOneShot,
DryRun: workerDryRun,
}
if workerLangs != "" {
cfg.Languages = ml.SplitComma(workerLangs)
}
if workerModels != "" {
cfg.Models = ml.SplitComma(workerModels)
}
ml.RunWorkerLoop(cfg)
return nil
}