Skip to content

Commit fb368a5

Browse files
authored
Perf input guide (labring#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
1 parent 8e8ceb7 commit fb368a5

File tree

123 files changed

+2126
-1807
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+2126
-1807
lines changed

.vscode/i18n-ally-custom-framework.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ usageMatchRegex:
2525
- "[^\\w\\d]publishT\\(['\"`]({key})['\"`]"
2626
- "[^\\w\\d]workflowT\\(['\"`]({key})['\"`]"
2727
- "[^\\w\\d]userT\\(['\"`]({key})['\"`]"
28+
- "[^\\w\\d]chatT\\(['\"`]({key})['\"`]"
2829

2930
# A RegEx to set a custom scope range. This scope will be used as a prefix when detecting keys
3031
# and works like how the i18next framework identifies the namespace scope from the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "对话问题引导"
3+
description: "FastGPT 对话问题引导"
4+
icon: "code"
5+
draft: false
6+
toc: true
7+
weight: 350
8+
---
9+
10+
![](/imgs/questionGuide.png)
11+
12+
## 什么是自定义问题引导
13+
14+
你可以为你的应用提前预设一些问题,用户在输入时,会根据输入的内容,动态搜索这些问题作为提示,从而引导用户更快的进行提问。
15+
16+
你可以直接在 FastGPT 中配置词库,或者提供自定义词库接口。
17+
18+
## 自定义词库接口
19+
20+
**请求:**
21+
22+
```bash
23+
curl --location --request GET 'http://localhost:3000/api/core/chat/inputGuide/query?appId=663c75302caf8315b1c00194&searchKey=你'
24+
```
25+
26+
**响应**
27+
28+
```json
29+
{
30+
"code": 200,
31+
"statusText": "",
32+
"message": "",
33+
"data": [
34+
"是你",
35+
"你是谁呀",
36+
"你好好呀",
37+
"你好呀",
38+
"你是谁!",
39+
"你好"
40+
]
41+
}
42+
```
43+
44+
45+
**参数说明:**
46+
47+
- appId - 应用ID
48+
- searchKey - 搜索关键字

docSite/content/docs/course/custom_link.md

-43
This file was deleted.

packages/global/core/app/constants.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AppWhisperConfigType } from './type';
1+
import { AppTTSConfigType, AppWhisperConfigType } from './type';
22

33
export enum AppTypeEnum {
44
simple = 'simple',
@@ -13,14 +13,16 @@ export const AppTypeMap = {
1313
}
1414
};
1515

16+
export const defaultTTSConfig: AppTTSConfigType = { type: 'web' };
17+
1618
export const defaultWhisperConfig: AppWhisperConfigType = {
1719
open: false,
1820
autoSend: false,
1921
autoTTSResponse: false
2022
};
2123

22-
export const defaultQuestionGuideTextConfig = {
24+
export const defaultChatInputGuideConfig = {
2325
open: false,
2426
textList: [],
25-
customURL: ''
27+
customUrl: ''
2628
};

packages/global/core/app/type.d.ts

+16-30
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DatasetSearchModeEnum } from '../dataset/constants';
88
import { TeamTagSchema as TeamTagsSchemaType } from '@fastgpt/global/support/user/team/type.d';
99
import { StoreEdgeItemType } from '../workflow/type/edge';
1010

