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, so the langchaingo dependency is confined to this peripheral package and wired in at the CLI composition layer.
Index ¶
- Constants
- func ChatModelsFromEnv(getenv func(string) string) (explore.ModelSet, error)
- func FromEnv(getenv func(string) string) (engine.AIPredictionEngine, error)
- type ChatClient
- type Config
- type Engine
- func (e *Engine) ExtractText(ctx context.Context, screenshotPNG []byte, query string) (engine.AIResult, error)
- func (e *Engine) FindDefects(ctx context.Context, screenshotPNG []byte) (engine.AIResult, error)
- func (e *Engine) PerformAssertion(ctx context.Context, screenshotPNG []byte, assertion string) (engine.AIResult, error)
- type Provider
Constants ¶
const ( DefaultProviderTimeout = 60 * time.Second MaxProviderTimeout = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func ChatModelsFromEnv ¶
ChatModelsFromEnv builds the explore model tiers from the same environment surface as FromEnv: FLOWBATON_AI_PROVIDER selects the backend, the provider's own key variable authenticates it, and FLOWBATON_AI_MODEL, FLOWBATON_AI_BASE_URL and FLOWBATON_AI_TIMEOUT shape the shared client.
The manager tier runs on FLOWBATON_AI_MODEL (or the provider default). FLOWBATON_AI_WORKER_MODEL and FLOWBATON_AI_VISION_MODEL optionally point their tiers at other models on the same provider; blank falls back to the manager client itself.
With no key configured the return is a zero ModelSet and nil error — the caller fails closed, matching FromEnv.
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
- FLOWBATON_AI_TIMEOUT: optional Go duration, default 60s, maximum 5m
"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 ChatClient ¶
type ChatClient struct {
// contains filtered or unexported fields
}
ChatClient implements explore.LLM on one llms.Model, keeping langchaingo quarantined in this package. A blank modelName uses the model the provider client was constructed with; a non-blank one overrides it per call, which is how the explore tiers share one provider client.
func NewChatClient ¶
func NewChatClient(model llms.Model, provider Provider, modelName string, timeout time.Duration) *ChatClient
NewChatClient wraps an already-constructed langchaingo model. The provider names the API dialect the model speaks, which decides how an image turn is encoded (see imagePart); blank keeps the Anthropic-shaped BinaryContent. Pass "" as modelName to use the client's own model; timeout zero (or out of range) falls back to DefaultProviderTimeout at call time.
func (*ChatClient) Chat ¶
func (c *ChatClient) Chat(ctx context.Context, request explore.ChatRequest) (explore.ChatResponse, error)
Chat runs one model invocation. Temperature is pinned to 0 and each call is bounded by the configured timeout.
type Config ¶
type Config struct {
Provider Provider
APIKey string
Model string
// Timeout bounds each provider call. Zero uses DefaultProviderTimeout.
// Values above MaxProviderTimeout are rejected.
Timeout time.Duration
// 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 ¶
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 ¶
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 ¶
FindDefects lists user-visible defects on the screenshot. Pass is true when none are found, matching assertNoDefectsWithAI's "no defects" success.