Optimize the project structure and introduce DDD design (#394)

This commit is contained in:
Archer
2023-10-12 17:46:37 +08:00
committed by GitHub
parent 76ac5238b6
commit ad7a17bf40
193 changed files with 1169 additions and 1084 deletions

View File

@@ -7,6 +7,9 @@ export enum SystemInputEnum {
'userChatInput' = 'userChatInput',
'questionGuide' = 'questionGuide'
}
export enum SystemOutputEnum {
finish = 'finish'
}
export enum VariableInputEnum {
input = 'input',

View File

@@ -9,13 +9,14 @@ import {
} from './index';
import type { AppItemType } from '@/types/app';
import type { FlowModuleTemplateType } from '@/types/core/app/flow';
import { chatModelList } from '@/store/static';
import { chatModelList } from '@/web/common/store/static';
import {
Input_Template_History,
Input_Template_TFSwitch,
Input_Template_UserChatInput
} from './inputTemplate';
import { ContextExtractEnum, HttpPropsEnum } from './flowField';
import { Output_Template_Finish } from './outputTemplate';
export const ChatModelSystemTip =
'模型固定的引导词,通过调整该内容,可以引导模型聊天方向。该内容会被固定在上下文的开头。可使用变量,例如 {{language}}';
@@ -130,12 +131,15 @@ export const ChatModule: FlowModuleTemplateType = {
intro: 'AI 大模型对话',
showStatus: true,
inputs: [
Input_Template_TFSwitch,
{
key: 'model',
type: FlowInputItemTypeEnum.custom,
type: FlowInputItemTypeEnum.selectChatModel,
label: '对话模型',
value: chatModelList[0]?.model,
list: chatModelList.map((item) => ({ label: item.name, value: item.model }))
list: chatModelList.map((item) => ({ label: item.name, value: item.model })),
required: true,
valueCheck: (val) => !!val
},
{
key: 'temperature',
@@ -152,7 +156,7 @@ export const ChatModule: FlowModuleTemplateType = {
},
{
key: 'maxToken',
type: FlowInputItemTypeEnum.custom,
type: FlowInputItemTypeEnum.maxToken,
label: '回复上限',
value: chatModelList[0] ? chatModelList[0].contextMaxToken / 2 : 2000,
min: 100,
@@ -190,10 +194,9 @@ export const ChatModule: FlowModuleTemplateType = {
valueType: FlowValueTypeEnum.string,
value: ''
},
Input_Template_TFSwitch,
{
key: 'quoteQA',
type: FlowInputItemTypeEnum.custom,
type: FlowInputItemTypeEnum.quoteList,
label: '引用内容',
description: "对象数组格式,结构:\n [{q:'问题',a:'回答'}]",
valueType: FlowValueTypeEnum.kbQuote,
@@ -219,14 +222,7 @@ export const ChatModule: FlowModuleTemplateType = {
type: FlowOutputItemTypeEnum.source,
targets: []
},
{
key: 'finish',
label: '回复结束',
description: 'AI 回复完成后触发',
valueType: FlowValueTypeEnum.boolean,
type: FlowOutputItemTypeEnum.source,
targets: []
}
Output_Template_Finish
]
};
@@ -237,12 +233,15 @@ export const KBSearchModule: FlowModuleTemplateType = {
intro: '去知识库中搜索对应的答案。可作为 AI 对话引用参考。',
showStatus: true,
inputs: [
Input_Template_TFSwitch,
{
key: 'kbList',
type: FlowInputItemTypeEnum.custom,
type: FlowInputItemTypeEnum.selectDataset,
label: '关联的知识库',
value: [],
list: []
list: [],
required: true,
valueCheck: (val) => !!val.length
},
{
key: 'similarity',
@@ -271,7 +270,6 @@ export const KBSearchModule: FlowModuleTemplateType = {
{ label: '20', value: 20 }
]
},
Input_Template_TFSwitch,
Input_Template_UserChatInput
],
outputs: [
@@ -297,7 +295,8 @@ export const KBSearchModule: FlowModuleTemplateType = {
type: FlowOutputItemTypeEnum.source,
valueType: FlowValueTypeEnum.kbQuote,
targets: []
}
},
Output_Template_Finish
]
};
@@ -312,23 +311,14 @@ export const AnswerModule: FlowModuleTemplateType = {
{
key: SpecialInputKeyEnum.answerText,
type: FlowInputItemTypeEnum.textarea,
valueType: FlowValueTypeEnum.string,
valueType: FlowValueTypeEnum.any,
value: '',
label: '回复的内容',
description:
'可以使用 \\n 来实现连续换行。\n\n可以通过外部模块输入实现回复外部模块输入时会覆盖当前填写的内容'
'可以使用 \\n 来实现连续换行。\n\n可以通过外部模块输入实现回复外部模块输入时会覆盖当前填写的内容。\n\n如传入非字符串类型数据将会自动转成字符串'
}
],
outputs: [
{
key: 'finish',
label: '回复结束',
description: '回复完成后触发',
valueType: FlowValueTypeEnum.boolean,
type: FlowOutputItemTypeEnum.source,
targets: []
}
]
outputs: [Output_Template_Finish]
};
export const ClassifyQuestionModule: FlowModuleTemplateType = {
flowType: FlowModuleTypeEnum.classifyQuestion,
@@ -461,6 +451,7 @@ export const HttpModule: FlowModuleTemplateType = {
description: '可以发出一个 HTTP POST 请求,实现更为复杂的操作(联网搜索、数据库查询等)',
showStatus: true,
inputs: [
Input_Template_TFSwitch,
{
key: HttpPropsEnum.url,
value: '',
@@ -468,19 +459,11 @@ export const HttpModule: FlowModuleTemplateType = {
label: '请求地址',
description: '请求目标地址',
placeholder: 'https://api.fastgpt.run/getInventory',
required: true
},
Input_Template_TFSwitch
],
outputs: [
{
key: HttpPropsEnum.finish,
label: '请求结束',
valueType: FlowValueTypeEnum.boolean,
type: FlowOutputItemTypeEnum.source,
targets: []
required: true,
valueCheck: (val) => !!val
}
]
],
outputs: [Output_Template_Finish]
};
export const EmptyModule: FlowModuleTemplateType = {
flowType: FlowModuleTypeEnum.empty,
@@ -527,13 +510,7 @@ export const AppModule: FlowModuleTemplateType = {
type: FlowOutputItemTypeEnum.source,
targets: []
},
{
key: 'finish',
label: '请求结束',
valueType: FlowValueTypeEnum.boolean,
type: FlowOutputItemTypeEnum.source,
targets: []
}
Output_Template_Finish
]
};

View File

@@ -8,17 +8,21 @@ export enum FlowInputItemTypeEnum {
select = 'select',
slider = 'slider',
custom = 'custom',
target = 'target',
none = 'none',
target = 'target', // data input
switch = 'switch',
hidden = 'hidden',
selectApp = 'selectApp'
selectApp = 'selectApp',
// chat special input
quoteList = 'quoteList',
maxToken = 'maxToken',
selectChatModel = 'selectChatModel',
// dataset special input
selectDataset = 'selectDataset',
hidden = 'hidden'
}
export enum FlowOutputItemTypeEnum {
answer = 'answer',
source = 'source',
none = 'none',
hidden = 'hidden'
}

View File

@@ -0,0 +1,12 @@
import type { FlowOutputItemType } from '@/types/core/app/flow';
import { SystemOutputEnum } from '../app';
import { FlowOutputItemTypeEnum, FlowValueTypeEnum } from './index';
export const Output_Template_Finish: FlowOutputItemType = {
key: SystemOutputEnum.finish,
label: '模块调用结束',
description: '模块调用结束时触发',
valueType: FlowValueTypeEnum.boolean,
type: FlowOutputItemTypeEnum.source,
targets: []
};

View File

@@ -1,302 +0,0 @@
import { extendTheme, defineStyleConfig, ComponentStyleConfig } from '@chakra-ui/react';
import { modalAnatomy, switchAnatomy, selectAnatomy, numberInputAnatomy } from '@chakra-ui/anatomy';
import { createMultiStyleConfigHelpers } from '@chakra-ui/styled-system';
const { definePartsStyle, defineMultiStyleConfig } = createMultiStyleConfigHelpers(
modalAnatomy.keys
);
const { definePartsStyle: switchPart, defineMultiStyleConfig: switchMultiStyle } =
createMultiStyleConfigHelpers(switchAnatomy.keys);
const { definePartsStyle: selectPart, defineMultiStyleConfig: selectMultiStyle } =
createMultiStyleConfigHelpers(selectAnatomy.keys);
const { definePartsStyle: numInputPart, defineMultiStyleConfig: numInputMultiStyle } =
createMultiStyleConfigHelpers(numberInputAnatomy.keys);
// 按键
const Button = defineStyleConfig({
baseStyle: {
_active: {
transform: 'scale(0.98)'
}
},
sizes: {
xs: {
fontSize: 'xs',
px: 3,
py: 0,
fontWeight: 'normal',
height: '22px',
borderRadius: '2px'
},
sm: {
fontSize: 'sm',
px: 4,
py: 0,
fontWeight: 'normal',
height: '26px',
borderRadius: '2px'
},
md: {
fontSize: 'md',
px: 6,
py: 0,
height: '32px',
fontWeight: 'normal',
borderRadius: '4px'
},
lg: {
fontSize: 'lg',
px: 8,
py: 0,
height: '42px',
fontWeight: 'normal',
borderRadius: '8px'
}
},
variants: {
primary: {
backgroundImage:
'linear-gradient(to bottom right, #2152d9 0%,#3370ff 40%, #4e83fd 100%) !important',
color: 'white',
border: 'none',
_hover: {
filter: 'brightness(115%)'
},
_disabled: {
bg: '#3370ff !important'
}
},
base: {
color: 'myGray.900',
border: '1px solid',
borderColor: 'myGray.200',
bg: 'transparent',
transition: 'background 0.3s',
_hover: {
color: 'myBlue.600',
bg: 'myWhite.400'
},
_active: {
color: 'myBlue.700'
},
_disabled: { bg: 'myGray.100 !important', color: 'myGray.700 !important' }
}
},
defaultProps: {
size: 'md',
variant: 'primary'
}
});
const Input: ComponentStyleConfig = {
baseStyle: {},
variants: {
outline: {
field: {
backgroundColor: 'transparent',
border: '1px solid',
borderRadius: 'base',
borderColor: 'myGray.200',
_focus: {
borderColor: 'myBlue.600',
boxShadow: '0px 0px 4px #A8DBFF',
bg: 'white'
},
_disabled: {
color: 'myGray.400',
bg: 'myWhite.300'
}
}
}
},
defaultProps: {
size: 'md',
variant: 'outline'
}
};
const NumberInput = numInputMultiStyle({
variants: {
outline: numInputPart({
field: {
bg: 'myWhite.300',
border: '1px solid',
borderRadius: 'base',
borderColor: 'myGray.200',
_focus: {
borderColor: 'myBlue.600 !important',
boxShadow: '0px 0px 4px #A8DBFF !important',
bg: 'transparent'
},
_disabled: {
color: 'myGray.400 !important',
bg: 'myWhite.300 !important'
}
},
stepper: {
bg: 'transparent',
border: 'none',
color: 'myGray.600',
_active: {
color: 'myBlue.600'
}
}
})
},
defaultProps: {
variant: 'outline'
}
});
const Textarea: ComponentStyleConfig = {
variants: {
outline: {
border: '1px solid',
borderRadius: 'base',
borderColor: 'myGray.200',
_hover: {
borderColor: ''
},
_focus: {
borderColor: 'myBlue.600',
boxShadow: '0px 0px 4px #A8DBFF',
bg: 'white'
}
}
},
defaultProps: {
size: 'md',
variant: 'outline'
}
};
const Switch = switchMultiStyle({
baseStyle: switchPart({
track: {
bg: 'myGray.100',
_checked: {
bg: 'myBlue.700'
}
}
})
});
const Select = selectMultiStyle({
variants: {
outline: selectPart({
field: {
borderColor: 'myGray.100',
_focusWithin: {
boxShadow: '0px 0px 4px #A8DBFF',
borderColor: 'myBlue.600'
}
}
})
}
});
// 全局主题
export const theme = extendTheme({
styles: {
global: {
'html, body': {
color: 'myGray.900',
fontSize: 'md',
fontWeight: 400,
height: '100%',
overflow: 'hidden'
},
a: {
color: 'myBlue.700'
}
}
},
colors: {
myWhite: {
100: '#FEFEFE',
200: '#FDFDFE',
300: '#FBFBFC',
400: '#F8FAFB',
500: '#F6F8F9',
600: '#F4F6F8',
700: '#C3C5C6',
800: '#929495',
900: '#626263',
1000: '#313132'
},
myGray: {
100: '#EFF0F1',
200: '#DEE0E2',
300: '#BDC1C5',
400: '#9CA2A8',
500: '#7B838B',
600: '#5A646E',
700: '#485058',
800: '#363C42',
900: '#24282C',
1000: '#121416'
},
myBlue: {
100: '#f0f7ff',
200: '#EBF7FD',
300: '#d6e8ff',
400: '#adceff',
500: '#85b1ff',
600: '#4e83fd',
700: '#3370ff',
800: '#2152d9',
900: '#1237b3',
1000: '#07228c'
},
myRead: {
600: '#ff4d4f'
}
},
fonts: {
body: '-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"'
},
fontSizes: {
xs: '10px',
sm: '12px',
md: '14px',
lg: '16px',
xl: '16px',
'2xl': '18px',
'3xl': '20px'
},
borders: {
sm: '1px solid #EFF0F1',
base: '1px solid #DEE0E2',
md: '1px solid #DAE0E2',
lg: '1px solid #D0E0E2'
},
shadows: {
sm: '0 0 5px rgba(0,0,0,0.1)',
md: '0 0 8px rgba(0,0,0,0.1)',
base: '0 0 10px rgba(0,0,0,0.15)',
lg: '0 0 10px rgba(0,0,0,0.2)'
},
breakpoints: {
sm: '900px',
md: '1200px',
lg: '1500px',
xl: '1800px',
'2xl': '2100px'
},
lgColor: {
activeBlueGradient: 'linear-gradient(to bottom right, #d6e8ff 0%, #f0f7ff 100%)',
hoverBlueGradient: 'linear-gradient(to top left, #d6e8ff 0%, #f0f7ff 100%)',
primary: 'linear-gradient(to bottom right, #2152d9 0%,#3370ff 40%, #4e83fd 100%)',
primary2: 'linear-gradient(to bottom right, #2152d9 0%,#3370ff 30%,#4e83fd 80%, #85b1ff 100%)'
},
components: {
Button,
Input,
Textarea,
Switch,
Select,
NumberInput
}
});