summarize

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package summarize asks a configured model for a cited upgrade-risk summary of a digest and keeps only the claims that cite entry IDs it was sent.

Index

Constants

View Source
const (
	// AnthropicBaseURL is the Anthropic API when llm.base_url is empty.
	AnthropicBaseURL = "https://api.anthropic.com"
	// AnthropicKeyEnv holds the API key when llm.api_key_env is empty.
	AnthropicKeyEnv = "ANTHROPIC_API_KEY"
)
View Source
const (
	APIMessages        = "messages"
	APIChatCompletions = "chat-completions"
)

The wire APIs of the bedrock-mantle endpoint, the values of llm.api.

View Source
const (
	ProviderOpenAI    = "openai-compatible"
	ProviderAnthropic = "anthropic"
	ProviderBedrock   = "bedrock"
	ProviderMantle    = "bedrock-mantle"
)

Provider names, the values of llm.provider.

View Source
const MaxTimeout = 2 * time.Minute

MaxTimeout caps llm.timeout: it is the longest single attempt httpx allows.

Variables

View Source
var ErrNotConfigured = errors.New("llm not configured")

ErrNotConfigured means the llm config can't make a call. The caller warns and prints the report without a summary.

Functions

func LoadAWSConfig

func LoadAWSConfig(
	ctx context.Context, profile string, transport http.RoundTripper, logger *slog.Logger,
) (aws.Config, error)

LoadAWSConfig reads the shared AWS config and credentials for profile (empty means the default chain). It makes no request; credentials are fetched on the first call. A non-nil transport carries every request, and the SDK logs to logger.

func MantleAPI

func MantleAPI(api, model string) string

MantleAPI returns api, or for an empty api, messages for Anthropic model IDs and chat-completions for the rest.

func MantleBaseURL

func MantleBaseURL(region, api string) string

MantleBaseURL returns the regional base URL that api is served under.

func Timeout

func Timeout(c config.LLM) (time.Duration, error)

Timeout returns llm.timeout, capped at MaxTimeout.

func WithBedrockAPIKey

func WithBedrockAPIKey(key string) func(*bedrockruntime.Options)

WithBedrockAPIKey makes the client send key, an Amazon Bedrock API key, as a bearer token instead of signing with SigV4.

Types

type Anthropic

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

Anthropic calls the Anthropic Messages API.

func NewAnthropic

func NewAnthropic(hc *http.Client, baseURL, apiKey, model string) *Anthropic

NewAnthropic returns a provider that posts to baseURL + "/v1/messages".

func (*Anthropic) Complete

func (a *Anthropic) Complete(ctx context.Context, p Prompt) (string, error)

Complete sends p and joins the text blocks of the answer.

type Bedrock

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

Bedrock calls the Amazon Bedrock Converse API.

func NewBedrock

func NewBedrock(cfg aws.Config, model string, optFns ...func(*bedrockruntime.Options)) *Bedrock

NewBedrock returns a provider for cfg; optFns change the client, such as its endpoint in tests.

func (*Bedrock) Complete

func (b *Bedrock) Complete(ctx context.Context, p Prompt) (string, error)

Complete sends p with Converse and joins the text blocks of the answer.

type Env

type Env struct {
	Lookup    func(string) (string, bool)
	Transport http.RoundTripper // nil means the network
	Logger    *slog.Logger
	UserAgent string
}

Env is what New takes from the outside world.

type Mantle

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

Mantle calls the bedrock-mantle endpoint of Amazon Bedrock with the Anthropic Messages or the OpenAI Chat Completions API.

func NewMantle

func NewMantle(o MantleOptions, e Env) (*Mantle, error)

NewMantle returns a provider for o. Requests go through httpx with e's transport, signed with SigV4 unless o has an API key.

func (*Mantle) API

func (m *Mantle) API() string

API returns the wire API m sends.

func (*Mantle) Complete

func (m *Mantle) Complete(ctx context.Context, p Prompt) (string, error)

Complete sends p and returns the text of the answer.

type MantleOptions

type MantleOptions struct {
	Model       string
	API         string // APIMessages or APIChatCompletions; empty picks by model ID, see [MantleAPI]
	BaseURL     string // empty means [MantleBaseURL]
	Region      string
	APIKey      string                  // an Amazon Bedrock API key; empty signs with SigV4
	Credentials aws.CredentialsProvider // for SigV4
	Now         func() time.Time        // nil means time.Now
}

MantleOptions configures NewMantle.

type OpenAI

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

OpenAI calls the chat completions endpoint of an OpenAI-compatible API, such as OpenAI, LiteLLM, Ollama or vLLM.

func NewOpenAI

func NewOpenAI(hc *http.Client, baseURL, apiKey, model string) *OpenAI

NewOpenAI returns a provider that posts to baseURL + "/chat/completions".

func (*OpenAI) Complete

func (o *OpenAI) Complete(ctx context.Context, p Prompt) (string, error)

Complete sends p as a system and a user message.

type Options

type Options struct {
	Provider       string // the llm.provider value
	Model          string
	MaxInputTokens int
}

Options says which model the summary names and how much input it may get.

type Prompt

type Prompt struct {
	System string
	User   string
}

Prompt is one system message and one user message.

type Provider

type Provider interface {
	Complete(ctx context.Context, p Prompt) (string, error)
}

Provider sends one prompt to a model and returns the text of its answer.

func New

func New(ctx context.Context, c config.LLM, e Env) (Provider, error)

New returns the provider that c names. It makes no network call, so with no provider configured --summarize sends nothing.

type Result

type Result struct {
	Summary  *report.Summary // nil when no claim survived the check
	Warnings []string
}

Result is a summary and the warnings the caller prints.

func Summarize

func Summarize(ctx context.Context, p Provider, d *report.Digest, o Options) (*Result, error)

Summarize sends the digest's listed entries to p and checks the answer. Entries go lowest confidence first when the prompt would exceed o.MaxInputTokens. An error means the provider failed; the caller reports it as a warning.

type SentField added in v0.7.0

type SentField struct {
	Part        string `json:"part"` // request, or the type of a line in the user message: upgrade or entry
	Name        string `json:"name"`
	Description string `json:"description"`
}

SentField is one value a --summarize request carries to the model provider.

func SentToModel added in v0.7.0

func SentToModel() []SentField

SentToModel returns every value a --summarize request carries. A test checks the upgrade and entry fields against the user message that Summarize builds.

Jump to

Keyboard shortcuts

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