Add question guide config (#3403)
* feat:Prompt task (#3337) * feat:猜你想问自定义功能 * 修改用户输入框部分,去除冗余代码 * 删除不必要的属性 * 删除多余内容 * 修正了格式问题,并实现获取调试和app最新参数 * 修正了几行代码 * feat:Prompt task (#3337) * feat:猜你想问自定义功能 * 修改用户输入框部分,去除冗余代码 * 删除不必要的属性 * 删除多余内容 * 修正了格式问题,并实现获取调试和app最新参数 * 修正了几行代码 * perf: question gudide code * fix: i18n * hunyuan logo * fix: cq templates * perf: create question guide code * udpate svg --------- Co-authored-by: Jiangween <145003935+Jiangween@users.noreply.github.com>
This commit is contained in:
@@ -8,15 +8,20 @@ import { NextAPI } from '@/service/middleware/entry';
|
||||
import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat';
|
||||
import { getChatItems } from '@fastgpt/service/core/chat/controller';
|
||||
import { chats2GPTMessages } from '@fastgpt/global/core/chat/adapt';
|
||||
import { getAppLatestVersion } from '@fastgpt/service/core/app/version/controller';
|
||||
|
||||
export type CreateQuestionGuideParams = OutLinkChatAuthProps & {
|
||||
appId: string;
|
||||
chatId: string;
|
||||
questionGuide?: {
|
||||
open: boolean;
|
||||
model?: string;
|
||||
customPrompt?: string;
|
||||
};
|
||||
};
|
||||
|
||||
async function handler(req: ApiRequestProps<CreateQuestionGuideParams>, res: NextApiResponse<any>) {
|
||||
const { appId, chatId } = req.body;
|
||||
|
||||
const { appId, chatId, questionGuide: inputQuestionGuide } = req.body;
|
||||
const [{ tmbId, teamId }] = await Promise.all([
|
||||
authChatCrud({
|
||||
req,
|
||||
@@ -27,6 +32,13 @@ async function handler(req: ApiRequestProps<CreateQuestionGuideParams>, res: Nex
|
||||
]);
|
||||
|
||||
// Auth app and get questionGuide config
|
||||
const questionGuide = await (async () => {
|
||||
if (inputQuestionGuide) {
|
||||
return inputQuestionGuide;
|
||||
}
|
||||
const { chatConfig } = await getAppLatestVersion(appId);
|
||||
return chatConfig.questionGuide;
|
||||
})();
|
||||
|
||||
// Get histories
|
||||
const { histories } = await getChatItems({
|
||||
@@ -38,15 +50,12 @@ async function handler(req: ApiRequestProps<CreateQuestionGuideParams>, res: Nex
|
||||
});
|
||||
const messages = chats2GPTMessages({ messages: histories, reserveId: false });
|
||||
|
||||
const qgModel = global.llmModels[0];
|
||||
const qgModel = questionGuide?.model || global.llmModels[0].model;
|
||||
|
||||
const { result, tokens } = await createQuestionGuide({
|
||||
messages,
|
||||
model: qgModel.model
|
||||
});
|
||||
|
||||
jsonRes(res, {
|
||||
data: result
|
||||
model: qgModel,
|
||||
customPrompt: questionGuide?.customPrompt
|
||||
});
|
||||
|
||||
pushQuestionGuideUsage({
|
||||
@@ -54,6 +63,8 @@ async function handler(req: ApiRequestProps<CreateQuestionGuideParams>, res: Nex
|
||||
teamId,
|
||||
tmbId
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
|
||||
@@ -40,7 +40,7 @@ const DatasetSelectModal = dynamic(() => import('@/components/core/app/DatasetSe
|
||||
const DatasetParamsModal = dynamic(() => import('@/components/core/app/DatasetParamsModal'));
|
||||
const ToolSelectModal = dynamic(() => import('./components/ToolSelectModal'));
|
||||
const TTSSelect = dynamic(() => import('@/components/core/app/TTSSelect'));
|
||||
const QGSwitch = dynamic(() => import('@/components/core/app/QGSwitch'));
|
||||
const QGConfig = dynamic(() => import('@/components/core/app/QGConfig'));
|
||||
const WhisperConfig = dynamic(() => import('@/components/core/app/WhisperConfig'));
|
||||
const InputGuideConfig = dynamic(() => import('@/components/core/app/InputGuideConfig'));
|
||||
const WelcomeTextConfig = dynamic(() => import('@/components/core/app/WelcomeTextConfig'));
|
||||
@@ -425,14 +425,14 @@ const EditForm = ({
|
||||
|
||||
{/* question guide */}
|
||||
<Box {...BoxStyles}>
|
||||
<QGSwitch
|
||||
isChecked={appForm.chatConfig.questionGuide}
|
||||
<QGConfig
|
||||
value={appForm.chatConfig.questionGuide}
|
||||
onChange={(e) => {
|
||||
setAppForm((state) => ({
|
||||
...state,
|
||||
chatConfig: {
|
||||
...state.chatConfig,
|
||||
questionGuide: e.target.checked
|
||||
questionGuide: e
|
||||
}
|
||||
}));
|
||||
}}
|
||||
|
||||
@@ -30,7 +30,7 @@ export const compareSimpleAppSnapshot = (
|
||||
{
|
||||
welcomeText: appForm1.chatConfig?.welcomeText || '',
|
||||
variables: appForm1.chatConfig?.variables || [],
|
||||
questionGuide: appForm1.chatConfig?.questionGuide || false,
|
||||
questionGuide: appForm1.chatConfig?.questionGuide || undefined,
|
||||
ttsConfig: appForm1.chatConfig?.ttsConfig || undefined,
|
||||
whisperConfig: appForm1.chatConfig?.whisperConfig || undefined,
|
||||
chatInputGuide: appForm1.chatConfig?.chatInputGuide || undefined,
|
||||
@@ -39,7 +39,7 @@ export const compareSimpleAppSnapshot = (
|
||||
{
|
||||
welcomeText: appForm2.chatConfig?.welcomeText || '',
|
||||
variables: appForm2.chatConfig?.variables || [],
|
||||
questionGuide: appForm2.chatConfig?.questionGuide || false,
|
||||
questionGuide: appForm2.chatConfig?.questionGuide || undefined,
|
||||
ttsConfig: appForm2.chatConfig?.ttsConfig || undefined,
|
||||
whisperConfig: appForm2.chatConfig?.whisperConfig || undefined,
|
||||
chatInputGuide: appForm2.chatConfig?.chatInputGuide || undefined,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { NodeProps } from 'reactflow';
|
||||
import { Box } from '@chakra-ui/react';
|
||||
import { FlowNodeItemType } from '@fastgpt/global/core/workflow/type/node.d';
|
||||
|
||||
import QGSwitch from '@/components/core/app/QGSwitch';
|
||||
import QGConfig from '@/components/core/app/QGConfig';
|
||||
import TTSSelect from '@/components/core/app/TTSSelect';
|
||||
import WhisperConfig from '@/components/core/app/WhisperConfig';
|
||||
import InputGuideConfig from '@/components/core/app/InputGuideConfig';
|
||||
@@ -13,7 +13,12 @@ import NodeCard from './render/NodeCard';
|
||||
import ScheduledTriggerConfig from '@/components/core/app/ScheduledTriggerConfig';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { WorkflowContext } from '../../context';
|
||||
import { AppChatConfigType, AppDetailType, VariableItemType } from '@fastgpt/global/core/app/type';
|
||||
import {
|
||||
AppChatConfigType,
|
||||
AppDetailType,
|
||||
AppQGConfigType,
|
||||
VariableItemType
|
||||
} from '@fastgpt/global/core/app/type';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
import VariableEdit from '@/components/core/app/VariableEdit';
|
||||
import { AppContext } from '@/pages/app/detail/components/context';
|
||||
@@ -149,17 +154,16 @@ function AutoExecute({ chatConfig: { autoExecute }, setAppDetail }: ComponentPro
|
||||
);
|
||||
}
|
||||
|
||||
function QuestionGuide({ chatConfig: { questionGuide = false }, setAppDetail }: ComponentProps) {
|
||||
function QuestionGuide({ chatConfig: { questionGuide }, setAppDetail }: ComponentProps) {
|
||||
return (
|
||||
<QGSwitch
|
||||
isChecked={questionGuide}
|
||||
<QGConfig
|
||||
value={questionGuide}
|
||||
onChange={(e) => {
|
||||
const value = e.target.checked;
|
||||
setAppDetail((state) => ({
|
||||
...state,
|
||||
chatConfig: {
|
||||
...state.chatConfig,
|
||||
questionGuide: value
|
||||
questionGuide: e
|
||||
}
|
||||
}));
|
||||
}}
|
||||
|
||||
@@ -142,7 +142,7 @@ export const AiPointsTable = () => {
|
||||
{whisperModel?.charsPointsPrice +
|
||||
t('common:support.wallet.subscription.point') +
|
||||
' / 60' +
|
||||
t('common:unit.minute')}
|
||||
t('common:unit.seconds')}
|
||||
</Box>
|
||||
</Flex>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user