llm

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package llm — HTTP client pooling per provider (Block 3.5).

langchaingo constructs a fresh net/http.Transport inside each provider constructor by default. For a long-running server that calls the same provider on every request, that leaks connections: every call-site allocates its own idle-conn pool, TLS session cache, and DNS resolver bucket. Pooling one *http.Client per provider (constructed here) fixes the leak.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*callOptions)

Option configures LLM completion.

func WithJSONMode

func WithJSONMode() Option

func WithMaxTokens

func WithMaxTokens(n int) Option

func WithTemperature

func WithTemperature(t float64) Option

type Provider

type Provider interface {
	Complete(ctx context.Context, prompt string, opts ...Option) (string, error)
	Embed(ctx context.Context, text string) ([]float32, error)
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
	Name() string
	ModelID() string
	// BatchCeiling returns the maximum number of texts that can be
	// passed to EmbedBatch in a single call. Callers that need to
	// process larger inputs must slice to this ceiling. Zero means
	// "no declared ceiling" (rare — only for providers that don't
	// care). Block 3.4.
	BatchCeiling() int
}

Provider is the unified LLM interface.

func NewProvider

func NewProvider(cfg *config.LLMConfig) (Provider, error)

NewProvider constructs the configured provider. When cfg.Provider is "none", NewProvider returns (nil, nil) — the caller must treat a nil Provider as "LLM disabled" and guard accordingly.

func ProviderForProject

func ProviderForProject(cfg *config.Config, slug string) (Provider, error)

ProviderForProject resolves the LLM provider for a given project slug, honoring cfg.LLMOverrides. An unknown / empty slug falls back to cfg.LLM gracefully. Providers are not cached — callers that issue many requests per second should memoize at the call site.

Directories

Path Synopsis
Package mock provides a deterministic llm.Provider implementation for tests.
Package mock provides a deterministic llm.Provider implementation for tests.

Jump to

Keyboard shortcuts

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