aiengine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package aiengine implements engine.AIPredictionEngine on top of langchaingo's provider-agnostic llms.Model. It lives outside internal/engine on purpose: the engine core stays stdlib-first (project CLAUDE.md hard rule 6), so the langchaingo dependency is confined to this peripheral package and wired in at the CLI composition layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromEnv

func FromEnv(getenv func(string) string) (engine.AIPredictionEngine, error)

FromEnv builds an Engine from environment configuration, or returns a nil engine (untyped) when no AI is configured — leaving AI commands to fail closed with ErrCloudAPIKeyNotAvailable, the same as product runtime FlowBaton without a provider.

Config is read through getenv (injected for tests):

  • FLOWBATON_AI_PROVIDER: "openai" (default) or "anthropic"
  • the provider's own key var: OPENAI_API_KEY / ANTHROPIC_API_KEY
  • FLOWBATON_AI_MODEL: optional model override
  • FLOWBATON_AI_BASE_URL: optional endpoint override, for an OpenAI/Anthropic-compatible host that is not the vendor's own

"Configured" means the selected provider's key var is non-blank. With no key, the return is (nil, nil): unconfigured is not an error, it is fail-closed.

Types

type Config

type Config struct {
	Provider Provider
	APIKey   string
	Model    string
	// BaseURL points the provider at an endpoint other than the vendor's own.
	// Blank keeps the vendor default. This is what makes an OpenAI- or
	// Anthropic-COMPATIBLE endpoint reachable — a self-hosted gateway, a proxy,
	// or another vendor speaking the same protocol, such as MiniMax at
	// https://api.minimax.io/anthropic. The protocol is the same; only the host
	// differs, so nothing else here has to know.
	//
	// Written either way round: with or without the trailing version segment.
	// See normalizeBaseURL for why both have to work.
	BaseURL string
}

Config selects and authenticates a provider. APIKey is optional: when blank, the provider library reads its own standard env var (OPENAI_API_KEY / ANTHROPIC_API_KEY). Model is optional and falls back to a vision-capable default for the chosen provider.

type Engine

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

Engine is a screenshot-driven AIPredictionEngine backed by one llms.Model. The model is injectable so tests drive the prompt/parse logic with a fake and no network. A per-call model name override is optional; blank uses whatever model the provider was constructed with.

func New

func New(cfg Config) (*Engine, error)

New builds an Engine for cfg. It fails loudly on an unknown provider or a provider the library refuses to construct (e.g. no API key anywhere) — a misconfiguration should surface, not silently fall back to fail-closed.

func NewFromModel

func NewFromModel(model llms.Model, modelName string) *Engine

NewFromModel wraps an already-constructed langchaingo model. modelName is an optional per-call override (e.g. "gpt-4o"); pass "" to use the model's own default. Used directly by tests; production goes through New/FromEnv.

func (*Engine) ExtractText

func (e *Engine) ExtractText(ctx context.Context, screenshotPNG []byte, query string) (engine.AIResult, error)

ExtractText pulls the text answering query out of the screenshot.

func (*Engine) FindDefects

func (e *Engine) FindDefects(ctx context.Context, screenshotPNG []byte) (engine.AIResult, error)

FindDefects lists user-visible defects on the screenshot. Pass is true when none are found, matching assertNoDefectsWithAI's "no defects" success.

func (*Engine) PerformAssertion

func (e *Engine) PerformAssertion(ctx context.Context, screenshotPNG []byte, assertion string) (engine.AIResult, error)

PerformAssertion asks whether assertion holds for the screenshot.

type Provider

type Provider string

Provider names the LLM backend an Engine talks to.

const (
	ProviderOpenAI    Provider = "openai"
	ProviderAnthropic Provider = "anthropic"
)

Jump to

Keyboard shortcuts

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