llm

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package llm is the provider-agnostic LLM abstraction the writer agent calls into. In v0.2 the only working implementation is Noop - real providers (Anthropic, OpenAI, local models) will land in v0.3 behind this same interface, so nothing above this package needs to change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Anthropic added in v0.7.0

type Anthropic struct {
	BaseURL string
	APIKey  string
	Model   string
	HTTP    *http.Client
}

Anthropic talks to Anthropic's Messages API.

func NewAnthropic added in v0.7.0

func NewAnthropic(s config.LLMSettings) *Anthropic

func (*Anthropic) Generate added in v0.7.0

func (c *Anthropic) Generate(ctx context.Context, req Request) (Response, error)

func (*Anthropic) Name added in v0.7.0

func (c *Anthropic) Name() string

type Client

type Client interface {
	Name() string
	Generate(ctx context.Context, req Request) (Response, error)
}

Client is the contract every provider implements. Generate must respect ctx cancellation; Name is used in logs so users can see which provider produced a given draft.

func New

func New(s config.LLMSettings) (Client, string)

New constructs a Client from settings. Unknown providers - or known providers with incomplete configuration - fall back to Noop with a warning surfaced via the returned message. We never crash the CLI just because config.json names a provider we don't ship yet.

type Noop

type Noop struct{}

Noop is a Client that returns an empty response, signalling "no LLM content - use your fallback". It exists so the writer agent's call site is identical whether or not a real provider is configured.

func (Noop) Generate

func (Noop) Generate(_ context.Context, _ Request) (Response, error)

func (Noop) Name

func (Noop) Name() string

type OpenAICompatible

type OpenAICompatible struct {
	ProviderName string
	BaseURL      string
	APIKey       string
	Model        string
	HTTP         *http.Client
}

OpenAICompatible talks to any HTTP chat-completions endpoint that mirrors OpenAI's request/response shape (OpenAI proper, Together, vLLM, Ollama's OpenAI shim, etc.). The implementation is intentionally minimal: only model + messages + max_tokens go on the wire, and only the first choice is returned.

func NewOpenAICompatible

func NewOpenAICompatible(s config.LLMSettings) *OpenAICompatible

NewOpenAICompatible constructs the client. No network call is made.

func NewOpenAICompatibleNamed added in v0.7.0

func NewOpenAICompatibleNamed(name string, s config.LLMSettings) *OpenAICompatible

NewOpenAICompatibleNamed constructs a chat-completions client with a user-facing provider name. Useful for providers that intentionally expose an OpenAI-compatible API but should be logged as "openai", "ollama", etc.

func (*OpenAICompatible) Generate

func (c *OpenAICompatible) Generate(ctx context.Context, req Request) (Response, error)

Generate sends one chat-completions request and returns the first choice. It validates required config up front so the user sees a clear error before any network I/O happens.

func (*OpenAICompatible) Name

func (c *OpenAICompatible) Name() string

type Request

type Request struct {
	System string
	Prompt string
	// MaxTokens is a hint - providers may clamp or ignore it.
	MaxTokens int
}

Request is the minimal payload we send to a provider. We keep it small on purpose: agents that want richer behavior should compose extra context into Prompt rather than growing this struct.

type Response

type Response struct {
	Text     string
	Provider string
	Model    string
}

Response is what a provider returns. Empty Text is a valid response and signals "I have nothing to add" - callers must fall back gracefully.

Jump to

Keyboard shortcuts

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