diff --git a/client/public/docs/chatProblem.md b/client/public/docs/chatProblem.md index 0dcc43d28..1b5eca3ef 100644 --- a/client/public/docs/chatProblem.md +++ b/client/public/docs/chatProblem.md @@ -14,7 +14,7 @@ | FastAI4k - 对话 | 0.015 | | FastAI16k - 对话 | 0.03 | | FastAI-Plus - 对话 | 0.45 | -| 文件拆分 | 0.03 | +| 文件 QA 拆分 | 0.03 | **其他问题** | 交流群 | 小助手 | diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 2c7d2d17a..09f9a5ff8 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -38,6 +38,7 @@ "Admin Mark Content": "Corrected response", "Complete Response": "Complete Response", "Confirm to clear history": "Confirm to clear history?", + "Confirm to clear share chat histroy": " Are you sure to delete all chats?", "Exit Chat": "Exit", "Feedback Close": "Close Feedback", "Feedback Failed": "Feedback Failed", diff --git a/client/public/locales/zh/common.json b/client/public/locales/zh/common.json index b1116d841..54c848082 100644 --- a/client/public/locales/zh/common.json +++ b/client/public/locales/zh/common.json @@ -38,6 +38,7 @@ "Admin Mark Content": "纠正后的回复", "Complete Response": "完整响应", "Confirm to clear history": "确认清空该应用的在线聊天记录?分享和 API 调用的记录不会被清空。", + "Confirm to clear share chat histroy": "确认删除所有聊天记录?", "Exit Chat": "退出聊天", "Feedback Close": "关闭反馈", "Feedback Failed": "提交反馈异常", diff --git a/client/src/components/Markdown/img/MermaidCodeBlock.tsx b/client/src/components/Markdown/img/MermaidCodeBlock.tsx index 4ade4670d..56e087f86 100644 --- a/client/src/components/Markdown/img/MermaidCodeBlock.tsx +++ b/client/src/components/Markdown/img/MermaidCodeBlock.tsx @@ -80,7 +80,7 @@ const MermaidBlock = ({ code }: { code: string }) => { ctx.fillRect(0, 0, w, h); const img = new Image(); - img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(ref.current.innerHTML)}`; + img.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(ref.current?.innerHTML)}`; img.onload = () => { ctx.drawImage(img, 0, 0, w, h); diff --git a/client/src/constants/flow/ModuleTemplate.ts b/client/src/constants/flow/ModuleTemplate.ts index 527faaf8f..baf7c83b2 100644 --- a/client/src/constants/flow/ModuleTemplate.ts +++ b/client/src/constants/flow/ModuleTemplate.ts @@ -20,7 +20,7 @@ import { ContextExtractEnum, HttpPropsEnum } from './flowField'; export const ChatModelSystemTip = '模型固定的引导词,通过调整该内容,可以引导模型聊天方向。该内容会被固定在上下文的开头。可使用变量,例如 {{language}}'; export const ChatModelLimitTip = - '限定模型对话范围,会被放置在本次提问前,拥有强引导和限定性。可使用变量,例如 {{language}}。引导例子:\n1. 知识库是关于 Laf 的介绍,参考知识库回答问题,与 "Laf" 无关内容,直接回复: "我不知道"。\n2. 你仅回答关于 "xxx" 的问题,其他问题回复: "xxxx"'; + '限定模型对话范围,会被放置在本次提问前,拥有强引导和限定性。不建议内容太长,会影响上下文,可使用变量,例如 {{language}}。可在文档中找到对应的限定例子'; export const userGuideTip = '可以添加特殊的对话前后引导模块,更好的让用户进行对话'; export const welcomeTextTip = '每次对话开始前,发送一个初始内容。支持标准 Markdown 语法,可使用的额外标记:\n[快捷按键]: 用户点击后可以直接发送该问题'; @@ -156,6 +156,7 @@ export const ChatModule: FlowModuleTemplateType = { key: 'systemPrompt', type: FlowInputItemTypeEnum.textarea, label: '系统提示词', + max: 300, valueType: FlowValueTypeEnum.string, description: ChatModelSystemTip, placeholder: ChatModelSystemTip, @@ -166,6 +167,7 @@ export const ChatModule: FlowModuleTemplateType = { type: FlowInputItemTypeEnum.textarea, valueType: FlowValueTypeEnum.string, label: '限定词', + max: 500, description: ChatModelLimitTip, placeholder: ChatModelLimitTip, value: '' @@ -175,6 +177,7 @@ export const ChatModule: FlowModuleTemplateType = { key: 'quoteQA', type: FlowInputItemTypeEnum.target, label: '引用内容', + description: "对象数组格式,结构:\n [{q:'问题',a:'回答'}]", valueType: FlowValueTypeEnum.kbQuote }, Input_Template_History, @@ -666,6 +669,7 @@ export const appTemplates: (AppItemType & { avatar: string; intro: string })[] = type: 'textarea', valueType: 'string', label: '限定词', + max: 500, description: '限定模型对话范围,会被放置在本次提问前,拥有强引导和限定性。可使用变量,例如 {{language}}。引导例子:\n1. 知识库是关于 Laf 的介绍,参考知识库回答问题,与 "Laf" 无关内容,直接回复: "我不知道"。\n2. 你仅回答关于 "xxx" 的问题,其他问题回复: "xxxx"', placeholder: diff --git a/client/src/pages/account/components/PayModal.tsx b/client/src/pages/account/components/PayModal.tsx index cd8ef9151..f39192999 100644 --- a/client/src/pages/account/components/PayModal.tsx +++ b/client/src/pages/account/components/PayModal.tsx @@ -104,7 +104,7 @@ const PayModal = ({ onClose }: { onClose: () => void }) => { | FastAI4k - 对话 | 0.015 | | FastAI16k - 对话 | 0.03 | | FastAI-Plus - 对话 | 0.45 | -| 文件拆分 | 0.03 |`} +| 文件QA拆分 | 0.03 |`} /> )} diff --git a/client/src/pages/chat/components/ChatHistorySlider.tsx b/client/src/pages/chat/components/ChatHistorySlider.tsx index f636d4b93..40fea4f74 100644 --- a/client/src/pages/chat/components/ChatHistorySlider.tsx +++ b/client/src/pages/chat/components/ChatHistorySlider.tsx @@ -67,13 +67,17 @@ const ChatHistorySlider = ({ const [currentTab, setCurrentTab] = useState<`${TabEnum}`>(TabEnum.history); + const isShare = useMemo(() => !appId || !userInfo, [appId, userInfo]); + // custom title edit const { onOpenModal, EditModal: EditTitleModal } = useEditInfo({ title: '自定义历史记录标题', placeholder: '如果设置为空,会自动跟随聊天记录。' }); const { openConfirm, ConfirmModal } = useConfirm({ - content: t('chat.Confirm to clear history') + content: isShare + ? t('chat.Confirm to clear share chat histroy') + : t('chat.Confirm to clear history') }); const concatHistory = useMemo( @@ -82,8 +86,6 @@ const ChatHistorySlider = ({ [activeChatId, history, t] ); - const isShare = useMemo(() => !appId || !userInfo, [appId, userInfo]); - useQuery(['init'], () => { if (isShare) { setCurrentTab(TabEnum.history); diff --git a/client/src/service/moduleDispatch/chat/oneapi.ts b/client/src/service/moduleDispatch/chat/oneapi.ts index e77943e50..083fdfc2d 100644 --- a/client/src/service/moduleDispatch/chat/oneapi.ts +++ b/client/src/service/moduleDispatch/chat/oneapi.ts @@ -237,25 +237,16 @@ function getChatMessages({ model: ChatModelItemType; hasQuoteOutput: boolean; }) { - const limitText = (() => { - if (!quotePrompt) { - return limitPrompt; - } - const defaultPrompt = `三引号引用的内容是我提供给你的知识,它们拥有最高优先级。instruction 是相关介绍${ - hasQuoteOutput ? ',output 是预期回答或补充' : '' - },使用引用内容来回答我下面的问题。`; - if (limitPrompt) { - return `${defaultPrompt}${limitPrompt}`; - } - return `${defaultPrompt}\n回答内容限制:你仅回答三引号中提及的内容,下面我提出的问题与引用内容无关时,你可以直接回复: "你的问题没有在知识库中体现"`; - })(); + const { quoteGuidePrompt } = getDefaultPrompt({ hasQuoteOutput }); + + const systemText = `${quotePrompt ? `${quoteGuidePrompt}\n\n` : ''}${systemPrompt}`; const messages: ChatItemType[] = [ - ...(systemPrompt + ...(systemText ? [ { obj: ChatRoleEnum.System, - value: systemPrompt + value: systemText } ] : []), @@ -268,11 +259,11 @@ function getChatMessages({ ] : []), ...history, - ...(limitText + ...(limitPrompt ? [ { obj: ChatRoleEnum.System, - value: limitText + value: limitPrompt } ] : []), @@ -385,3 +376,11 @@ async function streamResponse({ answer }; } + +function getDefaultPrompt({ hasQuoteOutput }: { hasQuoteOutput?: boolean }) { + return { + quoteGuidePrompt: `三引号引用的内容是我提供给你的知识库,它们拥有最高优先级。instruction 是相关介绍${ + hasQuoteOutput ? ',output 是预期回答或补充。' : '。' + }` + }; +} diff --git a/client/src/utils/app.ts b/client/src/utils/app.ts index c181d2a9c..db93510ea 100644 --- a/client/src/utils/app.ts +++ b/client/src/utils/app.ts @@ -36,7 +36,7 @@ export type EditFormType = { }; export const getDefaultAppForm = (): EditFormType => { const defaultChatModel = chatModelList[0]; - const defaultVectorModel = vectorModelList[0]; + return { chatModel: { model: defaultChatModel.model,