Skip to content

AI engine settings

Which engine does each AI job, a person's subscription or the API.

<div data-mount="settings"></div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/ai-engine-settings.css";
import { dollars, engineWord, settingsFromForm } from "capsomer/behavior/ai-engine-settings";

Usage

import { AiEngineSettings } from "capsomer/react/ai-engine-settings";
import { settingsFromForm } from "capsomer/behavior/ai-engine-settings";

<AiEngineSettings
  settings={settings}
  models={models}
  jobs={FEATURES}
  modelOptions={MODELS}
  efforts={efforts}
  effortOptions={EFFORTS}
  ready={{ subscription: !routineMissing, api: !apiKeyMissing }}
  readyNote="Both are secrets, set where the app is deployed."
  spentMicros={spent}
  usage={usage.map((u) => ({ job: u.feature, effort: u.effort, calls: u.calls, micros: u.micros }))}
  Form={Form}
  pending={busy}
/>

// A site whose API runs take no effort leaves out efforts and effortOptions: no Effort column.

// In the action:
const saved = settingsFromForm((name) => form.get(name), FEATURES);

Examples

The API for a few days, the subscription not connected, nothing spent

<div data-mount="override"></div>

API reference

AiEngineSettings

PropTypeRequiredDoes
settingsEngineSettingsLikeYes
modelsReadonly<Partial<Record<string, string>>>YesThe model each job's API run uses: "fast", "standard", "deep", or none (left out) for the job's default. A partial map, as site-runtime's settings reader returns it.
jobsreadonly EngineJob[]Yes
modelOptionsreadonly SelectOption[]YesThe model choices, with their prices (from site-runtime's MODEL_IDS and PRICES). The first is "The job's own default", value "".
effortsReadonly<Partial<Record<string, string>>>The effort each job's API run uses ("low" to "max"), a partial map like models, and its choices, the first "The job's own default", value "". A site whose API runs take no effort leaves both out, and the table has no Effort column.
effortOptionsreadonly SelectOption[]
ready{ subscription: boolean; api: boolean }YesWhether each engine can work now: the routine connected, an API key set.
readyNoteReactNodeWhat to do when one cannot, in a sentence.
spentMicrosnumberYesThis month's API spend, and by job (and by effort, where a run had one).
usageReadonlyArray<{ job: string; effort?: string | null; calls: number; micros: number }>Yes
capHelpReactNodeThe cap field's help, and the note under the spend, where the site has more to say.
costNoteReactNode
actionstring
FormFormComponent
pendingboolean

Functions

FunctionSignatureDoes
dollars(micros: number): string"$0.0042" under a cent, "$12.40" above.
engineWord(value: string): stringThe short name of an engine setting, for "Follow everything (Automatic)".
settingsFromForm(get: (name: string) => unknown, jobs: readonly Pick<EngineJob, "key">[]): { master: string; features: Record<string, string>; models: Record<string, string>; efforts: Record<...>; apiCapMicros: number; }The settings a saved form holds: master, feature-<key>, model-<key> and effort-<key> for each job (empty is "follow everything" and "the job's own default"), and cap in dollars. The override is not in the form; the app keeps the one it has.

Parts and data attributes

ClassIs
.cap-ai-enginethe root
.cap-ai-engine-job-notea part
.cap-ai-engine-notea part
.cap-ai-engine-spenda part
.cap-ai-engine-statusa part
.cap-ai-engine-tablea part

Accessibility

KeyDoes
TabThe table's region, then each row's engine and model, then Save, then the cap
The select's keysChoose an engine or a model
Enter on SaveSaves the table and the cap
  • The table has a caption (hidden) and row headers; each select is named by its job ("Social post drafts: engine").
  • The table scrolls in a labeled, focusable region on a narrow screen.
  • Each engine's state is a status with its shape and word.