Skip to content

Commit

Permalink
tool box ui (labring#52)
Browse files Browse the repository at this point in the history
* fix: training queue

* feat: simple edit tool select

* perf: simple edit dataset prompt

* fix: chatbox tool ux

* feat: quote prompt module

* perf: plugin tools sign

* perf: model avatar

* tool selector ui

* feat: max histories
  • Loading branch information
c121914yu committed Mar 20, 2024
1 parent 9c6b4b2 commit 17922ee
Show file tree
Hide file tree
Showing 62 changed files with 1,444 additions and 584 deletions.
1 change: 1 addition & 0 deletions packages/global/common/system/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const HUMAN_ICON = `/icon/human.svg`;
export const LOGO_ICON = `/icon/logo.svg`;
export const HUGGING_FACE_ICON = `/imgs/model/huggingface.svg`;
2 changes: 2 additions & 0 deletions packages/global/core/ai/model.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type LLMModelItemType = {
model: string;
name: string;
avatar?: string;
maxContext: number;
maxResponse: number;
quoteMaxToken: number;
Expand Down Expand Up @@ -31,6 +32,7 @@ export type LLMModelItemType = {
export type VectorModelItemType = {
model: string;
name: string;
avatar?: string;
defaultToken: number;
charsPointsPrice: number;
maxToken: number;
Expand Down
12 changes: 8 additions & 4 deletions packages/global/core/app/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { AppTTSConfigType, ModuleItemType, VariableItemType } from '../module/type.d';
import type {
AppTTSConfigType,
FlowNodeTemplateType,
ModuleItemType,
VariableItemType
} from '../module/type.d';
import { AppTypeEnum } from './constants';
import { PermissionTypeEnum } from '../../support/permission/constant';
import type { DatasetModuleProps } from '../module/node/type.d';
Expand Down Expand Up @@ -44,20 +49,19 @@ export type AppSimpleEditFormType = {
temperature: number;
maxToken: number;
isResponseAnswerText: boolean;
quoteTemplate?: string | undefined;
quotePrompt?: string | undefined;
maxHistories: number;
};
dataset: {
datasets: SelectedDatasetType;
searchMode: `${DatasetSearchModeEnum}`;
similarity?: number;
limit?: number;
usingReRank?: boolean;
searchEmptyText?: string;
datasetSearchUsingExtensionQuery?: boolean;
datasetSearchExtensionModel?: string;
datasetSearchExtensionBg?: string;
};
selectedTools: FlowNodeTemplateType[];
userGuide: {
welcomeText: string;
variables: {
Expand Down
42 changes: 21 additions & 21 deletions packages/global/core/app/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { AppSimpleEditFormType } from '../app/type';
import { FlowNodeTypeEnum } from '../module/node/constant';
import { ModuleOutputKeyEnum, ModuleInputKeyEnum } from '../module/constants';
import {
ModuleOutputKeyEnum,
ModuleInputKeyEnum,
FlowNodeTemplateTypeEnum
} from '../module/constants';
import type { FlowNodeInputItemType } from '../module/node/type.d';
import { getGuideModule, splitGuideModule } from '../module/utils';
import { ModuleItemType } from '../module/type.d';
Expand All @@ -13,20 +17,19 @@ export const getDefaultAppForm = (): AppSimpleEditFormType => {
systemPrompt: '',
temperature: 0,
isResponseAnswerText: true,
quotePrompt: '',
quoteTemplate: '',
maxHistories: 6,
maxToken: 4000
},
dataset: {
datasets: [],
similarity: 0.4,
limit: 1500,
searchEmptyText: '',
searchMode: DatasetSearchModeEnum.embedding,
usingReRank: false,
datasetSearchUsingExtensionQuery: true,
datasetSearchExtensionBg: ''
},
selectedTools: [],
userGuide: {
welcomeText: '',
variables: [],
Expand Down Expand Up @@ -67,13 +70,9 @@ export const appModules2Form = ({ modules }: { modules: ModuleItemType[] }) => {
module.inputs,
ModuleInputKeyEnum.aiChatMaxToken
);
defaultAppForm.aiSettings.quoteTemplate = findInputValueByKey(
defaultAppForm.aiSettings.maxHistories = findInputValueByKey(
module.inputs,
ModuleInputKeyEnum.aiChatQuoteTemplate
);
defaultAppForm.aiSettings.quotePrompt = findInputValueByKey(
module.inputs,
ModuleInputKeyEnum.aiChatQuotePrompt
ModuleInputKeyEnum.history
);
} else if (module.flowType === FlowNodeTypeEnum.datasetSearchNode) {
defaultAppForm.dataset.datasets = findInputValueByKey(
Expand Down Expand Up @@ -107,17 +106,6 @@ export const appModules2Form = ({ modules }: { modules: ModuleItemType[] }) => {
module.inputs,
ModuleInputKeyEnum.datasetSearchExtensionBg
);

// empty text
const emptyOutputs =
module.outputs.find((item) => item.key === ModuleOutputKeyEnum.datasetIsEmpty)?.targets ||
[];
const emptyOutput = emptyOutputs[0];
if (emptyOutput) {
const target = modules.find((item) => item.moduleId === emptyOutput.moduleId);
defaultAppForm.dataset.searchEmptyText =
target?.inputs?.find((item) => item.key === ModuleInputKeyEnum.answerText)?.value || '';
}
} else if (module.flowType === FlowNodeTypeEnum.userGuide) {
const { welcomeText, variableModules, questionGuide, ttsConfig } = splitGuideModule(
getGuideModule(modules)
Expand All @@ -128,6 +116,18 @@ export const appModules2Form = ({ modules }: { modules: ModuleItemType[] }) => {
questionGuide: questionGuide,
tts: ttsConfig
};
} else if (module.flowType === FlowNodeTypeEnum.pluginModule) {
defaultAppForm.selectedTools.push({
id: module.inputs.find((input) => input.key === ModuleInputKeyEnum.pluginId)?.value || '',
name: module.name,
avatar: module.avatar,
intro: module.intro || '',
flowType: module.flowType,
showStatus: module.showStatus,
inputs: module.inputs,
outputs: module.outputs,
templateType: FlowNodeTemplateTypeEnum.other
});
}
});

Expand Down
1 change: 1 addition & 0 deletions packages/global/core/module/node/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum FlowNodeInputTypeEnum {
// dataset special input
selectDataset = 'selectDataset',
selectDatasetParamsModal = 'selectDatasetParamsModal',
settingDatasetQuotePrompt = 'settingDatasetQuotePrompt',

hidden = 'hidden',
custom = 'custom'
Expand Down
1 change: 1 addition & 0 deletions packages/global/core/module/node/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export type SettingAIDataType = {
temperature: number;
maxToken: number;
isResponseAnswerText?: boolean;
maxHistories?: number;
};
/* ai chat modules props */
export type AIChatModuleProps = {
Expand Down
2 changes: 1 addition & 1 deletion packages/global/core/module/template/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const Input_Template_System_Prompt: FlowNodeInputItemType = {

export const Input_Template_Dataset_Quote: FlowNodeInputItemType = {
key: ModuleInputKeyEnum.aiChatDatasetQuote,
type: FlowNodeInputTypeEnum.target,
type: FlowNodeInputTypeEnum.settingDatasetQuotePrompt,
label: '知识库引用',
description: 'core.module.Dataset quote.Input description',
valueType: ModuleIOValueTypeEnum.datasetQuote,
Expand Down
1 change: 1 addition & 0 deletions packages/global/core/plugin/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ export type PluginRuntimeType = {
name: string;
avatar: string;
showStatus?: boolean;
isTool?: boolean;
modules: ModuleItemType[];
};
12 changes: 6 additions & 6 deletions packages/service/core/dataset/search/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ export async function searchDatasetData(props: SearchDatasetDataProps) {
const countRecallLimit = () => {
if (searchMode === DatasetSearchModeEnum.embedding) {
return {
embeddingLimit: 100,
embeddingLimit: 150,
fullTextLimit: 0
};
}
if (searchMode === DatasetSearchModeEnum.fullTextRecall) {
return {
embeddingLimit: 0,
fullTextLimit: 100
fullTextLimit: 150
};
}
return {
embeddingLimit: 60,
fullTextLimit: 40
embeddingLimit: 100,
fullTextLimit: 80
};
};
const embeddingRecall = async ({ query, limit }: { query: string; limit: number }) => {
Expand Down Expand Up @@ -357,8 +357,8 @@ export async function searchDatasetData(props: SearchDatasetDataProps) {
// embedding recall and fullText recall rrf concat
const rrfConcatResults = datasetSearchResultConcat([
{ k: 60, list: embeddingRecallResults },
{ k: 64, list: fullTextRecallResults },
{ k: 60, list: reRankResults }
{ k: 60, list: fullTextRecallResults },
{ k: 58, list: reRankResults }
]);

// remove same q and a data
Expand Down
14 changes: 6 additions & 8 deletions packages/service/core/dataset/training/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,26 @@ export async function pushDataListToTrainingQueue({
data,
prompt,
billId,
trainingMode = TrainingModeEnum.chunk,

vectorModelList = [],
datasetModelList = []
trainingMode = TrainingModeEnum.chunk
}: {
teamId: string;
tmbId: string;
vectorModelList: VectorModelItemType[];
datasetModelList: LLMModelItemType[];
} & PushDatasetDataProps): Promise<PushDatasetDataResponse> {
const vectorModelList = global.vectorModels;
const datasetModelList = global.llmModels;

const {
datasetId: { _id: datasetId, vectorModel, agentModel }
} = await getCollectionWithDataset(collectionId);

const checkModelValid = async () => {
const agentModelData = datasetModelList?.find((item) => item.model === agentModel);
if (!agentModelData) {
return Promise.reject(`Vector model ${agentModel} is inValid`);
return Promise.reject(`File model ${agentModel} is inValid`);
}
const vectorModelData = vectorModelList?.find((item) => item.model === vectorModel);
if (!vectorModelData) {
return Promise.reject(`File model ${vectorModel} is inValid`);
return Promise.reject(`Vector model ${vectorModel} is inValid`);
}

if (trainingMode === TrainingModeEnum.chunk) {
Expand Down
1 change: 1 addition & 0 deletions packages/service/core/plugin/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function getPluginPreviewModule({
name: plugin.name,
intro: plugin.intro,
showStatus: plugin.showStatus,
isTool: plugin.isTool,
...plugin2ModuleIO(plugin.id, plugin.modules)
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/web/components/common/Icon/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const iconPaths = {
'core/app/simpleMode/template': () => import('./icons/core/app/simpleMode/template.svg'),
'core/app/simpleMode/tts': () => import('./icons/core/app/simpleMode/tts.svg'),
'core/app/simpleMode/variable': () => import('./icons/core/app/simpleMode/variable.svg'),
'core/app/toolCall': () => import('./icons/core/app/toolCall.svg'),
'core/app/ttsFill': () => import('./icons/core/app/ttsFill.svg'),
'core/app/variable/external': () => import('./icons/core/app/variable/external.svg'),
'core/app/variable/input': () => import('./icons/core/app/variable/input.svg'),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions packages/web/components/common/Icon/icons/core/app/toolCall.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/web/components/common/MySelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ const MySelect = (
: `${width} !important`;
})()}
w={'auto'}
p={'6px'}
px={'6px'}
py={'6px'}
border={'1px solid #fff'}
boxShadow={
'0px 2px 4px rgba(161, 167, 179, 0.25), 0px 0px 1px rgba(121, 141, 159, 0.25);'
Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/common/Tabs/RowTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Props = BoxProps & {
onChange: (e: string) => void;
};

const RowTabs = ({ list, value, onChange, py = '7px', ...props }: Props) => {
const RowTabs = ({ list, value, onChange, py = '7px', px = '12px', ...props }: Props) => {
return (
<Box
display={'inline-flex'}
Expand All @@ -32,7 +32,7 @@ const RowTabs = ({ list, value, onChange, py = '7px', ...props }: Props) => {
alignItems={'center'}
cursor={'pointer'}
borderRadius={'md'}
px={'12px'}
px={px}
py={py}
userSelect={'none'}
whiteSpace={'noWrap'}
Expand Down
12 changes: 6 additions & 6 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "@fastgpt/web",
"version": "1.0.0",
"dependencies": {
"@chakra-ui/anatomy": "^2.2.1",
"@chakra-ui/icons": "^2.1.1",
"@chakra-ui/next-js": "^2.1.5",
"@chakra-ui/react": "^2.8.1",
"@chakra-ui/styled-system": "^2.9.1",
"@chakra-ui/system": "^2.6.1",
"@chakra-ui/anatomy": "2.2.1",
"@chakra-ui/icons": "2.1.1",
"@chakra-ui/next-js": "2.1.5",
"@chakra-ui/react": "2.8.1",
"@chakra-ui/styled-system": "2.9.1",
"@chakra-ui/system": "2.6.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fastgpt/global": "workspace:*",
Expand Down
12 changes: 12 additions & 0 deletions packages/web/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ const Button = defineStyleConfig({
_disabled: {
bg: 'myGray.50'
}
},
grayDanger: {
bg: 'myGray.150',
color: 'myGray.900',
_hover: {
color: 'red.600',
background: 'red.1',
borderColor: 'red.300'
},
_active: {
color: 'red.600'
}
}
},
defaultProps: {
Expand Down
Loading

0 comments on commit 17922ee

Please sign in to comment.