Skip to content
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

Merged
merged 1 commit into from
Jul 19, 2024

Conversation

PeterDaveHello
Copy link
Contributor

@PeterDaveHello PeterDaveHello commented Jul 17, 2024

πŸ’» ε˜ζ›΄η±»εž‹ | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

πŸ”€ ε˜ζ›΄θ―΄ζ˜Ž | 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

    • Added support for fetching and displaying prompts in traditional Chinese (TW).
  • Enhancements

    • The count of built-in prompts now includes traditional Chinese (TW) variants.

Copy link

vercel bot commented Jul 17, 2024

@PeterDaveHello is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jul 17, 2024

Walkthrough

The 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 prompt.ts file. The fetch-prompts.mjs script is also updated to fetch, process, and filter TW prompts from a new URL.

Changes

Files Change Summary
app/store/prompt.ts Updated prompt handling to include Taiwanese (TW) prompts in the fetch array and built-in prompt count.
scripts/fetch-prompts.mjs Added functionality to fetch and filter TW prompts, including a new URL and processing logic.

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
Loading

Poem

In a digital sea where languages blend,
A new prompt in TW, our latest trend.
From scripts that fetch with careful care,
To counts that tally, nothing left spare.
πŸ‡βœ¨ Hopping forward, our app does mend! 🌟


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between f8a2a28 and 238d312.

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 and TW_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: Updated fetchPrompts to include Traditional Chinese prompts.

The update to fetchPrompts to include res.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 Validation

The 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.

Comment on lines +85 to +91
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: [] }));
Copy link

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.

Suggested change
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: [] }));

Comment on lines +44 to +60
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 [];
}
Copy link

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.

Suggested change
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 [];
}

Copy link
Contributor

Your build has completed!

Preview deployment

@Dogtiti Dogtiti merged commit a280e25 into ChatGPTNextWeb:main Jul 19, 2024
1 of 2 checks passed
@PeterDaveHello PeterDaveHello deleted the Add-zh-tw-prompts branch July 19, 2024 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants