From 0f6ed9c2932f6fd31214ec5d1b9d1d6a5b1f56d5 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Sun, 12 Nov 2023 00:53:15 +0700 Subject: [PATCH 1/5] Feat UI/UX Page Local Language [Exporter Message] [+] fix(exporter.tsx): update the text in the ExportMessageModal component to use the localized title from the locale file [+] feat(cn.ts, en.ts, id.ts): add localized title for the Exporter Description in the respective locale files --- app/components/exporter.tsx | 2 +- app/locales/cn.ts | 3 +++ app/locales/en.ts | 3 +++ app/locales/id.ts | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 435e24953..571c28122 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -53,7 +53,7 @@ export function ExportMessageModal(props: { onClose: () => void }) { opacity: 0.5, }} > - 只有清除上下文之后的消息会被展示 + {Locale.Exporter.Description.Title} } > diff --git a/app/locales/cn.ts b/app/locales/cn.ts index e721adef7..bb4baf506 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -441,6 +441,9 @@ const cn = { Config: "配置", }, Exporter: { + Description : { + Title: "只有清除上下文之后的消息会被展示" + }, Model: "模型", Messages: "消息", Topic: "主题", diff --git a/app/locales/en.ts b/app/locales/en.ts index c6e61ecab..f90cffd4c 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -442,6 +442,9 @@ const en: LocaleType = { Config: "Config", }, Exporter: { + Description: { + Title: "Only messages after clearing the context will be displayed" + }, Model: "Model", Messages: "Messages", Topic: "Topic", diff --git a/app/locales/id.ts b/app/locales/id.ts index 4da55948e..571156a57 100644 --- a/app/locales/id.ts +++ b/app/locales/id.ts @@ -368,6 +368,9 @@ const id: PartialLocaleType = { Edit: "Edit", }, Exporter: { + Description: { + Title: "Hanya pesan setelah menghapus konteks yang akan ditampilkan" + }, Model: "Model", Messages: "Pesan", Topic: "Topik", From a46f08154e74744ac6c0bec6d074e00df445a851 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Sun, 12 Nov 2023 01:50:35 +0700 Subject: [PATCH 2/5] Fix UI/UX Page Local Language [Exporter Message] fix(locales): fix incorrect description title in en.ts and id.ts - Change "Only messages after clearing the context will be displayed" to "Only messages before clearing the context will be displayed" in en.ts - Change "Hanya pesan setelah menghapus konteks yang akan ditampilkan" to "Hanya pesan sebelum menghapus konteks yang akan ditampilkan" in id.ts --- app/locales/en.ts | 2 +- app/locales/id.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/locales/en.ts b/app/locales/en.ts index f90cffd4c..7390b7284 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -443,7 +443,7 @@ const en: LocaleType = { }, Exporter: { Description: { - Title: "Only messages after clearing the context will be displayed" + Title: "Only messages before clearing the context will be displayed" }, Model: "Model", Messages: "Messages", diff --git a/app/locales/id.ts b/app/locales/id.ts index 571156a57..2b9b21e11 100644 --- a/app/locales/id.ts +++ b/app/locales/id.ts @@ -369,7 +369,7 @@ const id: PartialLocaleType = { }, Exporter: { Description: { - Title: "Hanya pesan setelah menghapus konteks yang akan ditampilkan" + Title: "Hanya pesan sebelum menghapus konteks yang akan ditampilkan" }, Model: "Model", Messages: "Pesan", From 5ba3fc9321a126dce367c57d14649ec8a590dc82 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Sun, 12 Nov 2023 01:56:31 +0700 Subject: [PATCH 3/5] Revert "Fix UI/UX Page Local Language [Exporter Message]" This reverts commit a46f08154e74744ac6c0bec6d074e00df445a851. Reason : better after instead of before --- app/locales/en.ts | 2 +- app/locales/id.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/locales/en.ts b/app/locales/en.ts index 7390b7284..f90cffd4c 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -443,7 +443,7 @@ const en: LocaleType = { }, Exporter: { Description: { - Title: "Only messages before clearing the context will be displayed" + Title: "Only messages after clearing the context will be displayed" }, Model: "Model", Messages: "Messages", diff --git a/app/locales/id.ts b/app/locales/id.ts index 2b9b21e11..571156a57 100644 --- a/app/locales/id.ts +++ b/app/locales/id.ts @@ -369,7 +369,7 @@ const id: PartialLocaleType = { }, Exporter: { Description: { - Title: "Hanya pesan sebelum menghapus konteks yang akan ditampilkan" + Title: "Hanya pesan setelah menghapus konteks yang akan ditampilkan" }, Model: "Model", Messages: "Pesan", From b52e237044bdc0ddf0427dfb363486da10810973 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 12 Nov 2023 19:33:19 +0800 Subject: [PATCH 4/5] fix: #3189 should correct math eq in exporter --- app/components/chat-list.tsx | 5 ++++- app/components/chat.tsx | 7 ++++++- app/components/exporter.module.scss | 3 ++- app/components/exporter.tsx | 7 +++---- app/components/markdown.tsx | 2 +- app/components/mask.tsx | 18 +++++++++++------- app/components/message-selector.tsx | 5 ++++- app/components/new-chat.tsx | 16 ++++------------ app/constant.ts | 3 +++ app/locales/cn.ts | 4 ++-- 10 files changed, 40 insertions(+), 30 deletions(-) diff --git a/app/components/chat-list.tsx b/app/components/chat-list.tsx index f76b369f1..33967717d 100644 --- a/app/components/chat-list.tsx +++ b/app/components/chat-list.tsx @@ -61,7 +61,10 @@ export function ChatItem(props: { {props.narrow ? (
- +
{props.count} diff --git a/app/components/chat.tsx b/app/components/chat.tsx index a088483e7..4d9de7259 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1176,7 +1176,12 @@ function _Chat() { {["system"].includes(message.role) ? ( ) : ( - + )} )} diff --git a/app/components/exporter.module.scss b/app/components/exporter.module.scss index c2046ffc0..d3bfc81ad 100644 --- a/app/components/exporter.module.scss +++ b/app/components/exporter.module.scss @@ -186,7 +186,8 @@ box-shadow: var(--card-shadow); border: var(--border-in-light); - *:not(li) { + code, + pre { overflow: hidden; } } diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 435e24953..185cbb20b 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -1,5 +1,5 @@ /* eslint-disable @next/next/no-img-element */ -import { ChatMessage, useAppConfig, useChatStore } from "../store"; +import { ChatMessage, ModelType, useAppConfig, useChatStore } from "../store"; import Locale from "../locales"; import styles from "./exporter.module.scss"; import { @@ -275,7 +275,8 @@ export function RenderExport(props: { }); props.onRender(renderMsgs); - }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); return (
@@ -619,8 +620,6 @@ export function MarkdownPreviewer(props: { ); } -// modified by BackTrackZ now it's looks better - export function JsonPreviewer(props: { messages: ChatMessage[]; topic: string; diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index 1a1fbf416..b4cae9a21 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -11,7 +11,7 @@ import mermaid from "mermaid"; import LoadingIcon from "../icons/three-dots.svg"; import React from "react"; -import { useDebouncedCallback, useThrottledCallback } from "use-debounce"; +import { useDebouncedCallback } from "use-debounce"; import { showImageModal } from "./ui-lib"; export function Mermaid(props: { code: string }) { diff --git a/app/components/mask.tsx b/app/components/mask.tsx index 9fe1d485a..3f616c3ac 100644 --- a/app/components/mask.tsx +++ b/app/components/mask.tsx @@ -18,6 +18,7 @@ import { ChatMessage, createMessage, ModelConfig, + ModelType, useAppConfig, useChatStore, } from "../store"; @@ -58,11 +59,11 @@ function reorder(list: T[], startIndex: number, endIndex: number): T[] { return result; } -export function MaskAvatar(props: { mask: Mask }) { - return props.mask.avatar !== DEFAULT_MASK_AVATAR ? ( - +export function MaskAvatar(props: { avatar: string; model?: ModelType }) { + return props.avatar !== DEFAULT_MASK_AVATAR ? ( + ) : ( - + ); } @@ -123,7 +124,10 @@ export function MaskConfig(props: { onClick={() => setShowPicker(true)} style={{ cursor: "pointer" }} > - +
@@ -398,7 +402,7 @@ export function MaskPage() { setSearchText(text); if (text.length > 0) { const result = allMasks.filter((m) => - m.name.toLowerCase().includes(text.toLowerCase()) + m.name.toLowerCase().includes(text.toLowerCase()), ); setSearchMasks(result); } else { @@ -523,7 +527,7 @@ export function MaskPage() {
- +
{m.name}
diff --git a/app/components/message-selector.tsx b/app/components/message-selector.tsx index 3d2321d09..c20153401 100644 --- a/app/components/message-selector.tsx +++ b/app/components/message-selector.tsx @@ -208,7 +208,10 @@ export function MessageSelector(props: { {m.role === "user" ? ( ) : ( - + )}
diff --git a/app/components/new-chat.tsx b/app/components/new-chat.tsx index 76cbbeeb1..54c646f23 100644 --- a/app/components/new-chat.tsx +++ b/app/components/new-chat.tsx @@ -17,21 +17,13 @@ import { useCommand } from "../command"; import { showConfirm } from "./ui-lib"; import { BUILTIN_MASK_STORE } from "../masks"; -function getIntersectionArea(aRect: DOMRect, bRect: DOMRect) { - const xmin = Math.max(aRect.x, bRect.x); - const xmax = Math.min(aRect.x + aRect.width, bRect.x + bRect.width); - const ymin = Math.max(aRect.y, bRect.y); - const ymax = Math.min(aRect.y + aRect.height, bRect.y + bRect.height); - const width = xmax - xmin; - const height = ymax - ymin; - const intersectionArea = width < 0 || height < 0 ? 0 : width * height; - return intersectionArea; -} - function MaskItem(props: { mask: Mask; onClick?: () => void }) { return (
- +
{props.mask.name}
); diff --git a/app/constant.ts b/app/constant.ts index 561899769..779c6f7e7 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -84,6 +84,9 @@ You are ChatGPT, a large language model trained by OpenAI. Knowledge cutoff: {{cutoff}} Current model: {{model}} Current time: {{time}} + +Latex inline: $x^2$ +Latex block: $$e=mc^2$$ `; export const SUMMARIZE_MODEL = "gpt-3.5-turbo"; diff --git a/app/locales/cn.ts b/app/locales/cn.ts index e721adef7..f5b65559f 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -85,8 +85,8 @@ const cn = { Copy: "全部复制", Download: "下载文件", Share: "分享到 ShareGPT", - MessageFromYou: "来自你的消息", - MessageFromChatGPT: "来自 ChatGPT 的消息", + MessageFromYou: "用户", + MessageFromChatGPT: "ChatGPT", Format: { Title: "导出格式", SubTitle: "可以导出 Markdown 文本或者 PNG 图片", From a0cd939bfd560621b854b7533fa0b28a329dfa75 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 12 Nov 2023 19:45:58 +0800 Subject: [PATCH 5/5] fix: #2841 dollar sign conflict with latex math --- app/components/markdown.tsx | 26 ++++++++++++++++++++++++-- app/constant.ts | 1 - 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index b4cae9a21..f3a916cc5 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -5,7 +5,7 @@ import RemarkBreaks from "remark-breaks"; import RehypeKatex from "rehype-katex"; import RemarkGfm from "remark-gfm"; import RehypeHighlight from "rehype-highlight"; -import { useRef, useState, RefObject, useEffect } from "react"; +import { useRef, useState, RefObject, useEffect, useMemo } from "react"; import { copyToClipboard } from "../utils"; import mermaid from "mermaid"; @@ -99,7 +99,29 @@ export function PreCode(props: { children: any }) { ); } +function escapeDollarNumber(text: string) { + let escapedText = ""; + + for (let i = 0; i < text.length; i += 1) { + let char = text[i]; + const nextChar = text[i + 1] || " "; + + if (char === "$" && nextChar >= "0" && nextChar <= "9") { + char = "\\$"; + } + + escapedText += char; + } + + return escapedText; +} + function _MarkDownContent(props: { content: string }) { + const escapedContent = useMemo( + () => escapeDollarNumber(props.content), + [props.content], + ); + return ( - {props.content} + {escapedContent} ); } diff --git a/app/constant.ts b/app/constant.ts index 779c6f7e7..69d5c511f 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -84,7 +84,6 @@ You are ChatGPT, a large language model trained by OpenAI. Knowledge cutoff: {{cutoff}} Current model: {{model}} Current time: {{time}} - Latex inline: $x^2$ Latex block: $$e=mc^2$$ `;