From ca792669fce17493a58be64ec2388b4e9db9abb5 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Fri, 10 Nov 2023 18:20:51 +0800 Subject: [PATCH 01/14] Update constant.ts --- app/constant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/constant.ts b/app/constant.ts index fbc0c72e378..561899769d4 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -8,7 +8,7 @@ export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/c export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`; export const RUNTIME_CONFIG_DOM = "danger-runtime-config"; -export const DEFAULT_CORS_HOST = "https://ab.nextweb.fun"; +export const DEFAULT_CORS_HOST = "https://a.nextweb.fun"; export const DEFAULT_API_HOST = `${DEFAULT_CORS_HOST}/api/proxy`; export const OPENAI_BASE_URL = "https://api.openai.com"; From 943214c6a78bf3b9c6ed12e029efa682adaee659 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Fri, 10 Nov 2023 18:21:22 +0800 Subject: [PATCH 02/14] Update README_CN.md --- README_CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_CN.md b/README_CN.md index 72376374f86..604771c5251 100644 --- a/README_CN.md +++ b/README_CN.md @@ -138,7 +138,7 @@ Azure Api 版本,你可以在这里找到:[Azure 文档](https://learn.micro OPENAI_API_KEY= # 中国大陆用户,可以使用本项目自带的代理进行开发,你也可以自由选择其他代理地址 -BASE_URL=https://ab.nextweb.fun/api/proxy +BASE_URL=https://a.nextweb.fun/api/proxy ``` ### 本地开发 From be9774943bc17e30111ccf6ec1eb8242e61f3fa1 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 12 Nov 2023 00:29:36 +0800 Subject: [PATCH 03/14] feat: #3224 auto switch to first avaliable model --- app/components/chat.tsx | 22 +++++++++++++++++++--- app/utils/hooks.ts | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index c27c3eee464..48f76e8ab48 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -431,11 +431,27 @@ export function ChatActions(props: { // switch model const currentModel = chatStore.currentSession().mask.modelConfig.model; - const models = useAllModels() - .filter((m) => m.available) - .map((m) => m.name); + const allModels = useAllModels(); + const models = useMemo( + () => allModels.filter((m) => m.available).map((m) => m.name), + [allModels], + ); const [showModelSelector, setShowModelSelector] = useState(false); + useEffect(() => { + // if current model is not available + // switch to first available model + const isUnavaliableModel = !models.includes(currentModel); + if (isUnavaliableModel && models.length > 0) { + const nextModel = models[0] as ModelType; + chatStore.updateCurrentSession( + (session) => (session.mask.modelConfig.model = nextModel), + ); + showToast(nextModel); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [currentModel, models]); + return (
{couldStop && ( diff --git a/app/utils/hooks.ts b/app/utils/hooks.ts index f6bfae67323..35d1f53a4c9 100644 --- a/app/utils/hooks.ts +++ b/app/utils/hooks.ts @@ -8,7 +8,7 @@ export function useAllModels() { const models = useMemo(() => { return collectModels( configStore.models, - [accessStore.customModels, configStore.customModels].join(","), + [configStore.customModels, accessStore.customModels].join(","), ); }, [accessStore.customModels, configStore.customModels, configStore.models]); From a5a1f2e8ad781e0c82a6f775746286477d806545 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 12 Nov 2023 00:46:21 +0800 Subject: [PATCH 04/14] feat: CUSTOM_MODELS support mapper --- app/api/common.ts | 2 +- app/components/chat.tsx | 10 +++++----- app/utils/model.ts | 32 +++++++++++++++++++++----------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index adec611b2b3..dd1cc0bb80e 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -81,7 +81,7 @@ export async function requestOpenai(req: NextRequest) { const jsonBody = JSON.parse(clonedBody) as { model?: string }; // not undefined and is false - if (modelTable[jsonBody?.model ?? ""] === false) { + if (modelTable[jsonBody?.model ?? ""].available === false) { return NextResponse.json( { error: true, diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 48f76e8ab48..a088483e7b6 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -433,7 +433,7 @@ export function ChatActions(props: { const currentModel = chatStore.currentSession().mask.modelConfig.model; const allModels = useAllModels(); const models = useMemo( - () => allModels.filter((m) => m.available).map((m) => m.name), + () => allModels.filter((m) => m.available), [allModels], ); const [showModelSelector, setShowModelSelector] = useState(false); @@ -441,9 +441,9 @@ export function ChatActions(props: { useEffect(() => { // if current model is not available // switch to first available model - const isUnavaliableModel = !models.includes(currentModel); + const isUnavaliableModel = !models.some((m) => m.name === currentModel); if (isUnavaliableModel && models.length > 0) { - const nextModel = models[0] as ModelType; + const nextModel = models[0].name as ModelType; chatStore.updateCurrentSession( (session) => (session.mask.modelConfig.model = nextModel), ); @@ -531,8 +531,8 @@ export function ChatActions(props: { ({ - title: m, - value: m, + title: m.displayName, + value: m.name, }))} onClose={() => setShowModelSelector(false)} onSelection={(s) => { diff --git a/app/utils/model.ts b/app/utils/model.ts index 23090f9d2f3..d5c009c02d2 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -4,21 +4,34 @@ export function collectModelTable( models: readonly LLMModel[], customModels: string, ) { - const modelTable: Record = {}; + const modelTable: Record< + string, + { available: boolean; name: string; displayName: string } + > = {}; // default models - models.forEach((m) => (modelTable[m.name] = m.available)); + models.forEach( + (m) => + (modelTable[m.name] = { + ...m, + displayName: m.name, + }), + ); // server custom models customModels .split(",") .filter((v) => !!v && v.length > 0) .map((m) => { - if (m.startsWith("+")) { - modelTable[m.slice(1)] = true; - } else if (m.startsWith("-")) { - modelTable[m.slice(1)] = false; - } else modelTable[m] = true; + const available = !m.startsWith("-"); + const nameConfig = + m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m; + const [name, displayName] = nameConfig.split(":"); + modelTable[name] = { + name, + displayName: displayName || name, + available, + }; }); return modelTable; } @@ -31,10 +44,7 @@ export function collectModels( customModels: string, ) { const modelTable = collectModelTable(models, customModels); - const allModels = Object.keys(modelTable).map((m) => ({ - name: m, - available: modelTable[m], - })); + const allModels = Object.values(modelTable); return allModels; } From 64647b0bb3d06b5c0ab17c96cf245753d8f4b48a Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 12 Nov 2023 00:49:58 +0800 Subject: [PATCH 05/14] chore: update doc for mapped `CUSTOM_MODELS` --- README.md | 4 ++-- README_CN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a7c862b4099..abe93306180 100644 --- a/README.md +++ b/README.md @@ -216,9 +216,9 @@ If you want to disable parse settings from url, set this to 1. ### `CUSTOM_MODELS` (optional) > Default: Empty -> Example: `+llama,+claude-2,-gpt-3.5-turbo` means add `llama, claude-2` to model list, and remove `gpt-3.5-turbo` from list. +> Example: `+llama,+claude-2,-gpt-3.5-turbo,gpt-4-1106-preview:gpt-4-turbo` means add `llama, claude-2` to model list, and remove `gpt-3.5-turbo` from list, and display `gpt-4-1106-preview` as `gpt-4-turbo`. -To control custom models, use `+` to add a custom model, use `-` to hide a model, separated by comma. +To control custom models, use `+` to add a custom model, use `-` to hide a model, use `name:displayName` to customize model name, separated by comma. ## Requirements diff --git a/README_CN.md b/README_CN.md index 604771c5251..dde8c19b352 100644 --- a/README_CN.md +++ b/README_CN.md @@ -122,9 +122,9 @@ Azure Api 版本,你可以在这里找到:[Azure 文档](https://learn.micro ### `CUSTOM_MODELS` (可选) -> 示例:`+qwen-7b-chat,+glm-6b,-gpt-3.5-turbo` 表示增加 `qwen-7b-chat` 和 `glm-6b` 到模型列表,而从列表中删除 `gpt-3.5-turbo`。 +> 示例:`+qwen-7b-chat,+glm-6b,-gpt-3.5-turbo,gpt-4-1106-preview:gpt-4-turbo` 表示增加 `qwen-7b-chat` 和 `glm-6b` 到模型列表,而从列表中删除 `gpt-3.5-turbo`,并将 `gpt-4-1106-preview` 模型名字展示为 `gpt-4-turbo`。 -用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,用英文逗号隔开。 +用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名:展示名` 来自定义模型的展示名,用英文逗号隔开。 ## 开发 From be6d45e49f1df90daba4625117b95903189891c2 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 12 Nov 2023 01:21:39 +0800 Subject: [PATCH 06/14] feat: close #3222 share message list should start from clear context index --- app/components/exporter.tsx | 29 ++++++++++++++----- app/components/message-selector.module.scss | 10 +++++-- app/components/message-selector.tsx | 31 ++++++++++++++++----- app/components/ui-lib.tsx | 4 ++- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index 0a885d87463..435e24953e6 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -27,7 +27,7 @@ import { Avatar } from "./emoji"; import dynamic from "next/dynamic"; import NextImage from "next/image"; -import { toBlob, toJpeg, toPng } from "html-to-image"; +import { toBlob, toPng } from "html-to-image"; import { DEFAULT_MASK_AVATAR } from "../store/mask"; import { api } from "../client/api"; import { prettyObject } from "../utils/format"; @@ -41,7 +41,22 @@ const Markdown = dynamic(async () => (await import("./markdown")).Markdown, { export function ExportMessageModal(props: { onClose: () => void }) { return (
- + + 只有清除上下文之后的消息会被展示 +
+ } + >
@@ -149,7 +164,7 @@ export function MessageExporter() { if (exportConfig.includeContext) { ret.push(...session.mask.context); } - ret.push(...session.messages.filter((m, i) => selection.has(m.id))); + ret.push(...session.messages.filter((m) => selection.has(m.id))); return ret; }, [ exportConfig.includeContext, @@ -437,13 +452,13 @@ export function ImagePreviewer(props: { showToast(Locale.Export.Image.Toast); const dom = previewRef.current; if (!dom) return; - + const isApp = getClientConfig()?.isApp; - + try { const blob = await toPng(dom); if (!blob) return; - + if (isMobile || (isApp && window.__TAURI__)) { if (isApp && window.__TAURI__) { const result = await window.__TAURI__.dialog.save({ @@ -459,7 +474,7 @@ export function ImagePreviewer(props: { }, ], }); - + if (result !== null) { const response = await fetch(blob); const buffer = await response.arrayBuffer(); diff --git a/app/components/message-selector.module.scss b/app/components/message-selector.module.scss index b4ba1a1412a..c8defb6b027 100644 --- a/app/components/message-selector.module.scss +++ b/app/components/message-selector.module.scss @@ -58,8 +58,8 @@ } .body { - flex-grow: 1; - max-width: calc(100% - 40px); + flex: 1; + max-width: calc(100% - 80px); .date { font-size: 12px; @@ -71,6 +71,12 @@ font-size: 12px; } } + + .checkbox { + display: flex; + justify-content: flex-end; + flex: 1; + } } } } diff --git a/app/components/message-selector.tsx b/app/components/message-selector.tsx index cadf52e643e..3d2321d0962 100644 --- a/app/components/message-selector.tsx +++ b/app/components/message-selector.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { ChatMessage, useAppConfig, useChatStore } from "../store"; import { Updater } from "../typing"; import { IconButton } from "./button"; @@ -73,11 +73,23 @@ export function MessageSelector(props: { const chatStore = useChatStore(); const session = chatStore.currentSession(); const isValid = (m: ChatMessage) => m.content && !m.isError && !m.streaming; - const messages = session.messages.filter( - (m, i) => - m.id && // message must have id - isValid(m) && - (i >= session.messages.length - 1 || isValid(session.messages[i + 1])), + const allMessages = useMemo(() => { + let startIndex = Math.max(0, session.clearContextIndex ?? 0); + if (startIndex === session.messages.length - 1) { + startIndex = 0; + } + return session.messages.slice(startIndex); + }, [session.messages, session.clearContextIndex]); + + const messages = useMemo( + () => + allMessages.filter( + (m, i) => + m.id && // message must have id + isValid(m) && + (i >= allMessages.length - 1 || isValid(allMessages[i + 1])), + ), + [allMessages], ); const messageCount = messages.length; const config = useAppConfig(); @@ -176,6 +188,8 @@ export function MessageSelector(props: {
{messages.map((m, i) => { if (!isInSearchResult(m.id!)) return null; + const id = m.id ?? i; + const isSelected = props.selection.has(id); return (
{ props.updateSelection((selection) => { - const id = m.id ?? i; selection.has(id) ? selection.delete(id) : selection.add(id); }); onClickIndex(i); @@ -206,6 +219,10 @@ export function MessageSelector(props: { {m.content}
+ +
+ +
); })} diff --git a/app/components/ui-lib.tsx b/app/components/ui-lib.tsx index 0c927728a4e..f7e326fd318 100644 --- a/app/components/ui-lib.tsx +++ b/app/components/ui-lib.tsx @@ -97,8 +97,9 @@ export function Loading() { interface ModalProps { title: string; children?: any; - actions?: JSX.Element[]; + actions?: React.ReactNode[]; defaultMax?: boolean; + footer?: React.ReactNode; onClose?: () => void; } export function Modal(props: ModalProps) { @@ -147,6 +148,7 @@ export function Modal(props: ModalProps) {
{props.children}
+ {props.footer}
{props.actions?.map((action, i) => (
From 0f6ed9c2932f6fd31214ec5d1b9d1d6a5b1f56d5 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Sun, 12 Nov 2023 00:53:15 +0700 Subject: [PATCH 07/14] 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 435e24953e6..571c281226c 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 e721adef7ae..bb4baf50621 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 c6e61ecab04..f90cffd4cb1 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 4da55948efc..571156a5776 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 08/14] 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 f90cffd4cb1..7390b72840d 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 571156a5776..2b9b21e1122 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 09/14] 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 7390b72840d..f90cffd4cb1 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 2b9b21e1122..571156a5776 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 3a654ba1998581ce5e319988277d2858854f0edf Mon Sep 17 00:00:00 2001 From: nanaya Date: Sun, 12 Nov 2023 11:18:14 +0800 Subject: [PATCH 10/14] UI (model selection): hide unavailable model options --- app/components/model-config.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/components/model-config.tsx b/app/components/model-config.tsx index 1c730e1449f..214a18c79b5 100644 --- a/app/components/model-config.tsx +++ b/app/components/model-config.tsx @@ -25,11 +25,13 @@ export function ModelConfigList(props: { ); }} > - {allModels.map((v, i) => ( - - ))} + {allModels + .filter((v) => v.available) + .map((v, i) => ( + + ))} Date: Sun, 12 Nov 2023 19:33:19 +0800 Subject: [PATCH 11/14] 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 f76b369f12d..33967717d53 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 a088483e7b6..4d9de7259cc 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 c2046ffc09d..d3bfc81add1 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 435e24953e6..185cbb20b0e 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 1a1fbf41677..b4cae9a21e1 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 9fe1d485a6b..3f616c3ac15 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 3d2321d0962..c2015340139 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 76cbbeeb17e..54c646f237c 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 561899769d4..779c6f7e76f 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 e721adef7ae..f5b65559f3d 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 12/14] 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 b4cae9a21e1..f3a916cc535 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 779c6f7e76f..69d5c511f0a 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$$ `; From d033168d80b54636e306d6a38e604482f3999486 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 13 Nov 2023 10:53:30 +0800 Subject: [PATCH 13/14] fix: #3241 should not ensure openai url non-empty --- app/store/access.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/store/access.ts b/app/store/access.ts index 2abe1e3cc9f..3b9008ba84b 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -49,7 +49,7 @@ export const useAccessStore = createPersistStore( }, isValidOpenAI() { - return ensure(get(), ["openaiUrl", "openaiApiKey"]); + return ensure(get(), ["openaiApiKey"]); }, isValidAzure() { From 011b52d07d3d5d5c96a821ded5989d9be9fd7274 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 13 Nov 2023 16:53:36 +0800 Subject: [PATCH 14/14] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index abe93306180..d4e304f9d04 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,7 @@ If you want to add a new translation, read this [document](./docs/translation.md [@synwith](https://github.com/synwith) [@piksonGit](https://github.com/piksonGit) [@ouyangzhiping](https://github.com/ouyangzhiping) +[@wenjiavv](https://github.com/wenjiavv) ### Contributor