Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

updateProdEnv.ts 975 B

You have to be logged in to leave a comment. Sign In
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
  1. import fs from "fs";
  2. const HF_TOKEN = process.env.HF_TOKEN;
  3. const SECRET_CONFIG = fs.existsSync(".env.SECRET_CONFIG")
  4. ? fs.readFileSync(".env.SECRET_CONFIG", "utf8")
  5. : process.env.SECRET_CONFIG;
  6. if (!SECRET_CONFIG) {
  7. throw new Error(
  8. "SECRET_CONFIG is not defined. Please provide it either in a file or as an environment variable."
  9. );
  10. }
  11. // Read the content of the file .env.template
  12. const PUBLIC_CONFIG = fs.readFileSync(".env.template", "utf8");
  13. // Prepend the content of the env variable SECRET_CONFIG
  14. const full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;
  15. // Make an HTTP POST request to add the space secre
  16. fetch(`https://huggingface.co/api/spaces/huggingchat/chat-ui/secrets`, {
  17. method: "POST",
  18. body: JSON.stringify({
  19. key: "DOTENV_LOCAL",
  20. value: full_config,
  21. description: `Env variable for HuggingChat. Last updated ${new Date().toISOString()}`,
  22. }),
  23. headers: {
  24. Authorization: `Bearer ${HF_TOKEN}`,
  25. "Content-Type": "application/json",
  26. },
  27. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...