tripadvice

package
v0.18.21 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package tripadvice wraps the operator-configured AI provider to generate plain-language observations about a Rivian trip plan: charging stop summary, arrival SoC commentary, adapter warnings, and drive-mode suggestions when the plan looks sub-optimal.

Structure mirrors internal/recap: side-effect-free buildPrompt, stateless Generate, structured JSON output the SPA renders as a card below the route table.

Index

Constants

View Source
const DefaultDCFCRateUSD = 0.43

DefaultDCFCRateUSD is the per-kWh DCFC rate the cost estimator uses when the user hasn't configured per-network rates. Industry average for US public DC fast charging at time of writing.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	OriginLabel      string
	DestinationLabel string
	// DriveMode is the mode the user explicitly chose, or "" for
	// "let the planner pick". Included so the model can say "you
	// planned in Conserve mode" rather than treating it as a mystery.
	DriveMode   string
	StartingSoC float64
	HasAdapter  bool
	// Weather at the origin at departure time. nil when the operator
	// has not enabled the weather feature (recap.weather_enabled).
	Weather *weather.Snapshot
	// TirePressurebars holds [FL, FR, RL, RR] in bar from the live
	// vehicle state. Zero values mean unavailable for that corner.
	TirePressureBars [4]float64
	// PackKWh is the observed battery capacity in kWh from the vehicle
	// record. 0 means unknown.
	PackKWh float64
	// TirePlacardPSI is the user-configured door-jamb cold-fill
	// pressure from the vehicle profile. 0 means unconfigured; the
	// prompt then falls back to a generic "below placard" framing
	// instead of citing a specific number.
	TirePlacardPSI float64
	// HomePricePerKWh is the user's at-home charging cost in
	// HomeCurrency (typically USD). 0 means unconfigured — the cost
	// section degrades to a pure-DCFC estimate.
	HomePricePerKWh float64
	HomeCurrency    string
}

Context bundles user-supplied labels and request parameters that would otherwise be unavailable in the plan response itself.

type CostEstimate

type CostEstimate struct {
	Currency       string  `json:"currency"`
	DCFCSpend      float64 `json:"dcfc_spend"`
	HomeEquivalent float64 `json:"home_equivalent"`
	// DCFCRateUsed is the per-kWh rate (in Currency) the estimate
	// assumed for DCFC stops. Industry average when the user
	// hasn't configured per-network rates.
	DCFCRateUsed float64 `json:"dcfc_rate_used"`
	// HomeRateUsed is the user's configured at-home rate, 0 when
	// unconfigured.
	HomeRateUsed float64 `json:"home_rate_used"`
}

CostEstimate is a deterministic, code-computed projection of trip cost. Two views the user cares about:

  • DCFCSpend is real out-of-pocket money at fast chargers on the planned trip (sum of stop energies × DCFC rate).
  • HomeEquivalent is the all-in energy cost if every kWh used came from the home meter at the user's configured rate — a useful "what is this trip costing me really" number.

type Parsed

type Parsed struct {
	Headline   string   `json:"headline"`
	Cost       []string `json:"cost"`
	Efficiency []string `json:"efficiency"`
	Weather    []string `json:"weather"`
	Vehicle    []string `json:"vehicle"`
}

Parsed is the structured JSON shape the model emits. Each list holds 1-3 short sentences; sections with nothing useful to say stay empty rather than emitting filler.

type Result

type Result struct {
	// Raw is the model's reply, stored and forwarded as-is.
	Raw          string
	Parsed       *Parsed
	Model        string
	InputTokens  int64
	OutputTokens int64
	// Cost is computed deterministically in Go (not by the LLM) so
	// the dollar figure is always accurate. The LLM gets the same
	// numbers in the prompt and writes the commentary around them.
	Cost CostEstimate
}

Result is what Generate returns to the handler.

func Generate

func Generate(ctx context.Context, a *ai.Analyzer, plan *rivian.TripPlan, tc Context) (Result, error)

Generate calls the AI provider with a compact trip-plan summary and returns structured advice. The context's deadline should be generous (30s+) — sit in the AI-bound route group, not the timed one.

Jump to

Keyboard shortcuts

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