go-llm-pipeline

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: MIT

README

go-llm-pipeline

An idiomatic, dependency-free Go toolkit for local-first, deterministic LLM orchestration and structured data extraction.

Overview

go-llm-pipeline provides statically typed pipelines for high-throughput, batch LLM workloads. It favors deterministic, VCR-style testing over live API calls, routes natively to local inference engines (Ollama) as well as hosted providers (OpenAI, Gemini), and processes generic assets through concurrent worker pools. It is a Go library with no server component and a light dependency footprint.

Installation

go get github.com/vmontagh/go-llm-pipeline

The module targets Go 1.26 (see go.mod).

Quick start

pkg/pipeline provides a generic worker-pool consumer. Consume starts a pool of workers that read from a channel, honor context cancellation, and run your process function for each item:

package main

import (
	"context"
	"fmt"
	"sync"

	"github.com/vmontagh/go-llm-pipeline/pkg/pipeline"
)

func main() {
	ctx := context.Background()

	input := make(chan int)
	go func() {
		defer close(input)
		for i := 0; i < 5; i++ {
			input <- i
		}
	}()

	var wg sync.WaitGroup
	pipeline.Consume(ctx, input, 3, &wg, func(ctx context.Context, n int) {
		fmt.Println("processed", n)
	})
	wg.Wait()
}

Consume also accepts options such as WithPauseGate to pause and resume processing at runtime.

Package map

Package Description
pkg/analyzer Template Method and Builder contracts for LLM analysis (Event/Analyzer, domain-agnostic Asset, sentinel errors).
pkg/pipeline Concurrency utilities: generic worker-pool Consume, PauseGate, and a dead-letter queue.
pkg/provider Concurrency-safe KeyPool of API credentials with per-key cooldown and rotation.
pkg/provider/openai Transport half of the analyzer Template Method for OpenAI.
pkg/provider/gemini Transport half of the analyzer Template Method for Gemini.
pkg/provider/ollama Transport half of the analyzer Template Method for local Ollama.
pkg/strategy Ensemble generation and judge-synthesis strategies (Generator/Judge).
pkg/policy Provider-agnostic retry/error taxonomy (tiers, RetryPolicy, error classification).
pkg/scrub Regexp-based text scrubbing to redact sensitive patterns and PII.
pkg/vcrpatch Patch and rewrite VCR cassettes (match requests, apply actions).
pkg/llmvcr Standalone VCR record/replay for provider http.Clients; auto-redacts secrets (via pkg/scrub) before writing cassettes; fail-fast on miss.
pkg/llmtest Mock provider response/interaction fixtures for deterministic tests.
pkg/observ Observability HTTP server (pprof) bound to a loopback address.
pkg/trace runtime/trace-based Tracer plus a no-op implementation.
pkg/httputil Small protocol-level HTTP helpers, independent of business logic.
pkg/logger Helpers for creating *slog.Logger instances.

Determinism and testing

Deterministic, zero-cost CI is a first-class goal. The determinism toolkit is centered on pkg/llmvcr, with supporting packages for cassette patching, redaction rules, and fixtures:

  • pkg/llmvcr is the productized record/replay package. It returns a standard *http.Client that records provider HTTP interactions to YAML cassettes and replays them offline, failing fast with llmvcr.ErrCassetteMiss on a cassette miss instead of making a live call. It works with any client that accepts an *http.Client, including the OpenAI provider (openai.WithHTTPClient) and the Gemini genai.Client (option.WithHTTPClient). Sensitive headers, query parameters, and body tokens (bearer tokens, sk- and AIza keys) are redacted via pkg/scrub before any cassette is written.
  • pkg/vcrpatch patches and rewrites recorded cassettes for scenario testing.
  • pkg/scrub provides the regexp redaction rules reused by pkg/llmvcr (and usable for logs).
  • pkg/llmtest provides mock provider response and interaction fixtures for tests.
rec, err := llmvcr.New("testdata/openai_success", llmvcr.ModeReplayOnly)
if err != nil {
    // handle error
}
defer func() {
    if err := rec.Stop(); err != nil {
        log.Printf("stopping recorder: %v", err)
    }
}()
provider := openai.NewProvider(apiKeys, openai.WithHTTPClient(rec.HTTPClient()))

Development

Common make targets:

Target Description
make build Compile all packages.
make test Run the full test suite with the race detector.
make test-unit-cover Run tests with a coverage profile.
make lint Run golangci-lint.
make lint-arch Run the architecture linter (go-arch-lint).
make fmt Format the code with gofmt.
make vet Run go vet.
make tidy Run go mod tidy.
make clean Remove generated artifacts.

Roadmap

The product roadmap and positioning notes have moved to docs/ROADMAP.md.

License

Released under the MIT License.

Directories

Path Synopsis
pkg
analyzer
Package analyzer provides the Template Method and Builder patterns for LLM-based analysis.
Package analyzer provides the Template Method and Builder patterns for LLM-based analysis.
httputil
Package httputil contains small, protocol-level HTTP helpers that are independent of any business logic in this repository.
Package httputil contains small, protocol-level HTTP helpers that are independent of any business logic in this repository.
llmvcr
Package llmvcr provides a productized VCR (record/replay) workflow for the standard Go http.Client instances used by LLM provider SDKs.
Package llmvcr provides a productized VCR (record/replay) workflow for the standard Go http.Client instances used by LLM provider SDKs.
logger
Package logger provides helpers for creating *slog.Logger instances.
Package logger provides helpers for creating *slog.Logger instances.
observ
Package observ provides functionality for observ.
Package observ provides functionality for observ.
pipeline
Package pipeline provides foundational concurrency utilities used by the orchestrator: a generic worker-pool consumer and a dead-letter queue for failed pipeline events.
Package pipeline provides foundational concurrency utilities used by the orchestrator: a generic worker-pool consumer and a dead-letter queue for failed pipeline events.
policy
Package policy holds the foundational, provider-agnostic retry/error taxonomy shared by every layer that needs to make routing decisions on a failure: the analyzer adapters, the orchestrator/tagger pipeline and the CLI composition root.
Package policy holds the foundational, provider-agnostic retry/error taxonomy shared by every layer that needs to make routing decisions on a failure: the analyzer adapters, the orchestrator/tagger pipeline and the CLI composition root.
provider
Package provider — keypool.go implements KeyPool, the concurrency-safe pool of API credentials with per-key cooldown semantics that the per-backend analyzer providers (openai, gemini, ollama) use to rotate keys on quota / rate-limit errors.
Package provider — keypool.go implements KeyPool, the concurrency-safe pool of API credentials with per-key cooldown semantics that the per-backend analyzer providers (openai, gemini, ollama) use to rotate keys on quota / rate-limit errors.
provider/gemini
Package gemini implements the transport half of the analyzer Template Method using Google's Gemini models.
Package gemini implements the transport half of the analyzer Template Method using Google's Gemini models.
provider/ollama
Package ollama implements the transport half of the analyzer Template Method using a locally running Ollama instance with a vision-capable model.
Package ollama implements the transport half of the analyzer Template Method using a locally running Ollama instance with a vision-capable model.
provider/openai
Package openai implements the transport half of the analyzer Template Method for the OpenAI chat-completions API.
Package openai implements the transport half of the analyzer Template Method for the OpenAI chat-completions API.
scrub
Package scrub provides text scrubbing utilities for redacting sensitive patterns from strings.
Package scrub provides text scrubbing utilities for redacting sensitive patterns from strings.
trace
Package trace provides tracing functionality.
Package trace provides tracing functionality.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL