mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
feat: dataset quote role support system; fix: adapt o1 model (#2733)
* feat: dataset quote support system role * perf: adapt dataset quote role * fix: adapt o1 model
This commit is contained in:
@@ -30,7 +30,8 @@
|
||||
"customCQPrompt": "", // 自定义文本分类提示词(不支持工具和函数调用的模型
|
||||
"customExtractPrompt": "", // 自定义内容提取提示词
|
||||
"defaultSystemChatPrompt": "", // 对话默认携带的系统提示词
|
||||
"defaultConfig": {} // 请求API时,挟带一些默认配置(比如 GLM4 的 top_p)
|
||||
"defaultConfig": {}, // 请求API时,挟带一些默认配置(比如 GLM4 的 top_p)
|
||||
"fieldMap": {} // 字段映射(o1 模型需要把 max_tokens 映射为 max_completion_tokens)
|
||||
},
|
||||
{
|
||||
"model": "gpt-4o",
|
||||
@@ -53,7 +54,8 @@
|
||||
"customCQPrompt": "",
|
||||
"customExtractPrompt": "",
|
||||
"defaultSystemChatPrompt": "",
|
||||
"defaultConfig": {}
|
||||
"defaultConfig": {},
|
||||
"fieldMap": {}
|
||||
},
|
||||
{
|
||||
"model": "o1-mini",
|
||||
@@ -78,8 +80,10 @@
|
||||
"defaultSystemChatPrompt": "",
|
||||
"defaultConfig": {
|
||||
"temperature": 1,
|
||||
"max_tokens": null,
|
||||
"stream": false
|
||||
},
|
||||
"fieldMap": {
|
||||
"max_tokens": "max_completion_tokens"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -105,8 +109,10 @@
|
||||
"defaultSystemChatPrompt": "",
|
||||
"defaultConfig": {
|
||||
"temperature": 1,
|
||||
"max_tokens": null,
|
||||
"stream": false
|
||||
},
|
||||
"fieldMap": {
|
||||
"max_tokens": "max_completion_tokens"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
module.exports = {
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
defaultLocale: 'zh',
|
||||
locales: ['en', 'zh'],
|
||||
localeDetection: false
|
||||
},
|
||||
|
@@ -8,8 +8,9 @@ import { useTranslation } from 'next-i18next';
|
||||
import { ModalBody } from '@chakra-ui/react';
|
||||
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
|
||||
import {
|
||||
Prompt_QuotePromptList,
|
||||
Prompt_QuoteTemplateList
|
||||
Prompt_userQuotePromptList,
|
||||
Prompt_QuoteTemplateList,
|
||||
Prompt_systemQuotePromptList
|
||||
} from '@fastgpt/global/core/ai/prompt/AIChat';
|
||||
import PromptEditor from '@fastgpt/web/components/common/Textarea/PromptEditor';
|
||||
import PromptTemplate from '@/components/PromptTemplate';
|
||||
@@ -25,6 +26,14 @@ import { AppContext } from '@/pages/app/detail/components/context';
|
||||
import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip';
|
||||
import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel';
|
||||
import { datasetQuoteValueDesc } from '@fastgpt/global/core/workflow/node/constant';
|
||||
import type { AiChatQuoteRoleType } from '@fastgpt/global/core/workflow/template/system/aiChat/type';
|
||||
import {
|
||||
AiChatQuotePrompt,
|
||||
AiChatQuoteRole,
|
||||
AiChatQuoteTemplate
|
||||
} from '@fastgpt/global/core/workflow/template/system/aiChat';
|
||||
import MySelect from '@fastgpt/web/components/common/MySelect';
|
||||
import LightTip from '@fastgpt/web/components/common/LightTip';
|
||||
|
||||
const LabelStyles: BoxProps = {
|
||||
fontSize: ['sm', 'md']
|
||||
@@ -43,12 +52,17 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
|
||||
const { watch, setValue, handleSubmit } = useForm({
|
||||
defaultValues: {
|
||||
quoteTemplate: inputs.find((input) => input.key === 'quoteTemplate')?.value || '',
|
||||
quotePrompt: inputs.find((input) => input.key === 'quotePrompt')?.value || ''
|
||||
quoteTemplate:
|
||||
inputs.find((input) => input.key === NodeInputKeyEnum.aiChatQuoteTemplate)?.value || '',
|
||||
quotePrompt:
|
||||
inputs.find((input) => input.key === NodeInputKeyEnum.aiChatQuotePrompt)?.value || '',
|
||||
quoteRole: (inputs.find((input) => input.key === NodeInputKeyEnum.aiChatQuoteRole)?.value ||
|
||||
'system') as AiChatQuoteRoleType
|
||||
}
|
||||
});
|
||||
const aiChatQuoteTemplate = watch('quoteTemplate');
|
||||
const aiChatQuotePrompt = watch('quotePrompt');
|
||||
const aiChatQuoteRole = watch('quoteRole');
|
||||
const { appDetail } = useContextSelector(AppContext, (v) => v);
|
||||
|
||||
const variables = useCreation(() => {
|
||||
@@ -102,51 +116,58 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
label: t('common:core.app.Quote templates'),
|
||||
icon: 'core/app/simpleMode/variable'
|
||||
},
|
||||
{
|
||||
key: 'question',
|
||||
label: t('common:core.module.input.label.user question'),
|
||||
icon: 'core/app/simpleMode/variable'
|
||||
},
|
||||
...(aiChatQuoteRole === 'user'
|
||||
? [
|
||||
{
|
||||
key: 'question',
|
||||
label: t('common:core.module.input.label.user question'),
|
||||
icon: 'core/app/simpleMode/variable'
|
||||
}
|
||||
]
|
||||
: []),
|
||||
...variables
|
||||
],
|
||||
[t, variables]
|
||||
[t, variables, aiChatQuoteRole]
|
||||
);
|
||||
|
||||
const onSubmit = useCallback(
|
||||
(data: { quoteTemplate: string; quotePrompt: string }) => {
|
||||
const quoteTemplateInput = inputs.find(
|
||||
(input) => input.key === NodeInputKeyEnum.aiChatQuoteTemplate
|
||||
);
|
||||
const quotePromptInput = inputs.find(
|
||||
(input) => input.key === NodeInputKeyEnum.aiChatQuotePrompt
|
||||
);
|
||||
if (quoteTemplateInput) {
|
||||
onChangeNode({
|
||||
nodeId,
|
||||
type: 'updateInput',
|
||||
key: quoteTemplateInput.key,
|
||||
value: {
|
||||
...quoteTemplateInput,
|
||||
value: data.quoteTemplate
|
||||
}
|
||||
});
|
||||
}
|
||||
if (quotePromptInput) {
|
||||
onChangeNode({
|
||||
nodeId,
|
||||
type: 'updateInput',
|
||||
key: quotePromptInput.key,
|
||||
value: {
|
||||
...quotePromptInput,
|
||||
value: data.quotePrompt
|
||||
}
|
||||
});
|
||||
}
|
||||
(data: { quoteTemplate: string; quotePrompt: string; quoteRole: AiChatQuoteRoleType }) => {
|
||||
onChangeNode({
|
||||
nodeId,
|
||||
type: 'replaceInput',
|
||||
key: NodeInputKeyEnum.aiChatQuoteRole,
|
||||
value: {
|
||||
...AiChatQuoteRole,
|
||||
value: data.quoteRole || 'system'
|
||||
}
|
||||
});
|
||||
onChangeNode({
|
||||
nodeId,
|
||||
type: 'replaceInput',
|
||||
key: NodeInputKeyEnum.aiChatQuoteTemplate,
|
||||
value: {
|
||||
...AiChatQuoteTemplate,
|
||||
value: data.quoteTemplate
|
||||
}
|
||||
});
|
||||
onChangeNode({
|
||||
nodeId,
|
||||
type: 'replaceInput',
|
||||
key: NodeInputKeyEnum.aiChatQuotePrompt,
|
||||
value: {
|
||||
...AiChatQuotePrompt,
|
||||
value: data.quotePrompt
|
||||
}
|
||||
});
|
||||
|
||||
onClose();
|
||||
},
|
||||
[inputs, nodeId, onChangeNode, onClose]
|
||||
[nodeId, onChangeNode, onClose]
|
||||
);
|
||||
|
||||
const quotePromptTemplates =
|
||||
aiChatQuoteRole === 'user' ? Prompt_userQuotePromptList : Prompt_systemQuotePromptList;
|
||||
|
||||
const Render = useMemo(() => {
|
||||
return (
|
||||
<>
|
||||
@@ -176,16 +197,48 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
<MyModal
|
||||
isOpen={isOpen}
|
||||
iconSrc={'modal/edit'}
|
||||
title={t('common:core.module.Quote prompt setting')}
|
||||
w={'600px'}
|
||||
title={t('workflow:Quote_prompt_setting')}
|
||||
w={'100%'}
|
||||
h={['90vh', '85vh']}
|
||||
maxW={['90vw', '700px']}
|
||||
isCentered
|
||||
>
|
||||
<ModalBody>
|
||||
<Box>
|
||||
<ModalBody flex={'1 0 0'} overflow={'auto'}>
|
||||
<Flex {...LabelStyles} alignItems={'center'}>
|
||||
<FormLabel>{t('workflow:dataset_quote_role')}</FormLabel>
|
||||
<QuestionTip label={t('workflow:dataset_quote_role_tip')} ml={1} mr={5} />
|
||||
<MySelect<AiChatQuoteRoleType>
|
||||
value={aiChatQuoteRole}
|
||||
list={[
|
||||
{
|
||||
label: 'System',
|
||||
value: 'system',
|
||||
description: t('workflow:dataset_quote_role_system_option_desc')
|
||||
},
|
||||
{
|
||||
label: 'User',
|
||||
value: 'user',
|
||||
description: t('workflow:dataset_quote_role_user_option_desc')
|
||||
}
|
||||
]}
|
||||
onchange={(e) => {
|
||||
setValue('quoteRole', e);
|
||||
}}
|
||||
/>
|
||||
<Box ml={5}>
|
||||
{aiChatQuoteRole === 'user' ? (
|
||||
<LightTip text={t('workflow:quote_role_user_tip')} />
|
||||
) : (
|
||||
<LightTip text={t('workflow:quote_role_system_tip')} />
|
||||
)}
|
||||
</Box>
|
||||
</Flex>
|
||||
<Box mt={4}>
|
||||
<Flex {...LabelStyles} mb={1}>
|
||||
<FormLabel>{t('common:core.app.Quote templates')}</FormLabel>
|
||||
<QuestionTip
|
||||
ml={1}
|
||||
label={t('template.Quote Content Tip', {
|
||||
label={t('workflow:quote_content_tip', {
|
||||
default: Prompt_QuoteTemplateList[0].value
|
||||
})}
|
||||
></QuestionTip>
|
||||
@@ -208,9 +261,7 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
variables={quoteTemplateVariables}
|
||||
h={160}
|
||||
title={t('common:core.app.Quote templates')}
|
||||
placeholder={t('template.Quote Content Tip', {
|
||||
default: Prompt_QuoteTemplateList[0].value
|
||||
})}
|
||||
placeholder={t('workflow:quote_content_placeholder')}
|
||||
value={aiChatQuoteTemplate}
|
||||
onChange={(e) => {
|
||||
setValue('quoteTemplate', e);
|
||||
@@ -222,17 +273,17 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
<FormLabel>{t('common:core.app.Quote prompt')}</FormLabel>
|
||||
<QuestionTip
|
||||
ml={1}
|
||||
label={t('template.Quote Prompt Tip', {
|
||||
default: Prompt_QuotePromptList[0].value
|
||||
label={t('workflow:quote_prompt_tip', {
|
||||
default: quotePromptTemplates[0].value
|
||||
})}
|
||||
></QuestionTip>
|
||||
</Flex>
|
||||
<PromptEditor
|
||||
variables={quotePromptVariables}
|
||||
title={t('common:core.app.Quote prompt')}
|
||||
h={280}
|
||||
placeholder={t('template.Quote Prompt Tip', {
|
||||
default: Prompt_QuotePromptList[0].value
|
||||
h={300}
|
||||
placeholder={t('workflow:quote_prompt_tip', {
|
||||
default: quotePromptTemplates[0].value
|
||||
})}
|
||||
value={aiChatQuotePrompt}
|
||||
onChange={(e) => {
|
||||
@@ -248,6 +299,7 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
<Button onClick={handleSubmit(onSubmit)}>{t('common:common.Confirm')}</Button>
|
||||
</ModalFooter>
|
||||
</MyModal>
|
||||
{/* Prompt template */}
|
||||
{!!selectTemplateData && (
|
||||
<PromptTemplate
|
||||
title={selectTemplateData.title}
|
||||
@@ -255,9 +307,9 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
onClose={() => setSelectTemplateData(undefined)}
|
||||
onSuccess={(e) => {
|
||||
const quoteVal = e.value;
|
||||
const promptVal = Prompt_QuotePromptList.find(
|
||||
(item) => item.title === e.title
|
||||
)?.value;
|
||||
|
||||
const promptVal = quotePromptTemplates.find((item) => item.title === e.title)?.value;
|
||||
|
||||
setValue('quoteTemplate', quoteVal);
|
||||
setValue('quotePrompt', promptVal);
|
||||
}}
|
||||
@@ -267,6 +319,7 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
);
|
||||
}, [
|
||||
aiChatQuotePrompt,
|
||||
aiChatQuoteRole,
|
||||
aiChatQuoteTemplate,
|
||||
handleSubmit,
|
||||
isOpen,
|
||||
@@ -274,6 +327,7 @@ const SettingQuotePrompt = (props: RenderInputProps) => {
|
||||
onOpen,
|
||||
onSubmit,
|
||||
props,
|
||||
quotePromptTemplates,
|
||||
quotePromptVariables,
|
||||
quoteTemplateVariables,
|
||||
selectTemplateData,
|
||||
|
@@ -208,8 +208,8 @@ const InputDataModal = ({
|
||||
},
|
||||
errorToast: t('common:common.error.unKnow')
|
||||
});
|
||||
// update
|
||||
|
||||
// update
|
||||
const { runAsync: onUpdateData, loading: isUpdating } = useRequest2(
|
||||
async (e: InputDataType) => {
|
||||
if (!dataId) return Promise.reject(t('common:common.error.unKnow'));
|
||||
|
@@ -15,6 +15,7 @@ import { addMinutes } from 'date-fns';
|
||||
import { countGptMessagesTokens } from '@fastgpt/service/common/string/tiktoken/index';
|
||||
import { pushDataListToTrainingQueueByCollectionId } from '@fastgpt/service/core/dataset/training/controller';
|
||||
import { loadRequestMessages } from '@fastgpt/service/core/chat/utils';
|
||||
import { llmCompletionsBodyFormat } from '@fastgpt/service/core/ai/utils';
|
||||
|
||||
const reduceQueue = () => {
|
||||
global.qaQueueLen = global.qaQueueLen > 0 ? global.qaQueueLen - 1 : 0;
|
||||
@@ -111,13 +112,17 @@ ${replaceVariable(Prompt_AgentQA.fixedText, { text })}`;
|
||||
const ai = getAIApi({
|
||||
timeout: 600000
|
||||
});
|
||||
const chatResponse = await ai.chat.completions.create({
|
||||
model: modelData.model,
|
||||
temperature: 0.3,
|
||||
messages: await loadRequestMessages({ messages, useVision: false }),
|
||||
stream: false,
|
||||
...modelData.defaultConfig
|
||||
});
|
||||
const chatResponse = await ai.chat.completions.create(
|
||||
llmCompletionsBodyFormat(
|
||||
{
|
||||
model: modelData.model,
|
||||
temperature: 0.3,
|
||||
messages: await loadRequestMessages({ messages, useVision: false }),
|
||||
stream: false
|
||||
},
|
||||
modelData
|
||||
)
|
||||
);
|
||||
const answer = chatResponse.choices?.[0].message?.content || '';
|
||||
|
||||
const qaArr = formatSplitText(answer, text); // 格式化后的QA对
|
||||
|
@@ -22,7 +22,12 @@ import {
|
||||
userFilesInput
|
||||
} from '@fastgpt/global/core/workflow/template/system/workflowStart';
|
||||
import { SystemConfigNode } from '@fastgpt/global/core/workflow/template/system/systemConfig';
|
||||
import { AiChatModule } from '@fastgpt/global/core/workflow/template/system/aiChat';
|
||||
import {
|
||||
AiChatModule,
|
||||
AiChatQuotePrompt,
|
||||
AiChatQuoteRole,
|
||||
AiChatQuoteTemplate
|
||||
} from '@fastgpt/global/core/workflow/template/system/aiChat/index';
|
||||
import { DatasetSearchModule } from '@fastgpt/global/core/workflow/template/system/datasetSearch';
|
||||
import { ReadFilesNodes } from '@fastgpt/global/core/workflow/template/system/readFiles';
|
||||
import { i18nT } from '@fastgpt/web/i18n/utils';
|
||||
@@ -126,18 +131,9 @@ export function form2AppWorkflow(
|
||||
value: true,
|
||||
valueType: WorkflowIOValueTypeEnum.boolean
|
||||
},
|
||||
{
|
||||
key: 'quoteTemplate',
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
label: '',
|
||||
valueType: WorkflowIOValueTypeEnum.string
|
||||
},
|
||||
{
|
||||
key: 'quotePrompt',
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
label: '',
|
||||
valueType: WorkflowIOValueTypeEnum.string
|
||||
},
|
||||
AiChatQuoteRole,
|
||||
AiChatQuoteTemplate,
|
||||
AiChatQuotePrompt,
|
||||
{
|
||||
key: 'systemPrompt',
|
||||
renderTypeList: [FlowNodeInputTypeEnum.textarea, FlowNodeInputTypeEnum.reference],
|
||||
|
Reference in New Issue
Block a user