11-
export interface AppSchema {
11+
export type AppSchema = {
1212
_id: string;
1313
teamId: string;
1414
tmbId: string;
@@ -23,13 +23,14 @@ export interface AppSchema {
2323
edges: StoreEdgeItemType[];
2424

2525
// App system config
26+
chatConfig: AppChatConfigType;
2627
scheduledTriggerConfig?: AppScheduledTriggerConfigType | null;
2728
scheduledTriggerNextTime?: Date;
2829

2930
permission: `${PermissionTypeEnum}`;
3031
inited?: boolean;
3132
teamTags: string[];
32-
}
33+
};
3334

3435
export type AppListItemType = {
3536
_id: string;
@@ -66,33 +67,19 @@ export type AppSimpleEditFormType = {
6667
datasetSearchExtensionBg?: string;
6768
};
6869
selectedTools: FlowNodeTemplateType[];
69-
userGuide: {
70-
welcomeText: string;
71-
variables: {
72-
id: string;
73-
key: string;
74-
label: string;
75-
type: `${VariableInputEnum}`;
76-
required: boolean;
77-
maxLen: number;
78-
enums: {
79-
value: string;
80-
}[];
81-
}[];
82-
questionGuide: boolean;
83-
tts: {
84-
type: 'none' | 'web' | 'model';
85-
model?: string | undefined;
86-
voice?: string | undefined;
87-
speed?: number | undefined;
88-
};
89-
whisper: AppWhisperConfigType;
90-
scheduleTrigger: AppScheduledTriggerConfigType | null;
91-
questionGuideText: AppQuestionGuideTextConfigType;
92-
};
70+
chatConfig: AppChatConfigType;
9371
};
9472

95-
/* app function config */
73+
/* app chat config type */
74+
export type AppChatConfigType = {
75+
welcomeText?: string;
76+
variables?: VariableItemType[];
77+
questionGuide?: boolean;
78+
ttsConfig?: AppTTSConfigType;
79+
whisperConfig?: AppWhisperConfigType;
80+
scheduledTriggerConfig?: AppScheduledTriggerConfigType;
81+
chatInputGuide?: ChatInputGuideConfigType;
82+
};
9683
export type SettingAIDataType = {
9784
model: string;
9885
temperature: number;
@@ -125,10 +112,9 @@ export type AppWhisperConfigType = {
125112
autoTTSResponse: boolean;
126113
};
127114
// question guide text
128-
export type AppQuestionGuideTextConfigType = {
115+
export type ChatInputGuideConfigType = {
129116
open: boolean;
130-
textList: string[];
131-
customURL: string;
117+
customUrl: string;
132118
};
133119
// interval timer
134120
export type AppScheduledTriggerConfigType = {

packages/global/core/app/utils.ts

+36-58
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,42 @@
1-
import type { AppSimpleEditFormType } from '../app/type';
1+
import type { AppChatConfigType, AppSimpleEditFormType } from '../app/type';
22
import { FlowNodeTypeEnum } from '../workflow/node/constant';
33
import { NodeInputKeyEnum, FlowNodeTemplateTypeEnum } from '../workflow/constants';
44
import type { FlowNodeInputItemType } from '../workflow/type/io.d';
5-
import { getGuideModule, splitGuideModule } from '../workflow/utils';
5+
import { getAppChatConfig } from '../workflow/utils';
66
import { StoreNodeItemType } from '../workflow/type';
77
import { DatasetSearchModeEnum } from '../dataset/constants';
8-
import { defaultQuestionGuideTextConfig, defaultWhisperConfig } from './constants';
98

10-
export const getDefaultAppForm = (): AppSimpleEditFormType => {
11-
return {
12-
aiSettings: {
13-
model: 'gpt-3.5-turbo',
14-
systemPrompt: '',
15-
temperature: 0,
16-
isResponseAnswerText: true,
17-
maxHistories: 6,
18-
maxToken: 4000
19-
},
20-
dataset: {
21-
datasets: [],
22-
similarity: 0.4,
23-
limit: 1500,
24-
searchMode: DatasetSearchModeEnum.embedding,
25-
usingReRank: false,
26-
datasetSearchUsingExtensionQuery: true,
27-
datasetSearchExtensionBg: ''
28-
},
29-
selectedTools: [],
30-
userGuide: {
31-
welcomeText: '',
32-
variables: [],
33-
questionGuide: false,
34-
tts: {
35-
type: 'web'
36-
},
37-
whisper: defaultWhisperConfig,
38-
scheduleTrigger: null,
39-
questionGuideText: defaultQuestionGuideTextConfig
40-
}
41-
};
42-
};
9+
export const getDefaultAppForm = (): AppSimpleEditFormType => ({
10+
aiSettings: {
11+
model: 'gpt-3.5-turbo',
12+
systemPrompt: '',
13+
temperature: 0,
14+
isResponseAnswerText: true,
15+
maxHistories: 6,
16+
maxToken: 4000
17+
},
18+
dataset: {
19+
datasets: [],
20+
similarity: 0.4,
21+
limit: 1500,
22+
searchMode: DatasetSearchModeEnum.embedding,
23+
usingReRank: false,
24+
datasetSearchUsingExtensionQuery: true,
25+
datasetSearchExtensionBg: ''
26+
},
27+
selectedTools: [],
28+
chatConfig: {}
29+
});
4330

4431
/* format app nodes to edit form */
45-
export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
32+
export const appWorkflow2Form = ({
33+
nodes,
34+
chatConfig
35+
}: {
36+
nodes: StoreNodeItemType[];
37+
chatConfig: AppChatConfigType;
38+
}) => {
4639
const defaultAppForm = getDefaultAppForm();
47-
4840
const findInputValueByKey = (inputs: FlowNodeInputItemType[], key: string) => {
4941
return inputs.find((item) => item.key === key)?.value;
5042
};
@@ -103,26 +95,6 @@ export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
10395
node.inputs,
10496
NodeInputKeyEnum.datasetSearchExtensionBg
10597
);
106-
} else if (node.flowNodeType === FlowNodeTypeEnum.systemConfig) {
107-
const {
108-
welcomeText,
109-
variableNodes,
110-
questionGuide,
111-
ttsConfig,
112-
whisperConfig,
113-
scheduledTriggerConfig,
114-
questionGuideText
115-
} = splitGuideModule(getGuideModule(nodes));
116-
117-
defaultAppForm.userGuide = {
118-
welcomeText: welcomeText,
119-
variables: variableNodes,
120-
questionGuide: questionGuide,
121-
tts: ttsConfig,
122-
whisper: whisperConfig,
123-
scheduleTrigger: scheduledTriggerConfig,
124-
questionGuideText: questionGuideText
125-
};
12698
} else if (node.flowNodeType === FlowNodeTypeEnum.pluginModule) {
12799
if (!node.pluginId) return;
128100

@@ -139,6 +111,12 @@ export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
139111
outputs: node.outputs,
140112
templateType: FlowNodeTemplateTypeEnum.other
141113
});
114+
} else if (node.flowNodeType === FlowNodeTypeEnum.systemConfig) {
115+
defaultAppForm.chatConfig = getAppChatConfig({
116+
chatConfig,
117+
systemConfigNode: node,
118+
isPublicFetch: true
119+
});
142120
}
143121
});
144122

