nikiagi's picture
Upload folder using huggingface_hub
105e2f1 verified
Raw History Blame Contribute Delete
712 Bytes
import { readFileSync } from "node:fs";
let cached;
export function policyProfile() {
if (cached) return cached;
const name = process.env.FAILPROOF_PROFILE;
const path = process.env.FAILPROOF_PROFILE_CONFIG;
if (!name || !path) {
throw new Error("policy profile environment is missing");
}
const doc = JSON.parse(readFileSync(path, "utf8"));
const values = doc?.profiles?.[name];
if (!values) throw new Error(`unknown policy profile: ${name}`);
cached = Object.freeze({ name, ...values });
return cached;
}
export function profileNudgeLimit(key, fallback = 1) {
const value = policyProfile()?.nudge_limits?.[key];
return Number.isInteger(value) && value >= 0 ? value : fallback;
}