-
Notifications
You must be signed in to change notification settings - Fork 59k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Traditional Chinese prompts converted from Simplified Chinese version #5046
Conversation
@PeterDaveHello is attempting to deploy a commit to the NextChat Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes add support for fetching and handling Taiwanese (TW) language prompts in addition to the existing English (EN) and Chinese (CN) prompts. This involves updating the array handling fetch prompts and the built-in prompt count in the Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant App as Application
participant Store as Prompt Store
participant API as API Service
User->>App: Access prompts
App->>Store: fetchPrompts()
Store->>API: Fetch EN, CN, TW prompts
API-->>Store: Return prompts in EN, CN, TW
Store-->>App: Store prompts and update count
App-->>User: Display prompts
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- app/store/prompt.ts (2 hunks)
- public/prompts.json (1 hunks)
- scripts/fetch-prompts.mjs (3 hunks)
Files not summarized due to errors (1)
- public/prompts.json: Error: Message exceeds token limit
Additional comments not posted (4)
scripts/fetch-prompts.mjs (1)
9-10
: Constants for Traditional Chinese prompts URL are correctly defined.The constants
RAW_TW_URL
andTW_URL
are defined correctly to construct the URL for fetching Traditional Chinese prompts. This aligns with the existing pattern for other languages.app/store/prompt.ts (2)
157-157
: UpdatedfetchPrompts
to include Traditional Chinese prompts.The update to
fetchPrompts
to includeres.tw
is correctly implemented and follows the existing pattern for handling multiple languages. This change ensures that Traditional Chinese prompts are correctly fetched and processed.
178-179
: Updated prompt count to include Traditional Chinese prompts.The calculation of
SearchService.count.builtin
now includes the count of Traditional Chinese prompts. This is a necessary update to accurately reflect the total number of built-in prompts across all supported languages.public/prompts.json (1)
488-981
: JSON Structure and Translation ValidationThe addition of Traditional Chinese prompts under the "tw" key has been implemented correctly. The JSON syntax is valid, and the structure matches the existing format used for other languages.
Ensure the accuracy and appropriateness of the translations for the intended audience.
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: [] })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handling of multiple language prompts in main
function.
The main
function now handles fetching prompts for CN, TW, and EN concurrently using Promise.all
. This is efficient and maintains consistency across different language fetches. The error handling in the catch block could be enhanced by logging the specific error.
- console.error("[Fetch] failed to fetch prompts");
+ console.error("[Fetch] failed to fetch prompts due to", e.message);
Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
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: [] })); | |
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 due to", e.message); | |
fs.writeFile(FILE, JSON.stringify({ cn: [], tw: [], en: [] })); |
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 []; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review of fetchTW
function.
The fetchTW
function is implemented consistently with the existing fetchCN
and fetchEN
functions. It uses a timeout promise to handle potential delays and fetches the data using the constructed URL. The function also filters the results based on ignoreWords
, which is a good practice for content filtering. However, the error handling could be improved by providing more specific error messages or handling different types of exceptions separately.
- console.error("[Fetch] failed to fetch tw prompts", error);
+ console.error("[Fetch] failed to fetch tw prompts due to", error.message);
Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
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 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 due to", error.message); | |
return []; | |
} |
Your build has completed! |
π» εζ΄η±»ε | Change Type
π εζ΄θ―΄ζ | Description of Change
Add Traditional Chinese prompts converted from the Simplified Chinese version.
π θ‘₯ε δΏ‘ζ― | Additional Information
Reference:
https://github.com/PlexPt/awesome-chatgpt-prompts-zh/blob/main/prompts-zh-TW.json
Summary by CodeRabbit
New Features
Enhancements