promptdiff

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package promptdiff computes structural and token diffs between two prompt versions, with README-matching output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySemantic added in v1.5.0

func ApplySemantic(ctx context.Context, d *Diff, client embed.Client, oldP, newP *prompt.Template) error

ApplySemantic embeds oldP.Body and newP.Body with client and sets d.SemanticSimilarity to their cosine similarity.

Types

type CostLine

type CostLine struct {
	Model string  `json:"model"`
	Old   float64 `json:"old"`
	New   float64 `json:"new"`
	Delta float64 `json:"delta"`
	// Approx is true when Model has no known BPE vocabulary, so the token
	// counts behind Old/New/Delta are approximated with cl100k_base rather
	// than the model's real tokenizer.
	Approx bool `json:"approx"`
	// CacheSupported is true when Model's provider family has a modeled
	// prompt-caching discount (see internal/cost.IsCacheSupported). When
	// false, CachedOld/CachedNew/CachedDelta are zero and should be ignored
	// rather than read as "no savings".
	CacheSupported bool `json:"cache_supported"`
	// CachedOld/CachedNew/CachedDelta project cost the same way as
	// Old/New/Delta, but assume the whole prompt is cached: the first of the
	// 100k invocations pays the provider's cache-write price, the rest pay
	// the cheaper cache-read price. Only meaningful when CacheSupported.
	CachedOld   float64 `json:"cached_old,omitempty"`
	CachedNew   float64 `json:"cached_new,omitempty"`
	CachedDelta float64 `json:"cached_delta,omitempty"`
}

CostLine is one model row of the cost projection.

type Diff

type Diff struct {
	TokenDelta      int         `json:"token_delta"`
	TokenPercent    float64     `json:"token_percent"`
	Costs           []CostLine  `json:"costs"`
	AddedSections   []string    `json:"added_sections,omitempty"`
	RemovedSections []string    `json:"removed_sections,omitempty"`
	ModifiedVars    []VarChange `json:"modified_vars,omitempty"`
	AddedVars       []string    `json:"added_vars,omitempty"`
	RemovedVars     []string    `json:"removed_vars,omitempty"`
	// SemanticSimilarity is the cosine similarity, in [-1, 1], between the
	// old and new prompt body embeddings. Nil unless semantic diffing ran.
	SemanticSimilarity *float64 `json:"semantic_similarity,omitempty"`
}

Diff is the result of comparing two versions of a prompt.

func Compare

func Compare(oldP, newP *prompt.Template) Diff

Compare diffs oldP -> newP.

type VarChange

type VarChange struct {
	From string `json:"from"`
	To   string `json:"to"`
}

VarChange records a variable that was renamed.

Jump to

Keyboard shortcuts

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