mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
Perf input guide (#1557)
* perf: input guide code * perf: input guide ui * Chat input guide api * Update app chat config store * perf: app chat config field * perf: app context * perf: params * fix: ts * perf: filter private config * perf: filter private config * perf: import workflow * perf: limit max tip amount
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AppWhisperConfigType } from './type';
|
||||
import { AppTTSConfigType, AppWhisperConfigType } from './type';
|
||||
|
||||
export enum AppTypeEnum {
|
||||
simple = 'simple',
|
||||
@@ -13,14 +13,16 @@ export const AppTypeMap = {
|
||||
}
|
||||
};
|
||||
|
||||
export const defaultTTSConfig: AppTTSConfigType = { type: 'web' };
|
||||
|
||||
export const defaultWhisperConfig: AppWhisperConfigType = {
|
||||
open: false,
|
||||
autoSend: false,
|
||||
autoTTSResponse: false
|
||||
};
|
||||
|
||||
export const defaultQuestionGuideTextConfig = {
|
||||
export const defaultChatInputGuideConfig = {
|
||||
open: false,
|
||||
textList: [],
|
||||
customURL: ''
|
||||
customUrl: ''
|
||||
};
|
||||
|
46
packages/global/core/app/type.d.ts
vendored
46
packages/global/core/app/type.d.ts
vendored
@@ -8,7 +8,7 @@ import { DatasetSearchModeEnum } from '../dataset/constants';
|
||||
import { TeamTagSchema as TeamTagsSchemaType } from '@fastgpt/global/support/user/team/type.d';
|
||||
import { StoreEdgeItemType } from '../workflow/type/edge';
|
||||
|
||||
export interface AppSchema {
|
||||
export type AppSchema = {
|
||||
_id: string;
|
||||
teamId: string;
|
||||
tmbId: string;
|
||||
@@ -23,13 +23,14 @@ export interface AppSchema {
|
||||
edges: StoreEdgeItemType[];
|
||||
|
||||
// App system config
|
||||
chatConfig: AppChatConfigType;
|
||||
scheduledTriggerConfig?: AppScheduledTriggerConfigType | null;
|
||||
scheduledTriggerNextTime?: Date;
|
||||
|
||||
permission: `${PermissionTypeEnum}`;
|
||||
inited?: boolean;
|
||||
teamTags: string[];
|
||||
}
|
||||
};
|
||||
|
||||
export type AppListItemType = {
|
||||
_id: string;
|
||||
@@ -66,33 +67,19 @@ export type AppSimpleEditFormType = {
|
||||
datasetSearchExtensionBg?: string;
|
||||
};
|
||||
selectedTools: FlowNodeTemplateType[];
|
||||
userGuide: {
|
||||
welcomeText: string;
|
||||
variables: {
|
||||
id: string;
|
||||
key: string;
|
||||
label: string;
|
||||
type: `${VariableInputEnum}`;
|
||||
required: boolean;
|
||||
maxLen: number;
|
||||
enums: {
|
||||
value: string;
|
||||
}[];
|
||||
}[];
|
||||
questionGuide: boolean;
|
||||
tts: {
|
||||
type: 'none' | 'web' | 'model';
|
||||
model?: string | undefined;
|
||||
voice?: string | undefined;
|
||||
speed?: number | undefined;
|
||||
};
|
||||
whisper: AppWhisperConfigType;
|
||||
scheduleTrigger: AppScheduledTriggerConfigType | null;
|
||||
questionGuideText: AppQuestionGuideTextConfigType;
|
||||
};
|
||||
chatConfig: AppChatConfigType;
|
||||
};
|
||||
|
||||
/* app function config */
|
||||
/* app chat config type */
|
||||
export type AppChatConfigType = {
|
||||
welcomeText?: string;
|
||||
variables?: VariableItemType[];
|
||||
questionGuide?: boolean;
|
||||
ttsConfig?: AppTTSConfigType;
|
||||
whisperConfig?: AppWhisperConfigType;
|
||||
scheduledTriggerConfig?: AppScheduledTriggerConfigType;
|
||||
chatInputGuide?: ChatInputGuideConfigType;
|
||||
};
|
||||
export type SettingAIDataType = {
|
||||
model: string;
|
||||
temperature: number;
|
||||
@@ -125,10 +112,9 @@ export type AppWhisperConfigType = {
|
||||
autoTTSResponse: boolean;
|
||||
};
|
||||
// question guide text
|
||||
export type AppQuestionGuideTextConfigType = {
|
||||
export type ChatInputGuideConfigType = {
|
||||
open: boolean;
|
||||
textList: string[];
|
||||
customURL: string;
|
||||
customUrl: string;
|
||||
};
|
||||
// interval timer
|
||||
export type AppScheduledTriggerConfigType = {
|
||||
|
@@ -1,50 +1,42 @@
|
||||
import type { AppSimpleEditFormType } from '../app/type';
|
||||
import type { AppChatConfigType, AppSimpleEditFormType } from '../app/type';
|
||||
import { FlowNodeTypeEnum } from '../workflow/node/constant';
|
||||
import { NodeInputKeyEnum, FlowNodeTemplateTypeEnum } from '../workflow/constants';
|
||||
import type { FlowNodeInputItemType } from '../workflow/type/io.d';
|
||||
import { getGuideModule, splitGuideModule } from '../workflow/utils';
|
||||
import { getAppChatConfig } from '../workflow/utils';
|
||||
import { StoreNodeItemType } from '../workflow/type';
|
||||
import { DatasetSearchModeEnum } from '../dataset/constants';
|
||||
import { defaultQuestionGuideTextConfig, defaultWhisperConfig } from './constants';
|
||||
|
||||
export const getDefaultAppForm = (): AppSimpleEditFormType => {
|
||||
return {
|
||||
aiSettings: {
|
||||
model: 'gpt-3.5-turbo',
|
||||
systemPrompt: '',
|
||||
temperature: 0,
|
||||
isResponseAnswerText: true,
|
||||
maxHistories: 6,
|
||||
maxToken: 4000
|
||||
},
|
||||
dataset: {
|
||||
datasets: [],
|
||||
similarity: 0.4,
|
||||
limit: 1500,
|
||||
searchMode: DatasetSearchModeEnum.embedding,
|
||||
usingReRank: false,
|
||||
datasetSearchUsingExtensionQuery: true,
|
||||
datasetSearchExtensionBg: ''
|
||||
},
|
||||
selectedTools: [],
|
||||
userGuide: {
|
||||
welcomeText: '',
|
||||
variables: [],
|
||||
questionGuide: false,
|
||||
tts: {
|
||||
type: 'web'
|
||||
},
|
||||
whisper: defaultWhisperConfig,
|
||||
scheduleTrigger: null,
|
||||
questionGuideText: defaultQuestionGuideTextConfig
|
||||
}
|
||||
};
|
||||
};
|
||||
export const getDefaultAppForm = (): AppSimpleEditFormType => ({
|
||||
aiSettings: {
|
||||
model: 'gpt-3.5-turbo',
|
||||
systemPrompt: '',
|
||||
temperature: 0,
|
||||
isResponseAnswerText: true,
|
||||
maxHistories: 6,
|
||||
maxToken: 4000
|
||||
},
|
||||
dataset: {
|
||||
datasets: [],
|
||||
similarity: 0.4,
|
||||
limit: 1500,
|
||||
searchMode: DatasetSearchModeEnum.embedding,
|
||||
usingReRank: false,
|
||||
datasetSearchUsingExtensionQuery: true,
|
||||
datasetSearchExtensionBg: ''
|
||||
},
|
||||
selectedTools: [],
|
||||
chatConfig: {}
|
||||
});
|
||||
|
||||
/* format app nodes to edit form */
|
||||
export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
|
||||
export const appWorkflow2Form = ({
|
||||
nodes,
|
||||
chatConfig
|
||||
}: {
|
||||
nodes: StoreNodeItemType[];
|
||||
chatConfig: AppChatConfigType;
|
||||
}) => {
|
||||
const defaultAppForm = getDefaultAppForm();
|
||||
|
||||
const findInputValueByKey = (inputs: FlowNodeInputItemType[], key: string) => {
|
||||
return inputs.find((item) => item.key === key)?.value;
|
||||
};
|
||||
@@ -103,26 +95,6 @@ export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
|
||||
node.inputs,
|
||||
NodeInputKeyEnum.datasetSearchExtensionBg
|
||||
);
|
||||
} else if (node.flowNodeType === FlowNodeTypeEnum.systemConfig) {
|
||||
const {
|
||||
welcomeText,
|
||||
variableNodes,
|
||||
questionGuide,
|
||||
ttsConfig,
|
||||
whisperConfig,
|
||||
scheduledTriggerConfig,
|
||||
questionGuideText
|
||||
} = splitGuideModule(getGuideModule(nodes));
|
||||
|
||||
defaultAppForm.userGuide = {
|
||||
welcomeText: welcomeText,
|
||||
variables: variableNodes,
|
||||
questionGuide: questionGuide,
|
||||
tts: ttsConfig,
|
||||
whisper: whisperConfig,
|
||||
scheduleTrigger: scheduledTriggerConfig,
|
||||
questionGuideText: questionGuideText
|
||||
};
|
||||
} else if (node.flowNodeType === FlowNodeTypeEnum.pluginModule) {
|
||||
if (!node.pluginId) return;
|
||||
|
||||
@@ -139,6 +111,12 @@ export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
|
||||
outputs: node.outputs,
|
||||
templateType: FlowNodeTemplateTypeEnum.other
|
||||
});
|
||||
} else if (node.flowNodeType === FlowNodeTypeEnum.systemConfig) {
|
||||
defaultAppForm.chatConfig = getAppChatConfig({
|
||||
chatConfig,
|
||||
systemConfigNode: node,
|
||||
isPublicFetch: true
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
2
packages/global/core/app/version.d.ts
vendored
2
packages/global/core/app/version.d.ts
vendored
@@ -1,5 +1,6 @@
|
||||
import { StoreNodeItemType } from '../workflow/type';
|
||||
import { StoreEdgeItemType } from '../workflow/type/edge';
|
||||
import { AppChatConfigType } from './type';
|
||||
|
||||
export type AppVersionSchemaType = {
|
||||
_id: string;
|
||||
@@ -7,4 +8,5 @@ export type AppVersionSchemaType = {
|
||||
time: Date;
|
||||
nodes: StoreNodeItemType[];
|
||||
edges: StoreEdgeItemType[];
|
||||
chatConfig: AppChatConfigType;
|
||||
};
|
||||
|
5
packages/global/core/chat/inputGuide/type.d.ts
vendored
Normal file
5
packages/global/core/chat/inputGuide/type.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export type ChatInputGuideSchemaType = {
|
||||
_id: string;
|
||||
appId: string;
|
||||
text: string;
|
||||
};
|
2
packages/global/core/chat/type.d.ts
vendored
2
packages/global/core/chat/type.d.ts
vendored
@@ -10,7 +10,7 @@ import {
|
||||
import { FlowNodeTypeEnum } from '../workflow/node/constant';
|
||||
import { NodeOutputKeyEnum } from '../workflow/constants';
|
||||
import { DispatchNodeResponseKeyEnum } from '../workflow/runtime/constants';
|
||||
import { AppSchema, VariableItemType } from '../app/type';
|
||||
import { AppChatConfigType, AppSchema, VariableItemType } from '../app/type';
|
||||
import type { AppSchema as AppType } from '@fastgpt/global/core/app/type.d';
|
||||
import { DatasetSearchModeEnum } from '../dataset/constants';
|
||||
import { ChatBoxInputType } from '../../../../projects/app/src/components/ChatBox/type';
|
||||
|
@@ -45,7 +45,7 @@ export enum NodeInputKeyEnum {
|
||||
whisper = 'whisper',
|
||||
variables = 'variables',
|
||||
scheduleTrigger = 'scheduleTrigger',
|
||||
questionGuideText = 'questionGuideText',
|
||||
chatInputGuide = 'chatInputGuide',
|
||||
|
||||
// entry
|
||||
userChatInput = 'userChatInput',
|
||||
|
@@ -1,33 +0,0 @@
|
||||
import { FlowNodeTemplateTypeEnum, WorkflowIOValueTypeEnum } from '../../constants';
|
||||
import { getHandleConfig } from '../utils';
|
||||
import { FlowNodeOutputTypeEnum, FlowNodeTypeEnum } from '../../node/constant';
|
||||
import { VariableItemType } from '../../../app/type';
|
||||
import { FlowNodeTemplateType } from '../../type';
|
||||
|
||||
export const getGlobalVariableNode = ({
|
||||
id,
|
||||
variables
|
||||
}: {
|
||||
id: string;
|
||||
variables: VariableItemType[];
|
||||
}): FlowNodeTemplateType => {
|
||||
return {
|
||||
id,
|
||||
templateType: FlowNodeTemplateTypeEnum.other,
|
||||
flowNodeType: FlowNodeTypeEnum.systemConfig,
|
||||
sourceHandle: getHandleConfig(true, true, true, true),
|
||||
targetHandle: getHandleConfig(true, true, true, true),
|
||||
avatar: '/imgs/workflow/variable.png',
|
||||
name: '全局变量',
|
||||
intro: '',
|
||||
version: '481',
|
||||
inputs: [],
|
||||
outputs: variables.map((item) => ({
|
||||
id: item.key,
|
||||
key: item.key,
|
||||
valueType: WorkflowIOValueTypeEnum.string,
|
||||
type: FlowNodeOutputTypeEnum.static,
|
||||
label: item.label
|
||||
}))
|
||||
};
|
||||
};
|
@@ -1,10 +1,6 @@
|
||||
import { FlowNodeInputTypeEnum, FlowNodeTypeEnum } from '../../node/constant';
|
||||
import { FlowNodeTypeEnum } from '../../node/constant';
|
||||
import { FlowNodeTemplateType } from '../../type/index.d';
|
||||
import {
|
||||
WorkflowIOValueTypeEnum,
|
||||
NodeInputKeyEnum,
|
||||
FlowNodeTemplateTypeEnum
|
||||
} from '../../constants';
|
||||
import { FlowNodeTemplateTypeEnum, WorkflowIOValueTypeEnum } from '../../constants';
|
||||
import { getHandleConfig } from '../utils';
|
||||
|
||||
export const SystemConfigNode: FlowNodeTemplateType = {
|
||||
@@ -19,50 +15,6 @@ export const SystemConfigNode: FlowNodeTemplateType = {
|
||||
unique: true,
|
||||
forbidDelete: true,
|
||||
version: '481',
|
||||
inputs: [
|
||||
{
|
||||
key: NodeInputKeyEnum.welcomeText,
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
valueType: WorkflowIOValueTypeEnum.string,
|
||||
label: 'core.app.Welcome Text'
|
||||
},
|
||||
{
|
||||
key: NodeInputKeyEnum.variables,
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
valueType: WorkflowIOValueTypeEnum.any,
|
||||
label: 'core.module.Variable',
|
||||
value: []
|
||||
},
|
||||
{
|
||||
key: NodeInputKeyEnum.questionGuide,
|
||||
valueType: WorkflowIOValueTypeEnum.boolean,
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
label: ''
|
||||
},
|
||||
{
|
||||
key: NodeInputKeyEnum.tts,
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
valueType: WorkflowIOValueTypeEnum.any,
|
||||
label: ''
|
||||
},
|
||||
{
|
||||
key: NodeInputKeyEnum.whisper,
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
valueType: WorkflowIOValueTypeEnum.any,
|
||||
label: ''
|
||||
},
|
||||
{
|
||||
key: NodeInputKeyEnum.scheduleTrigger,
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
valueType: WorkflowIOValueTypeEnum.any,
|
||||
label: ''
|
||||
},
|
||||
{
|
||||
key: NodeInputKeyEnum.questionGuideText,
|
||||
renderTypeList: [FlowNodeInputTypeEnum.hidden],
|
||||
valueType: WorkflowIOValueTypeEnum.any,
|
||||
label: ''
|
||||
}
|
||||
],
|
||||
inputs: [],
|
||||
outputs: []
|
||||
};
|
||||
|
@@ -12,10 +12,15 @@ import type {
|
||||
AppTTSConfigType,
|
||||
AppWhisperConfigType,
|
||||
AppScheduledTriggerConfigType,
|
||||
AppQuestionGuideTextConfigType
|
||||
ChatInputGuideConfigType,
|
||||
AppChatConfigType
|
||||
} from '../app/type';
|
||||
import { EditorVariablePickerType } from '../../../web/components/common/Textarea/PromptEditor/type';
|
||||
import { defaultWhisperConfig } from '../app/constants';
|
||||
import {
|
||||
defaultChatInputGuideConfig,
|
||||
defaultTTSConfig,
|
||||
defaultWhisperConfig
|
||||
} from '../app/constants';
|
||||
import { IfElseResultEnum } from './template/system/ifElse/constant';
|
||||
|
||||
export const getHandleId = (nodeId: string, type: 'source' | 'target', key: string) => {
|
||||
@@ -41,70 +46,81 @@ export const splitGuideModule = (guideModules?: StoreNodeItemType) => {
|
||||
const welcomeText: string =
|
||||
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.welcomeText)?.value || '';
|
||||
|
||||
const variableNodes: VariableItemType[] =
|
||||
const variables: VariableItemType[] =
|
||||
guideModules?.inputs.find((item) => item.key === NodeInputKeyEnum.variables)?.value || [];
|
||||
|
||||
const questionGuide: boolean =
|
||||
!!guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.questionGuide)?.value ||
|
||||
false;
|
||||
|
||||
const ttsConfig: AppTTSConfigType = guideModules?.inputs?.find(
|
||||
(item) => item.key === NodeInputKeyEnum.tts
|
||||
)?.value || { type: 'web' };
|
||||
const ttsConfig: AppTTSConfigType =
|
||||
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.tts)?.value ||
|
||||
defaultTTSConfig;
|
||||
|
||||
const whisperConfig: AppWhisperConfigType =
|
||||
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.whisper)?.value ||
|
||||
defaultWhisperConfig;
|
||||
|
||||
const scheduledTriggerConfig: AppScheduledTriggerConfigType | null =
|
||||
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.scheduleTrigger)?.value ??
|
||||
null;
|
||||
const scheduledTriggerConfig: AppScheduledTriggerConfigType = guideModules?.inputs?.find(
|
||||
(item) => item.key === NodeInputKeyEnum.scheduleTrigger
|
||||
)?.value;
|
||||
|
||||
const questionGuideText: AppQuestionGuideTextConfigType = guideModules?.inputs?.find(
|
||||
(item) => item.key === NodeInputKeyEnum.questionGuideText
|
||||
)?.value || {
|
||||
open: false
|
||||
};
|
||||
const chatInputGuide: ChatInputGuideConfigType =
|
||||
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.chatInputGuide)?.value ||
|
||||
defaultChatInputGuideConfig;
|
||||
|
||||
return {
|
||||
welcomeText,
|
||||
variableNodes,
|
||||
variables,
|
||||
questionGuide,
|
||||
ttsConfig,
|
||||
whisperConfig,
|
||||
scheduledTriggerConfig,
|
||||
questionGuideText
|
||||
chatInputGuide
|
||||
};
|
||||
};
|
||||
export const replaceAppChatConfig = ({
|
||||
node,
|
||||
variableList,
|
||||
welcomeText
|
||||
export const getAppChatConfig = ({
|
||||
chatConfig,
|
||||
systemConfigNode,
|
||||
storeVariables,
|
||||
storeWelcomeText,
|
||||
isPublicFetch = false
|
||||
}: {
|
||||
node?: StoreNodeItemType;
|
||||
variableList?: VariableItemType[];
|
||||
welcomeText?: string;
|
||||
}): StoreNodeItemType | undefined => {
|
||||
if (!node) return;
|
||||
return {
|
||||
...node,
|
||||
inputs: node.inputs.map((input) => {
|
||||
if (input.key === NodeInputKeyEnum.variables && variableList) {
|
||||
return {
|
||||
...input,
|
||||
value: variableList
|
||||
};
|
||||
}
|
||||
if (input.key === NodeInputKeyEnum.welcomeText && welcomeText) {
|
||||
return {
|
||||
...input,
|
||||
value: welcomeText
|
||||
};
|
||||
}
|
||||
chatConfig?: AppChatConfigType;
|
||||
systemConfigNode?: StoreNodeItemType;
|
||||
storeVariables?: VariableItemType[];
|
||||
storeWelcomeText?: string;
|
||||
isPublicFetch: boolean;
|
||||
}): AppChatConfigType => {
|
||||
const {
|
||||
welcomeText,
|
||||
variables,
|
||||
questionGuide,
|
||||
ttsConfig,
|
||||
whisperConfig,
|
||||
scheduledTriggerConfig,
|
||||
chatInputGuide
|
||||
} = splitGuideModule(systemConfigNode);
|
||||
|
||||
return input;
|
||||
})
|
||||
const config: AppChatConfigType = {
|
||||
questionGuide,
|
||||
ttsConfig,
|
||||
whisperConfig,
|
||||
scheduledTriggerConfig,
|
||||
chatInputGuide,
|
||||
...chatConfig,
|
||||
variables: storeVariables ?? chatConfig?.variables ?? variables,
|
||||
welcomeText: storeWelcomeText ?? chatConfig?.welcomeText ?? welcomeText
|
||||
};
|
||||
|
||||
if (!isPublicFetch) {
|
||||
if (config?.chatInputGuide?.customUrl) {
|
||||
config.chatInputGuide.customUrl = '';
|
||||
}
|
||||
config.scheduledTriggerConfig = undefined;
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
|
||||
export const getOrInitModuleInputValue = (input: FlowNodeInputItemType) => {
|
||||
|
Reference in New Issue
Block a user