From a3c4a856fa5ef3b1337ffb3c36f50fd8c1f97a53 Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Wed, 23 Aug 2023 16:20:53 +0800 Subject: [PATCH] perf: default prompt --- client/src/pages/_app.tsx | 3 +- client/src/pages/account/index.tsx | 16 +++------ .../src/service/moduleDispatch/chat/oneapi.ts | 36 +++++++++---------- docSite/README.md | 3 ++ 4 files changed, 27 insertions(+), 31 deletions(-) create mode 100644 docSite/README.md diff --git a/client/src/pages/_app.tsx b/client/src/pages/_app.tsx index 7fe3d1812..c51694ed3 100644 --- a/client/src/pages/_app.tsx +++ b/client/src/pages/_app.tsx @@ -10,7 +10,7 @@ import NProgress from 'nprogress'; //nprogress module import Router from 'next/router'; import { clientInitData, feConfigs } from '@/store/static'; import { appWithTranslation, useTranslation } from 'next-i18next'; -import { getLangStore } from '@/utils/i18n'; +import { getLangStore, setLangStore } from '@/utils/i18n'; import { useRouter } from 'next/router'; import 'nprogress/nprogress.css'; @@ -58,6 +58,7 @@ function App({ Component, pageProps }: AppProps) { useEffect(() => { const lang = getLangStore() || 'zh'; i18n?.changeLanguage?.(lang); + setLangStore(lang); }, [router.asPath]); return ( diff --git a/client/src/pages/account/index.tsx b/client/src/pages/account/index.tsx index d15e4b71a..d46dd0d21 100644 --- a/client/src/pages/account/index.tsx +++ b/client/src/pages/account/index.tsx @@ -14,18 +14,10 @@ import { serviceSideProps } from '@/utils/i18n'; import { feConfigs } from '@/store/static'; import { useTranslation } from 'react-i18next'; -const Promotion = dynamic(() => import('./components/Promotion'), { - ssr: false -}); -const BillTable = dynamic(() => import('./components/BillTable'), { - ssr: false -}); -const PayRecordTable = dynamic(() => import('./components/PayRecordTable'), { - ssr: false -}); -const InformTable = dynamic(() => import('./components/InformTable'), { - ssr: false -}); +const Promotion = dynamic(() => import('./components/Promotion')); +const BillTable = dynamic(() => import('./components/BillTable')); +const PayRecordTable = dynamic(() => import('./components/PayRecordTable')); +const InformTable = dynamic(() => import('./components/InformTable')); enum TabEnum { 'info' = 'info', diff --git a/client/src/service/moduleDispatch/chat/oneapi.ts b/client/src/service/moduleDispatch/chat/oneapi.ts index 3a7fcb6d1..a7d6a1fea 100644 --- a/client/src/service/moduleDispatch/chat/oneapi.ts +++ b/client/src/service/moduleDispatch/chat/oneapi.ts @@ -201,7 +201,7 @@ function filterQuote({ maxToken: model.quoteMaxToken, messages: quoteQA.map((item) => ({ obj: ChatRoleEnum.System, - value: item.a ? `{user:${item.q},assistant:${item.a}}` : `{instruction:${item.q}}` + value: item.a ? `${item.q}\n${item.a}` : item.q })) }); @@ -210,11 +210,9 @@ function filterQuote({ const quotePrompt = filterQuoteQA.length > 0 - ? `${filterQuoteQA - .map((item) => - item.a ? `{user:${item.q},assistant:${item.a}}` : `{instruction:${item.q}}` - ) - .join('\n')}` + ? `"""${filterQuoteQA + .map((item) => (item.a ? `${item.q}\n${item.a}` : item.q)) + .join('\n\n')}"""` : ''; return { @@ -238,22 +236,15 @@ function getChatMessages({ model: ChatModelItemType; }) { const limitText = (() => { - if (limitPrompt) return limitPrompt; + if (limitPrompt) + return `Use the provided content delimited by triple quotes to answer questions.${limitPrompt}`; if (quotePrompt && !limitPrompt) { - return '根据我上文提供的内容回答下面问题,不要进行额外补充。'; + return `Use the provided content delimited by triple quotes to answer questions.Your task is to answer the question using only the provided conetnt and to cite the passage(s) of the conetnt used to answer the question. If the conetnt does not contain the information needed to answer this question then simply write: "你的问题没有在知识库中体现".`; } - return ''; + return ``; })(); const messages: ChatItemType[] = [ - ...(quotePrompt - ? [ - { - obj: ChatRoleEnum.System, - value: quotePrompt - } - ] - : []), ...(systemPrompt ? [ { @@ -262,7 +253,14 @@ function getChatMessages({ } ] : []), - ...history, + ...(quotePrompt + ? [ + { + obj: ChatRoleEnum.System, + value: quotePrompt + } + ] + : []), ...(limitText ? [ { @@ -271,6 +269,7 @@ function getChatMessages({ } ] : []), + ...history, { obj: ChatRoleEnum.Human, value: userChatInput @@ -301,6 +300,7 @@ function getMaxTokens({ }) { const tokensLimit = model.contextMaxToken; /* count response max token */ + const promptsToken = modelToolMap.countTokens({ model: model.model, messages: filterMessages diff --git a/docSite/README.md b/docSite/README.md new file mode 100644 index 000000000..77fba8ae0 --- /dev/null +++ b/docSite/README.md @@ -0,0 +1,3 @@ +# 文档 + +## 本地运行