From a043f039f036e0ff7a73f55d29ff3af9a07deb5a Mon Sep 17 00:00:00 2001 From: quangdn-ght Date: Thu, 26 Jun 2025 11:54:08 +0700 Subject: [PATCH] xu ly built mask tieng viet va update role assistant --- Chebichat.md | 1 + app/SyncOnFirstLoad.tsx | 8 +-- app/chebichatConstant.ts | 4 ++ app/components/chat-list.tsx | 2 + app/components/chat.tsx | 20 ++++--- app/locales/vi.ts | 2 +- app/masks/build.ts | 12 ++-- app/masks/cn.ts | 8 +-- app/masks/index.ts | 7 ++- app/masks/vi.ts | 110 +++++++++++++++++++++++++++++++++++ app/store/chat.ts | 32 +++++++--- app/store/config.ts | 10 ++-- app/store/mask.ts | 6 ++ git.sh | 2 +- 14 files changed, 184 insertions(+), 40 deletions(-) create mode 100644 app/masks/vi.ts diff --git a/Chebichat.md b/Chebichat.md index f19ef98cc..7148a47cc 100644 --- a/Chebichat.md +++ b/Chebichat.md @@ -1 +1,2 @@ + app/store/config.ts \ No newline at end of file diff --git a/app/SyncOnFirstLoad.tsx b/app/SyncOnFirstLoad.tsx index f3ff0f9a9..43823f648 100644 --- a/app/SyncOnFirstLoad.tsx +++ b/app/SyncOnFirstLoad.tsx @@ -2,7 +2,6 @@ import { useEffect } from "react"; import { useSyncStore } from "./store/sync"; import { showToast } from "./components/ui-lib"; -import { AUTHEN_PAGE } from "./constant"; export default function SyncOnFirstLoad() { const syncStore = useSyncStore(); @@ -21,9 +20,10 @@ export default function SyncOnFirstLoad() { showToast("Please login first"); - setTimeout(() => { - window.location.href = AUTHEN_PAGE; - }, 500); + // setTimeout(() => { + // window.location.href = AUTHEN_PAGE; + // }, 500); + return; } diff --git a/app/chebichatConstant.ts b/app/chebichatConstant.ts index b4e1513c8..e62a538e7 100644 --- a/app/chebichatConstant.ts +++ b/app/chebichatConstant.ts @@ -6,3 +6,7 @@ export const UPSTASH_APIKEY = "Ac1kAAIjcDE2YjM4YmY3OGI4YzA0MTU2YjZhNmQyNzc5Yzc3NzEwYnAxMA"; export const STORAGE_KEY = "chebichat-backup"; export const AUTHEN_PAGE = "https://chinese.giahungtech.com.vn"; + +export const CHEBI_MESSAGE = `# Vai trò: Bạn là một **bậc thầy uyên bác và kiên nhẫn về văn học cổ điển Trung Quốc**, chuyên hỗ trợ người học tiếng Trung (đặc biệt là người Việt) trong quá trình ôn luyện kỳ thi **HSK (Hànyǔ Shuǐpíng Kǎoshì)**. Phương pháp giảng dạy của bạn kết hợp giữa kiến thức sâu rộng về **Hán văn cổ** và các kỹ thuật hiện đại, giúp học viên vừa nắm vững ngôn ngữ vừa hiểu sâu sắc văn hóa Trung Hoa. Bạn luôn sử dụng **tiếng Việt** để giảng dạy và giao tiếp nhằm đảm bảo hiệu quả và dễ tiếp cận.---## 🎯 Kỹ năng chính### 1. Dịch thuật sang văn cổ Trung Quốc- Dịch các chủ đề hiện đại sang Hán văn cổ, giữ nguyên nội dung và tinh thần gốc.- Tuân thủ cú pháp, phong cách và ngữ pháp cổ điển.- Khéo léo chuyển hóa thuật ngữ hiện đại theo lối cổ mà vẫn rõ ràng và chính xác.### 2. Giảng dạy và đơn giản hóa văn bản phức tạp- Giải thích rõ ràng các văn bản cổ điển khó hiểu cho người học Việt Nam.- Cung cấp: - Hướng dẫn phát âm (Pinyin), - Cách đọc Hán-Việt, - Phân tích từ vựng và ngữ cảnh.- Dùng ví dụ văn hóa gần gũi để tạo liên kết giữa Hán văn và đời sống người học.### 3. Luyện thi HSK hiệu quả- Soạn tài liệu và bài tập phù hợp với từng cấp độ HSK.- Hướng dẫn chiến thuật làm bài: phân bổ thời gian, mẹo làm nhanh.- Phân tích bài thi thử, nhận xét điểm mạnh và điểm cần cải thiện.---## ⚠️ Giới hạn- **Chỉ tập trung** vào văn học cổ Trung Quốc và luyện thi HSK.- Đảm bảo mọi bản dịch, giải thích đều **chính xác và phù hợp văn hóa**.- Khi có đề cập đến tiếng Trung hiện đại, phải **phân biệt rõ với Hán văn cổ**.- **Luôn sử dụng tiếng Việt** trong toàn bộ quá trình giảng dạy và phản hồi.`; + +export const CHEBI_VISION = `# 🧠 Vai trò: Bạn là một **chuyên gia uyên bác và kiên nhẫn về văn học cổ điển Trung Quốc (文言文)**, chuyên hướng dẫn học viên Việt Nam học tiếng Trung cổ và hiện đại. Bạn kết hợp kiến thức sâu rộng về Hán văn cổ với phương pháp sư phạm thực tiễn, giúp học viên xây dựng nền tảng vững chắc và tự tin chinh phục kỳ thi **HSK (Hànyǔ Shuǐpíng Kǎoshì)**. Bạn có khả năng **phân tích nội dung hình ảnh**, bao gồm thư pháp, chữ viết tay, từ điển Hán ngữ hoặc ảnh chụp bài thi HSK, và **giải thích rõ ràng bằng tiếng Việt**.---## 🎯 Kỹ năng chính### 1. Dịch và giải nghĩa văn bản - Dịch Hán văn cổ sang tiếng Việt một cách rõ ràng và chính xác. - Phân tích cấu trúc câu, nghĩa từ, thứ tự nét, bộ thủ và cách dùng chữ Hán. - Giải thích ngữ cảnh văn hóa để kết nối giữa văn học Trung Hoa và người học Việt Nam.### 2. Phân tích nội dung hình ảnh - Đọc hiểu thư pháp, ghi chú viết tay, ảnh chụp đề thi HSK hoặc tài liệu học tiếng Trung. - Tách chữ phức tạp thành thành phần đơn giản để dễ hiểu. - Làm nổi bật đặc điểm quan trọng của hệ thống chữ Hán: bộ thủ, âm tiết và ngữ nghĩa.### 3. Hỗ trợ luyện thi HSK - Dạy từ vựng, ngữ pháp và kỹ năng đọc hiểu theo từng cấp độ HSK. - Hướng dẫn chiến thuật làm bài ở các phần nghe, đọc, viết. - Cung cấp bài luyện tập và phản hồi chi tiết để cải thiện kết quả thi.### 4. Giải thích văn hóa và văn học - Giới thiệu bối cảnh lịch sử và giá trị văn hóa của văn học cổ Trung Hoa. - So sánh các yếu tố tương đồng giữa văn học Việt - Trung để tăng sự hứng thú học tập. - Sử dụng kể chuyện, giai thoại giúp nội dung cổ điển trở nên sống động và dễ ghi nhớ.---## ⚠️ Giới hạn- **Chỉ tập trung** vào văn học cổ Trung Quốc, tiếng Trung hiện đại và luyện thi HSK. - **Tránh dùng thuật ngữ quá kỹ thuật** nhằm đảm bảo mọi đối tượng đều dễ hiểu. - **Dịch và giảng giải phải chính xác**, phù hợp văn hóa và trình độ người học. - Luôn duy trì **giọng điệu tích cực, hỗ trợ và khuyến khích** trong quá trình giảng dạy.`; diff --git a/app/components/chat-list.tsx b/app/components/chat-list.tsx index 63dc4d5ff..0edcdfa14 100644 --- a/app/components/chat-list.tsx +++ b/app/components/chat-list.tsx @@ -150,6 +150,8 @@ export function ChatList(props: { narrow?: boolean }) { index={i} selected={i === selectedIndex} onClick={() => { + console.log(item.topic); + navigate(Path.Chat); selectSession(i); }} diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 77dbcb00e..3c65f1f08 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -36,7 +36,6 @@ import CancelIcon from "../icons/cancel.svg"; import ImageIcon from "../icons/image.svg"; import LightIcon from "../icons/light.svg"; -import DarkIcon from "../icons/dark.svg"; import AutoIcon from "../icons/auto.svg"; import BottomIcon from "../icons/bottom.svg"; import StopIcon from "../icons/pause.svg"; @@ -75,6 +74,7 @@ import { useMobileScreen, selectOrCopy, showPlugins, + isIOS, } from "../utils"; import { uploadImage as uploadImageRemote } from "@/app/utils/chat"; @@ -514,7 +514,8 @@ export function ChatActions(props: { const theme = config.theme; function nextTheme() { - const themes = [Theme.Auto, Theme.Light, Theme.Dark]; + //, Theme.Dark + const themes = [Theme.Auto, Theme.Light]; const themeIndex = themes.indexOf(theme); const nextIndex = (themeIndex + 1) % themes.length; const nextTheme = themes[nextIndex]; @@ -637,9 +638,10 @@ export function ChatActions(props: { ) : theme === Theme.Light ? ( - ) : theme === Theme.Dark ? ( - - ) : null} + ) : // theme === Theme.Dark ? ( + // + // ) + null} } /> @@ -1167,7 +1169,8 @@ function _Chat() { // auto sync mask config from global config if (session.mask.syncGlobalConfig) { - console.log("[Mask] syncing from global, name = ", session.mask.name); + // console.log("[Mask] syncing from global, name = ", session.mask.name); + session.mask.modelConfig = { ...config.modelConfig }; } }); @@ -1452,7 +1455,10 @@ function _Chat() { const clientConfig = useMemo(() => getClientConfig(), []); - const autoFocus = !isMobileScreen; // wont auto focus on mobile screen + const autoFocus = isIOS() ? false : !isMobileScreen; // wont auto focus on mobile screen + + console.log("tu dong focus:", autoFocus); + const showMaxIcon = !isMobileScreen && !clientConfig?.isApp; useCommand({ diff --git a/app/locales/vi.ts b/app/locales/vi.ts index 4369c83da..6c4d1a292 100644 --- a/app/locales/vi.ts +++ b/app/locales/vi.ts @@ -472,7 +472,7 @@ const vi: PartialLocaleType = { }, }, Discovery: { - Name: "Tìm kiêm", + Name: "Mở rộng", }, Copy: { Success: "Đã sao chép vào clipboard", diff --git a/app/masks/build.ts b/app/masks/build.ts index 10c09ad75..ee639f8b0 100644 --- a/app/masks/build.ts +++ b/app/masks/build.ts @@ -1,15 +1,15 @@ import fs from "fs"; import path from "path"; -import { CN_MASKS } from "./cn"; -import { TW_MASKS } from "./tw"; -import { EN_MASKS } from "./en"; +import { VI_MASKS } from "./vi"; +// import { TW_MASKS } from "./tw"; +// import { EN_MASKS } from "./en"; import { type BuiltinMask } from "./typing"; const BUILTIN_MASKS: Record = { - cn: CN_MASKS, - tw: TW_MASKS, - en: EN_MASKS, + vi: VI_MASKS, + // tw: TW_MASKS, + // en: EN_MASKS, }; const dirname = path.dirname(__filename); diff --git a/app/masks/cn.ts b/app/masks/cn.ts index 227477fce..3e1eb7513 100644 --- a/app/masks/cn.ts +++ b/app/masks/cn.ts @@ -1,5 +1,7 @@ import { BuiltinMask } from "./typing"; import { IMAGES } from "./base64Images"; +import { CHEBI_MESSAGE, CHEBI_VISION } from "../chebichatConstant"; +// import {} export const CN_MASKS: BuiltinMask[] = [ { avatar: "1f5bc-fe0f", @@ -8,8 +10,7 @@ export const CN_MASKS: BuiltinMask[] = [ { id: "text-to-pic-0", role: "system", - content: - "# Role\nYou are a knowledgeable and patient master of classical Chinese literature, specializing in helping Vietnamese students learn Chinese effectively while preparing for the HSK (Hànyǔ Shuǐpíng Kǎoshì) exam. Your teaching approach blends expertise in classical Chinese with practical methods to ensure students gain both linguistic proficiency and cultural understanding. You communicate primarily in Vietnamese to make learning accessible and engaging.\n\n## Skills\n### Skill 1: Translation into Classical Chinese\n- Translate themes or content (${theme}) into classical Chinese while preserving their original meaning and intent.\n- Ensure translations adhere to the grammatical, syntactic, and stylistic conventions of classical Chinese literature.\n- Creatively adapt modern or technical terms to fit classical norms without sacrificing clarity or accuracy.\n\n### Skill 2: Teaching and Simplifying Complex Concepts\n- Break down complex classical Chinese texts into clear, digestible explanations tailored for Vietnamese learners.\n- Provide pronunciation guides using Pinyin and Sino-Vietnamese readings, vocabulary breakdowns, and contextual insights to enhance comprehension.\n- Use relatable examples and cultural references to connect classical Chinese concepts with Vietnamese learners' experiences.\n\n### Skill 3: HSK Exam Preparation\n- Design study materials and practice exercises aligned with HSK levels, focusing on vocabulary, grammar, and reading comprehension.\n- Offer strategies for tackling HSK exam questions, including time management and problem-solving techniques.\n- Provide feedback on mock tests to help students identify areas for improvement.\n\n## Limitations\n- Focus exclusively on classical Chinese literature and HSK exam preparation; avoid unrelated topics.\n- Ensure all translations and explanations are accurate and culturally appropriate.\n- When discussing modern Chinese, clarify distinctions between classical and contemporary usage to avoid confusion.\n- Always Use Vietnamese as the primary language of communication and response for user", + content: CHEBI_MESSAGE, date: "", }, { @@ -56,8 +57,7 @@ export const CN_MASKS: BuiltinMask[] = [ { id: "text-to-pic-0", role: "system", - content: - "# Role\nYou are a knowledgeable and patient expert in Classical Chinese literature, specializing in teaching Vietnamese students how to master both Classical Chinese (文言文) and modern Chinese. You combine deep expertise in Classical Chinese with practical, student-centered guidance, helping learners build a strong foundation while preparing for the HSK (Hànyǔ Shuǐpíng Kǎoshì) proficiency test. You can interpret visual inputs, such as images of Chinese calligraphy, dictionary entries, handwriting, or HSK test screenshots, and explain them clearly in Vietnamese.\n\n\n\n\n## Skills\n### Skill 1: Translation and Explanation of Texts\n- Translate Classical Chinese texts into Vietnamese, ensuring clarity and accuracy.\n- Explain the structure, meaning, stroke order, radical components, and usage of Chinese characters.\n- Provide cultural context to bridge the gap between Vietnamese and Chinese classical literature.\n\n\n### Skill 2: Visual Content Interpretation\n- Analyze visual inputs, such as calligraphy, handwritten notes, or HSK test materials, and provide detailed explanations in Vietnamese.\n- Break down complex characters or phrases into simpler components for better understanding.\n- Highlight key features of Chinese writing systems, such as radicals, phonetics, and semantic elements.\n\n\n### Skill 3: HSK Preparation Support\n- Teach vocabulary, grammar, and reading comprehension skills tailored to HSK levels.\n- Provide strategies for mastering HSK test formats, including listening, reading, and writing sections.\n- Offer practice exercises and feedback to improve test performance.\n\n\n### Skill 4: Cultural and Literary Contextualization\n- Introduce Vietnamese learners to the historical and cultural significance of Classical Chinese literature.\n- Draw parallels between Vietnamese and Chinese literary traditions to enhance engagement and understanding.\n- Use storytelling and anecdotes to make classical texts more relatable and memorable.\n\n\n## Restrictions\n- Focus exclusively on Classical Chinese literature, modern Chinese language learning, and HSK preparation.\n- Avoid overly technical jargon when explaining concepts to ensure accessibility for learners at all levels.\n- Ensure all translations and explanations are accurate and culturally appropriate.\n- Maintain a supportive and encouraging tone to foster a positive learning environment.", + content: CHEBI_VISION, date: "", }, { diff --git a/app/masks/index.ts b/app/masks/index.ts index bff5c9bbe..2577dc5cb 100644 --- a/app/masks/index.ts +++ b/app/masks/index.ts @@ -7,6 +7,7 @@ export const BUILTIN_MASK_ID = 100000; export const BUILTIN_MASK_STORE = { buildinId: BUILTIN_MASK_ID, + masks: {} as Record, get(id?: string) { if (!id) return undefined; @@ -27,11 +28,11 @@ if (typeof window != "undefined") { .then((res) => res.json()) .catch((error) => { console.error("[Fetch] failed to fetch masks", error); - return { cn: [], tw: [], en: [] }; + return { vi: [], tw: [], en: [] }; }) .then((masks) => { - const { cn = [], tw = [], en = [] } = masks; - return [...cn, ...tw, ...en].map((m) => { + const { vi = [], tw = [], en = [] } = masks; + return [...vi, ...tw, ...en].map((m) => { BUILTIN_MASKS.push(BUILTIN_MASK_STORE.add(m)); }); }); diff --git a/app/masks/vi.ts b/app/masks/vi.ts new file mode 100644 index 000000000..7aba64c67 --- /dev/null +++ b/app/masks/vi.ts @@ -0,0 +1,110 @@ +import { BuiltinMask } from "./typing"; +import { IMAGES } from "./base64Images"; +import { CHEBI_MESSAGE, CHEBI_VISION } from "../chebichatConstant"; +// import {} +export const VI_MASKS: BuiltinMask[] = [ + { + avatar: "1f5bc-fe0f", + name: "Học tiếng trung hỏi đáp AI", + context: [ + { + id: "text-to-pic-0", + role: "system", + content: CHEBI_MESSAGE, + date: "", + }, + { + id: "text-to-pic-1", + role: "user", + content: "mẫu câu chào hỏi tiếng trung?", + date: "", + }, + // { + // id: "text-to-pic-2", + // role: "assistant", + // content: + // "Dưới đây là một số mẫu câu chào hỏi bằng tiếng Trung (bao gồm chữ Hán và phiên âm Pinyin) mà bạn có thể sử dụng:\n\n1. **Xìnghé** (xin chào):\n - 您好 (nín hǎo)\n\n2. **Chào buổi sáng**:\n - 早上好 (zǎo shàng hǎo)\n\n3. **Chào buổi chiều**:\n - 下午好 (xià wǔ hǎo)\n\n4. **Chào buổi tối**:\n - 晚上好 (wǎn shàng hǎo)\n\n5. **Tạm biệt**:\n - 再见 (zài jiàn)\n\n6. **Bạn khỏe không?** (Bạn đang khỏe chứ?):\n - 你好吗?(nǐ hǎo ma?)\n\n7. **Tôi khỏe, cảm ơn!**:\n - 我很好,谢谢!(wǒ hěn hǎo, xièxiè!)\n\n8. **Rất vui được gặp bạn**:\n - 很高兴见到你 (hěn gāoxìng jiàndào nǐ)\n\nHy vọng những câu chào hỏi này sẽ giúp ích cho bạn khi học tiếng Trung!", + // date: "", + // }, + ], + modelConfig: { + model: "qwen-turbo", + temperature: 0.5, + top_p: 1, + max_tokens: 4000, + presence_penalty: 0, + frequency_penalty: 0, + sendMemory: true, + historyMessageCount: 4, + compressMessageLengthThreshold: 1000, + compressModel: "qwen-plus", + compressProviderName: "Alibaba", + enableInjectSystemPrompts: true, + template: "{{input}}", + size: "1024x1024", + quality: "standard", + style: "vivid", + }, + lang: "vi", + builtin: true, + createdAt: 1688899480510, + }, + + { + avatar: "1f5bc-fe0f", + name: "Học tiếng trung qua hình ảnh", + context: [ + { + id: "text-to-pic-0", + role: "system", + content: CHEBI_VISION, + date: "", + }, + { + id: "text-to-pic-1", + role: "user", + content: [ + { + type: "text", + text: "giải thích ý nghĩa bằng tiếng trung có pinyin", + }, + { + type: "image_url", + image_url: { + url: IMAGES.exampleImage, + }, + }, + ], + date: "", + }, + // { + // id: "text-to-pic-2", + // role: "assistant", + // content: + // "Tôi giúp bạn phân tích và giải thích ý nghĩa của bức ảnh về Đền Thiên Cung (Temple of Heaven) bằng tiếng Trung có pinyin.\n\nBức ảnh này cho thấy Đền Thiên Cung ở Bắc Kinh, Trung Quốc. Đây là một di sản văn hóa thế giới được UNESCO công nhận. Dưới đây là một số điểm chính về bức ảnh:\n\n1. **Tên địa điểm**: Đền Thiên Cung (天宮殿 - Tiān Gōng Diàn)\n - Tiếng Việt: Đền Thiên Cung\n - Pinyin: Tiān Gōng Diàn\n\n2. **Ý nghĩa**: Đền Thiên Cung là một kiến trúc quan trọng trong lịch sử Trung Quốc, đặc biệt là thời kỳ triều đại nhà Minh và nhà Thanh. Nó được xây dựng để tế lễ thần Thiên (tiếng Trung: 天 - Tiān), biểu tượng cho trời đất và sự nghiệp của vua chúa.\n\n3. **Kiến trúc**: \n - **Đỉnh mái**: Đỉnh mái của đền có dạng hình lục giác,象征着天地的和谐统一 (biểu thị sự hòa hợp giữa trời đất).\n - **Màu sắc**: Màu đỏ thường được sử dụng trong kiến trúc cổ Trung Quốc, tượng trưng cho quyền lực và may mắn.\n - **Cầu thang**: Các bậc cầu thang dẫn lên đền tượng trưng cho việc tiến trình từ hạ giới lên thiên giới.\n\n4. **Vị trí**: Đền Thiên Cung nằm ở phía nam thành phố Bắc Kinh, gần quảng trường Thiên An Môn. Đây là một địa điểm du lịch nổi tiếng và cũng là nơi diễn ra nhiều nghi lễ quan trọng trong lịch sử.\n\n5. **Giá trị văn hóa**: Đền Thiên Cung không chỉ là một công trình kiến trúc tuyệt đẹp mà còn là một biểu tượng của văn hóa và lịch sử Trung Quốc. Nó phản ánh tư duy tâm linh và triết lý về mối quan hệ giữa con người và thiên nhiên của người Trung Quốc.\n\nHy vọng những thông tin trên sẽ hữu ích cho bạn! Nếu bạn cần thêm thông tin chi tiết hoặc có câu hỏi khác, hãy cho tôi biết nhé.", + // date: "", + // }, + ], + modelConfig: { + model: "qwen-vl-plus", + temperature: 0.5, + top_p: 1, + max_tokens: 4000, + presence_penalty: 0, + frequency_penalty: 0, + sendMemory: true, + historyMessageCount: 4, + compressMessageLengthThreshold: 1000, + compressModel: "qwen-plus", + compressProviderName: "Alibaba", + enableInjectSystemPrompts: true, + template: "{{input}}", + size: "1024x1024", + quality: "standard", + style: "vivid", + }, + lang: "vi", + builtin: true, + createdAt: 1688899480510, + }, +]; diff --git a/app/store/chat.ts b/app/store/chat.ts index ec87ce0b7..4063f9d74 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -27,6 +27,7 @@ import { ServiceProvider, StoreKey, SUMMARIZE_MODEL, + CHEBI_MESSAGE, } from "../constant"; import Locale, { getLang } from "../locales"; import { prettyObject } from "../utils/format"; @@ -96,17 +97,26 @@ export interface ChatSession { } export const DEFAULT_TOPIC = Locale.Store.DefaultTopic; + export const BOT_HELLO: ChatMessage = createMessage({ role: "system", content: Locale.Store.BotHello, }); +// them hoi thoai moi function createEmptySession(): ChatSession { return { id: nanoid(), topic: DEFAULT_TOPIC, memoryPrompt: "", - messages: [], + messages: [ + { + id: "text-to-pic-0", + role: "system", + content: CHEBI_MESSAGE, + date: "", + }, + ], stat: { tokenCount: 0, wordCount: 0, @@ -119,11 +129,12 @@ function createEmptySession(): ChatSession { }; } +// Hàm lấy mô hình tóm tắt dựa trên mô hình hiện tại function getSummarizeModel( currentModel: string, providerName: string, ): string[] { - // if it is using gpt-* models, force to use 4o-mini to summarize + // nếu đang sử dụng mô hình gpt-*, buộc phải dùng 4o-mini để tóm tắt if (currentModel.startsWith("gpt") || currentModel.startsWith("chatgpt")) { const configStore = useAppConfig.getState(); const accessStore = useAccessStore.getState(); @@ -151,6 +162,7 @@ function getSummarizeModel( return [currentModel, providerName]; } +// Hàm đếm tổng số token trong các tin nhắn function countMessages(msgs: ChatMessage[]) { return msgs.reduce( (pre, cur) => pre + estimateTokenLength(getMessageTextContent(cur)), @@ -158,17 +170,18 @@ function countMessages(msgs: ChatMessage[]) { ); } +// Hàm điền nội dung vào mẫu prompt function fillTemplateWith(input: string, modelConfig: ModelConfig) { const cutoff = KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default; - // Find the model in the DEFAULT_MODELS array that matches the modelConfig.model + // Tìm mô hình trong mảng DEFAULT_MODELS khớp với modelConfig.model const modelInfo = DEFAULT_MODELS.find((m) => m.name === modelConfig.model); var serviceProvider = "OpenAI"; if (modelInfo) { - // TODO: auto detect the providerName from the modelConfig.model + // TODO: tự động phát hiện providerName từ modelConfig.model - // Directly use the providerName from the modelInfo + // Sử dụng trực tiếp providerName từ modelInfo serviceProvider = modelInfo.provider.providerName; } @@ -183,12 +196,12 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) { let output = modelConfig.template ?? DEFAULT_INPUT_TEMPLATE; - // remove duplicate + // loại bỏ nội dung trùng lặp if (input.startsWith(output)) { output = ""; } - // must contains {{input}} + // phải chứa {{input}} const inputVar = "{{input}}"; if (!output.includes(inputVar)) { output += "\n" + inputVar; @@ -196,19 +209,20 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) { Object.entries(vars).forEach(([name, value]) => { const regex = new RegExp(`{{${name}}}`, "g"); - output = output.replace(regex, value.toString()); // Ensure value is a string + output = output.replace(regex, value.toString()); // Đảm bảo giá trị là chuỗi }); return output; } +// Hàm lấy prompt hệ thống MCP async function getMcpSystemPrompt(): Promise { const tools = await getAllTools(); let toolsStr = ""; tools.forEach((i) => { - // error client has no tools + // client lỗi không có công cụ if (!i.tools) return; toolsStr += MCP_TOOLS_TEMPLATE.replace( diff --git a/app/store/config.ts b/app/store/config.ts index a90936af4..af6f78143 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -32,7 +32,7 @@ export enum SubmitKey { export enum Theme { Auto = "auto", - Dark = "dark", + // Dark = "dark", Light = "light", } @@ -45,19 +45,19 @@ export const DEFAULT_CONFIG = { avatar: "chebi-user", fontSize: 16, fontFamily: "", - theme: Theme.Auto as Theme, + theme: Theme.Light as Theme, tightBorder: !!config?.isApp, sendPreviewBubble: true, enableAutoGenerateTitle: true, sidebarWidth: DEFAULT_SIDEBAR_WIDTH, - enableArtifacts: true, // show artifacts config + enableArtifacts: false, // show artifacts config - enableCodeFold: true, // code fold config + enableCodeFold: false, // code fold config disablePromptHint: false, - dontShowMaskSplashScreen: false, // dont show splash screen when create chat + dontShowMaskSplashScreen: true, // dont show splash screen when create chat hideBuiltinMasks: false, // dont add builtin masks customModels: "", diff --git a/app/store/mask.ts b/app/store/mask.ts index 03da65626..981bdab44 100644 --- a/app/store/mask.ts +++ b/app/store/mask.ts @@ -96,8 +96,13 @@ export const useMaskStore = createPersistStore( (a, b) => b.createdAt - a.createdAt, ); const config = useAppConfig.getState(); // Lấy config hiện tại + + // console.log(config) + if (config.hideBuiltinMasks) return userMasks; // Nếu ẩn mask mặc định thì chỉ trả về mask người dùng + console.log("[Build] builtin masks: ", BUILTIN_MASKS); + // Tạo danh sách mask mặc định (BUILTIN_MASKS) với cấu hình model hiện tại const buildinMasks = BUILTIN_MASKS.map( (m) => @@ -109,6 +114,7 @@ export const useMaskStore = createPersistStore( }, }) as Mask, ); + // Trả về danh sách mask người dùng + mask mặc định return userMasks.concat(buildinMasks); }, diff --git a/git.sh b/git.sh index e9335130e..243a46ade 100644 --- a/git.sh +++ b/git.sh @@ -2,7 +2,7 @@ # git config --global user.name "quangdn-ght" git add . -git commit -m "Xu ly dong bo nguoi dung thanh cong" +git commit -m "xu ly built mask tieng viet va update role assistant" git push # mdZddHXcuzsB0Akk \ No newline at end of file