Joel Stevick

Appendix B · section 27 of 32

ask/live.ts

From Failing Closed.

import Anthropic from "@anthropic-ai/sdk";
import { askerFor } from "./answer.js";
import { LAWS } from "./corpus.js";
import type { Pipeline } from "./pipeline.js";
import { haikuRephraseFor, sideJobClient } from "./rephrase.js";
import { haikuRerankFor } from "./rerank.js";
import { ROWS } from "./schedule.js";
import { buildIndex, nearLawsFor, workersAiEmbedder } from "./vectors.js";

// The deployed pipeline, built from whatever the environment holds. Every
// stage that needs a credential the environment lacks is left out, and the
// pipeline answers as it did before that stage existed.
export async function livePipeline(): Promise<Pipeline> {
  const embed = workersAiEmbedder();
  const side = sideJobClient();
  return {
    ask: askerFor(new Anthropic()),
    laws: LAWS,
    ...(embed === undefined ? {} : { near: nearLawsFor(await buildIndex(LAWS, embed), embed) }),
    rephrase: haikuRephraseFor(side),
    rerank: haikuRerankFor(side),
    penalties: ROWS,
  };
}