Spaces:
Running
Running
File size: 1,308 Bytes
fac3250 3cbea34 fac3250 1ae93cf 3cbea34 e9f817c fac3250 1ae93cf 3cbea34 e9f817c 1ae93cf fac3250 39fde06 fac3250 3cbea34 fac3250 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import fs from "fs";
const HF_DEPLOYMENT_TOKEN = process.env.HF_DEPLOYMENT_TOKEN; // token used for pushing to hub
const SERPER_API_KEY = process.env.SERPER_API_KEY;
const OPENID_CONFIG = process.env.OPENID_CONFIG;
const MONGODB_URL = process.env.MONGODB_URL;
const HF_TOKEN = process.env.HF_TOKEN ?? process.env.HF_ACCESS_TOKEN; // token used for API requests in prod
const WEBHOOK_URL_REPORT_ASSISTANT = process.env.WEBHOOK_URL_REPORT_ASSISTANT; // slack webhook url used to get "report assistant" events
// Read the content of the file .env.template
const PUBLIC_CONFIG = fs.readFileSync(".env.template", "utf8");
// Prepend the content of the env variable SECRET_CONFIG
const full_config = `${PUBLIC_CONFIG}
MONGODB_URL=${MONGODB_URL}
OPENID_CONFIG=${OPENID_CONFIG}
SERPER_API_KEY=${SERPER_API_KEY}
HF_TOKEN=${HF_TOKEN}
WEBHOOK_URL_REPORT_ASSISTANT=${WEBHOOK_URL_REPORT_ASSISTANT}
`;
// Make an HTTP POST request to add the space secrets
fetch(`https://huggingface.co/api/spaces/huggingchat/chat-ui/secrets`, {
method: "POST",
body: JSON.stringify({
key: "DOTENV_LOCAL",
value: full_config,
description: `Env variable for HuggingChat. Last updated ${new Date().toISOString()}`,
}),
headers: {
Authorization: `Bearer ${HF_DEPLOYMENT_TOKEN}`,
"Content-Type": "application/json",
},
});
|