packages/global/core/app/version.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { StoreNodeItemType } from '../workflow/type';
22
import { StoreEdgeItemType } from '../workflow/type/edge';
3+
import { AppChatConfigType } from './type';
34

45
export type AppVersionSchemaType = {
56
_id: string;
67
appId: string;
78
time: Date;
89
nodes: StoreNodeItemType[];
910
edges: StoreEdgeItemType[];
11+
chatConfig: AppChatConfigType;
1012
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type ChatInputGuideSchemaType = {
2+
_id: string;
3+
appId: string;
4+
text: string;
5+
};

packages/global/core/chat/type.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import { FlowNodeTypeEnum } from '../workflow/node/constant';
1111
import { NodeOutputKeyEnum } from '../workflow/constants';
1212
import { DispatchNodeResponseKeyEnum } from '../workflow/runtime/constants';
13-
import { AppSchema, VariableItemType } from '../app/type';
13+
import { AppChatConfigType, AppSchema, VariableItemType } from '../app/type';
1414
import type { AppSchema as AppType } from '@fastgpt/global/core/app/type.d';
1515
import { DatasetSearchModeEnum } from '../dataset/constants';
1616
import { ChatBoxInputType } from '../../../../projects/app/src/components/ChatBox/type';

packages/global/core/workflow/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export enum NodeInputKeyEnum {
4545
whisper = 'whisper',
4646
variables = 'variables',
4747
scheduleTrigger = 'scheduleTrigger',
48-
questionGuideText = 'questionGuideText',
48+
chatInputGuide = 'chatInputGuide',
4949

5050
// entry
5151
userChatInput = 'userChatInput',

0 commit comments

Comments
 (0)