INNER CODE UNIT · TypeScript

byName

harvard-edge/cs249r_book · interviews/staffml/worker/src/index.ts:250

  const byName = new Map(ADAPTERS.map((a) => [a.name, a]));
  const ordered: Adapter[] = [];
  for (const name of priority) {
    const a = byName.get(name);
    if (a && isAvailable(a, env)) ordered.push(a);
  }
  // Always append cf-workers-ai as the floor if not already in the list
  const floor = byName.get("cf-workers-ai");
  if (floor && !ordered.includes(floor) && isAvailable(floor, env)) {
    ordered.push(floor);
  }
  return ordered;
}

function getModel(adapter: Adapter, env: Env): string {
  if (adapter.modelEnv) {
    const override = env[adapter.modelEnv];
    if (typeof override === "string" && override) return override;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…