rewrite

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package rewrite is the optional Layer 2 pass. It hands text to a model to do what the deterministic rules cannot, like reworking a sentence to drop a semicolon or bending the text toward a chosen voice.

Index

Constants

View Source
const (
	// DefaultOpenAIModel is the model used for --provider openai when none is set.
	DefaultOpenAIModel = "gpt-4o"
	// DefaultOpenAIBaseURL is the OpenAI Chat Completions base. Any OpenAI-compatible
	// server, like a local Ollama or a router, is reached by overriding it.
	DefaultOpenAIBaseURL = "https://api.openai.com/v1"
)

OpenAI-compatible Chat Completions constants.

View Source
const DefaultModel = "claude-opus-4-8"

DefaultModel is the model used when none is set.

Variables

This section is empty.

Functions

This section is empty.

Types

type Completer

type Completer interface {
	Complete(ctx context.Context, system, user string) (string, error)
}

Completer sends a system prompt and a user prompt to a model and returns the text of the reply.

func NewAnthropicCompleter

func NewAnthropicCompleter(model string) Completer

NewAnthropicCompleter returns a Completer that calls the Anthropic Messages API over HTTP. It reads the API key from the ANTHROPIC_API_KEY environment variable. Talking to the API directly keeps the deterministic core free of the Anthropic SDK and its dependency tree, so the default binary stays small.

func NewCompleter added in v0.10.0

func NewCompleter(provider Provider, model, baseURL string) (Completer, error)

NewCompleter returns the Completer for provider. model and baseURL may be empty, in which case the provider's own defaults stand. baseURL only applies to the OpenAI provider. An unknown provider is an error.

func NewOpenAICompleter added in v0.10.0

func NewOpenAICompleter(model, baseURL string) Completer

NewOpenAICompleter returns a Completer that calls an OpenAI-compatible Chat Completions API. It reads the API key from OPENAI_API_KEY. An empty model or base URL falls back to the OpenAI defaults. A local base URL may run without a key, since servers like Ollama ignore the Authorization header.

type CompleterFunc

type CompleterFunc func(ctx context.Context, system, user string) (string, error)

CompleterFunc adapts a function to the Completer interface.

func (CompleterFunc) Complete

func (f CompleterFunc) Complete(ctx context.Context, system, user string) (string, error)

Complete calls the wrapped function.

type Issue added in v0.7.0

type Issue struct {
	// Kind is added, removed, or changed.
	Kind string `json:"kind"`
	// Was is the original wording, empty when the rewrite added something.
	Was string `json:"was"`
	// Now is the rewrite wording, empty when the rewrite removed something.
	Now string `json:"now"`
	// Note is a short reason for the issue.
	Note string `json:"note"`
}

Issue is one meaning change between the original and the rewrite.

type Judge added in v0.7.0

type Judge struct {
	// contains filtered or unexported fields
}

Judge compares an original text with its rewrite through a Completer and reports any change in meaning. It is the optional Layer 3 pass behind the --verify flag.

func NewJudge added in v0.7.0

func NewJudge(completer Completer) *Judge

NewJudge returns a Judge. It panics if completer is nil, since that is a programming error in this internal package.

func (*Judge) Judge added in v0.7.0

func (j *Judge) Judge(ctx context.Context, original, rewrite string) (Verdict, error)

Judge asks the model whether rewrite preserves the meaning of original and returns its verdict.

type Provider added in v0.10.0

type Provider string

Provider names a model backend the rewrite pass can talk to.

const (
	// ProviderAnthropic is the Anthropic Messages API, the default.
	ProviderAnthropic Provider = "anthropic"
	// ProviderOpenAI is any OpenAI-compatible Chat Completions API, including a local
	// server like Ollama when its base URL is set.
	ProviderOpenAI Provider = "openai"
)

type Rewriter

type Rewriter struct {
	// contains filtered or unexported fields
}

Rewriter rewrites text through a Completer using a built system prompt.

func New

func New(completer Completer, tone ...string) *Rewriter

New returns a Rewriter. It panics if completer is nil, since that is a programming error in this internal package.

func (*Rewriter) Rewrite

func (r *Rewriter) Rewrite(ctx context.Context, text string, feedback ...string) (string, error)

Rewrite returns the text rewritten to read like a person wrote it. Any feedback notes name facts a prior attempt changed, so the model can preserve them this time.

type Verdict added in v0.7.0

type Verdict struct {
	// Faithful reports whether the rewrite preserved the original's meaning.
	Faithful bool `json:"faithful"`
	// Issues lists each meaning change the judge found.
	Issues []Issue `json:"issues"`
}

Verdict is the meaning-comparison result from the judge.

Directories

Path Synopsis
Package prompt builds the instructions the rewrite and verify passes send the model.
Package prompt builds the instructions the rewrite and verify passes send the model.

Jump to

Keyboard shortcuts

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