llm

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 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 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 {
	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 (*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