Skip to Content
AI

Fake

A deterministic provider for tests: no network, no spend.

Usage

import { createExtractor, fakeProvider } from "@dapplelight/signet-ai"
import { invoiceSchema } from "./schemas"

const ai = createExtractor({
  providers: [fakeProvider({ invoiceNumber: "INV-1042", total: 8000 })],
})

const { value } = await ai.extract({ schema: invoiceSchema, input: "any", instructions: "Read it." })

API

fakeProvider(responses, options)

ArgumentTypeDefault
responsesvalue, array, or (input) => valuerequiredAn array is returned in order, repeating the last
options.namestring"fake"
options.modelstring"fake-1"
options.usage{ inputTokens, outputTokens }noneReported usage
options.failTimesnumber0Fail this many calls first
options.errorunknowna 503 errorWhat to throw when failing

It is priced at $0, so it passes the ledger's pricing check.

Examples

Test failover

import { createExtractor } from "@dapplelight/signet-ai/extract"
import { fakeProvider } from "@dapplelight/signet-ai/fake"
import { invoiceSchema as schema } from "./schemas"

const ai = createExtractor({
  providers: [
    fakeProvider(null, { name: "primary", failTimes: 99, error: new Error("bad key") }),
    fakeProvider({ total: 120 }, { name: "backup" }),
  ],
})
const { meta } = await ai.extract({ schema, input: "x", instructions: "y" })
// meta.provider === "backup"