Pārlūkot izejas kodu

Add Traditional Chinese prompts converted from Simplified Chinese version

Peter Dave Hello 1 gadu atpakaļ
vecāks
revīzija
238d3122c4
3 mainītis faili ar 32 papildinājumiem un 7 dzēšanām
  1. 3 2
      app/store/prompt.ts
  2. 3 0
      public/prompts.json
  3. 26 5
      scripts/fetch-prompts.mjs

+ 3 - 2
app/store/prompt.ts

@@ -154,7 +154,7 @@ export const usePromptStore = createPersistStore(
       fetch(PROMPT_URL)
         .then((res) => res.json())
         .then((res) => {
-          let fetchPrompts = [res.en, res.cn];
+          let fetchPrompts = [res.en, res.tw, res.cn];
           if (getLang() === "cn") {
             fetchPrompts = fetchPrompts.reverse();
           }
@@ -175,7 +175,8 @@ export const usePromptStore = createPersistStore(
           const allPromptsForSearch = builtinPrompts
             .reduce((pre, cur) => pre.concat(cur), [])
             .filter((v) => !!v.title && !!v.content);
-          SearchService.count.builtin = res.en.length + res.cn.length;
+          SearchService.count.builtin =
+            res.en.length + res.cn.length + res.tw.length;
           SearchService.init(allPromptsForSearch, userPrompts);
         });
     },

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 3 - 0
public/prompts.json


+ 26 - 5
scripts/fetch-prompts.mjs

@@ -6,11 +6,13 @@ const MIRRORF_FILE_URL = "http://raw.fgit.ml/";
 
 const RAW_CN_URL = "PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json";
 const CN_URL = MIRRORF_FILE_URL + RAW_CN_URL;
+const RAW_TW_URL = "PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh-TW.json";
+const TW_URL = MIRRORF_FILE_URL + RAW_TW_URL;
 const RAW_EN_URL = "f/awesome-chatgpt-prompts/main/prompts.csv";
 const EN_URL = MIRRORF_FILE_URL + RAW_EN_URL;
 const FILE = "./public/prompts.json";
 
-const ignoreWords = ["涩涩", "魅魔"];
+const ignoreWords = ["涩涩", "魅魔", "澀澀"];
 
 const timeoutPromise = (timeout) => {
   return new Promise((resolve, reject) => {
@@ -39,6 +41,25 @@ async function fetchCN() {
   }
 }
 
+async function fetchTW() {
+  console.log("[Fetch] fetching tw prompts...");
+  try {
+    const response = await Promise.race([fetch(TW_URL), timeoutPromise(5000)]);
+    const raw = await response.json();
+    return raw
+      .map((v) => [v.act, v.prompt])
+      .filter(
+        (v) =>
+          v[0] &&
+          v[1] &&
+          ignoreWords.every((w) => !v[0].includes(w) && !v[1].includes(w)),
+      );
+  } catch (error) {
+    console.error("[Fetch] failed to fetch tw prompts", error);
+    return [];
+  }
+}
+
 async function fetchEN() {
   console.log("[Fetch] fetching en prompts...");
   try {
@@ -61,13 +82,13 @@ async function fetchEN() {
 }
 
 async function main() {
-  Promise.all([fetchCN(), fetchEN()])
-    .then(([cn, en]) => {
-      fs.writeFile(FILE, JSON.stringify({ cn, en }));
+  Promise.all([fetchCN(), fetchTW(), fetchEN()])
+    .then(([cn, tw, en]) => {
+      fs.writeFile(FILE, JSON.stringify({ cn, tw, en }));
     })
     .catch((e) => {
       console.error("[Fetch] failed to fetch prompts");
-      fs.writeFile(FILE, JSON.stringify({ cn: [], en: [] }));
+      fs.writeFile(FILE, JSON.stringify({ cn: [], tw: [], en: [] }));
     })
     .finally(() => {
       console.log("[Fetch] saved to " + FILE);

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels