Commit a3c4a856 by archer

perf: default prompt

parent 6c70f060
...@@ -10,7 +10,7 @@ import NProgress from 'nprogress'; //nprogress module ...@@ -10,7 +10,7 @@ import NProgress from 'nprogress'; //nprogress module
import Router from 'next/router'; import Router from 'next/router';
import { clientInitData, feConfigs } from '@/store/static'; import { clientInitData, feConfigs } from '@/store/static';
import { appWithTranslation, useTranslation } from 'next-i18next'; import { appWithTranslation, useTranslation } from 'next-i18next';
import { getLangStore } from '@/utils/i18n'; import { getLangStore, setLangStore } from '@/utils/i18n';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import 'nprogress/nprogress.css'; import 'nprogress/nprogress.css';
...@@ -58,6 +58,7 @@ function App({ Component, pageProps }: AppProps) { ...@@ -58,6 +58,7 @@ function App({ Component, pageProps }: AppProps) {
useEffect(() => { useEffect(() => {
const lang = getLangStore() || 'zh'; const lang = getLangStore() || 'zh';
i18n?.changeLanguage?.(lang); i18n?.changeLanguage?.(lang);
setLangStore(lang);
}, [router.asPath]); }, [router.asPath]);
return ( return (
......
...@@ -14,18 +14,10 @@ import { serviceSideProps } from '@/utils/i18n'; ...@@ -14,18 +14,10 @@ import { serviceSideProps } from '@/utils/i18n';
import { feConfigs } from '@/store/static'; import { feConfigs } from '@/store/static';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
const Promotion = dynamic(() => import('./components/Promotion'), { const Promotion = dynamic(() => import('./components/Promotion'));
ssr: false const BillTable = dynamic(() => import('./components/BillTable'));
}); const PayRecordTable = dynamic(() => import('./components/PayRecordTable'));
const BillTable = dynamic(() => import('./components/BillTable'), { const InformTable = dynamic(() => import('./components/InformTable'));
ssr: false
});
const PayRecordTable = dynamic(() => import('./components/PayRecordTable'), {
ssr: false
});
const InformTable = dynamic(() => import('./components/InformTable'), {
ssr: false
});
enum TabEnum { enum TabEnum {
'info' = 'info', 'info' = 'info',
......
...@@ -201,7 +201,7 @@ function filterQuote({ ...@@ -201,7 +201,7 @@ function filterQuote({
maxToken: model.quoteMaxToken, maxToken: model.quoteMaxToken,
messages: quoteQA.map((item) => ({ messages: quoteQA.map((item) => ({
obj: ChatRoleEnum.System, 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({ ...@@ -210,11 +210,9 @@ function filterQuote({
const quotePrompt = const quotePrompt =
filterQuoteQA.length > 0 filterQuoteQA.length > 0
? `${filterQuoteQA ? `"""${filterQuoteQA
.map((item) => .map((item) => (item.a ? `${item.q}\n${item.a}` : item.q))
item.a ? `{user:${item.q},assistant:${item.a}}` : `{instruction:${item.q}}` .join('\n\n')}"""`
)
.join('\n')}`
: ''; : '';
return { return {
...@@ -238,31 +236,31 @@ function getChatMessages({ ...@@ -238,31 +236,31 @@ function getChatMessages({
model: ChatModelItemType; model: ChatModelItemType;
}) { }) {
const limitText = (() => { const limitText = (() => {
if (limitPrompt) return limitPrompt; if (limitPrompt)
return `Use the provided content delimited by triple quotes to answer questions.${limitPrompt}`;
if (quotePrompt && !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[] = [ const messages: ChatItemType[] = [
...(quotePrompt ...(systemPrompt
? [ ? [
{ {
obj: ChatRoleEnum.System, obj: ChatRoleEnum.System,
value: quotePrompt value: systemPrompt
} }
] ]
: []), : []),
...(systemPrompt ...(quotePrompt
? [ ? [
{ {
obj: ChatRoleEnum.System, obj: ChatRoleEnum.System,
value: systemPrompt value: quotePrompt
} }
] ]
: []), : []),
...history,
...(limitText ...(limitText
? [ ? [
{ {
...@@ -271,6 +269,7 @@ function getChatMessages({ ...@@ -271,6 +269,7 @@ function getChatMessages({
} }
] ]
: []), : []),
...history,
{ {
obj: ChatRoleEnum.Human, obj: ChatRoleEnum.Human,
value: userChatInput value: userChatInput
...@@ -301,6 +300,7 @@ function getMaxTokens({ ...@@ -301,6 +300,7 @@ function getMaxTokens({
}) { }) {
const tokensLimit = model.contextMaxToken; const tokensLimit = model.contextMaxToken;
/* count response max token */ /* count response max token */
const promptsToken = modelToolMap.countTokens({ const promptsToken = modelToolMap.countTokens({
model: model.model, model: model.model,
messages: filterMessages messages: filterMessages
......
# 文档
## 本地运行
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment