Skip to content

Commit

Permalink
feat: question guide (#1508)
Browse files Browse the repository at this point in the history
* feat: question guide

* fix

* fix

* fix

* change interface

* fix
  • Loading branch information
newfish-cmyk committed May 19, 2024
1 parent fd31a0b commit e35ce2c
Show file tree
Hide file tree
Showing 40 changed files with 1,071 additions and 34 deletions.
Binary file added docSite/assets/imgs/questionGuide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions docSite/content/docs/course/custom_link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: "自定义词库地址"
description: "FastGPT 自定义输入提示的接口地址"
icon: "code"
draft: false
toc: true
weight: 350
---

![](/imgs/questionGuide.png)

## 什么是输入提示
可自定义开启或关闭,当输入提示开启,并且词库中存在数据时,用户在输入问题时如果输入命中词库,那么会在输入框上方展示对应的智能推荐数据

用户可配置词库,选择存储在 FastGPT 数据库中,或者提供自定义接口获取词库

## 数据格式
词库的形式为一个字符串数组,定义的词库接口应该有两种方法 —— GET & POST

### GET
对于 GET 方法,用于获取词库数据,FastGPT 会给接口发送数据 query 为
```
{
appId: 'xxxx'
}
```
返回数据格式应当为
```
{
data: ['xxx', 'xxxx']
}
```

### POST
对于 POST 方法,用于更新词库数据,FastGPT 会给接口发送数据 body 为
```
{
appId: 'xxxx',
text: ['xxx', 'xxxx']
}
```
接口应当按照获取的数据格式存储相对应的词库数组

6 changes: 6 additions & 0 deletions packages/global/core/app/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ export const defaultWhisperConfig: AppWhisperConfigType = {
autoSend: false,
autoTTSResponse: false
};

export const defaultQuestionGuideTextConfig = {
open: false,
textList: [],
customURL: ''
};
7 changes: 7 additions & 0 deletions packages/global/core/app/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type AppSimpleEditFormType = {
};
whisper: AppWhisperConfigType;
scheduleTrigger: AppScheduledTriggerConfigType | null;
questionGuideText: AppQuestionGuideTextConfigType;
};
};

Expand Down Expand Up @@ -123,6 +124,12 @@ export type AppWhisperConfigType = {
autoSend: boolean;
autoTTSResponse: boolean;
};
// question guide text
export type AppQuestionGuideTextConfigType = {
open: boolean;
textList: string[];
customURL: string;
};
// interval timer
export type AppScheduledTriggerConfigType = {
cronString: string;
Expand Down
11 changes: 7 additions & 4 deletions packages/global/core/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { FlowNodeInputItemType } from '../workflow/type/io.d';
import { getGuideModule, splitGuideModule } from '../workflow/utils';
import { StoreNodeItemType } from '../workflow/type';
import { DatasetSearchModeEnum } from '../dataset/constants';
import { defaultWhisperConfig } from './constants';
import { defaultQuestionGuideTextConfig, defaultWhisperConfig } from './constants';

export const getDefaultAppForm = (): AppSimpleEditFormType => {
return {
Expand Down Expand Up @@ -35,7 +35,8 @@ export const getDefaultAppForm = (): AppSimpleEditFormType => {
type: 'web'
},
whisper: defaultWhisperConfig,
scheduleTrigger: null
scheduleTrigger: null,
questionGuideText: defaultQuestionGuideTextConfig
}
};
};
Expand Down Expand Up @@ -109,7 +110,8 @@ export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
questionGuide,
ttsConfig,
whisperConfig,
scheduledTriggerConfig
scheduledTriggerConfig,
questionGuideText
} = splitGuideModule(getGuideModule(nodes));

defaultAppForm.userGuide = {
Expand All @@ -118,7 +120,8 @@ export const appWorkflow2Form = ({ nodes }: { nodes: StoreNodeItemType[] }) => {
questionGuide: questionGuide,
tts: ttsConfig,
whisper: whisperConfig,
scheduleTrigger: scheduledTriggerConfig
scheduleTrigger: scheduledTriggerConfig,
questionGuideText: questionGuideText
};
} else if (node.flowNodeType === FlowNodeTypeEnum.pluginModule) {
if (!node.pluginId) return;
Expand Down
1 change: 1 addition & 0 deletions packages/global/core/workflow/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum NodeInputKeyEnum {
whisper = 'whisper',
variables = 'variables',
scheduleTrigger = 'scheduleTrigger',
questionGuideText = 'questionGuideText',

// entry
userChatInput = 'userChatInput',
Expand Down
6 changes: 6 additions & 0 deletions packages/global/core/workflow/template/system/systemConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export const SystemConfigNode: FlowNodeTemplateType = {
renderTypeList: [FlowNodeInputTypeEnum.hidden],
valueType: WorkflowIOValueTypeEnum.any,
label: ''
},
{
key: NodeInputKeyEnum.questionGuideText,
renderTypeList: [FlowNodeInputTypeEnum.hidden],
valueType: WorkflowIOValueTypeEnum.any,
label: ''
}
],
outputs: []
Expand Down
12 changes: 10 additions & 2 deletions packages/global/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type {
VariableItemType,
AppTTSConfigType,
AppWhisperConfigType,
AppScheduledTriggerConfigType
AppScheduledTriggerConfigType,
AppQuestionGuideTextConfigType
} from '../app/type';
import { EditorVariablePickerType } from '../../../web/components/common/Textarea/PromptEditor/type';
import { defaultWhisperConfig } from '../app/constants';
Expand Down Expand Up @@ -59,13 +60,20 @@ export const splitGuideModule = (guideModules?: StoreNodeItemType) => {
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.scheduleTrigger)?.value ??
null;

const questionGuideText: AppQuestionGuideTextConfigType = guideModules?.inputs?.find(
(item) => item.key === NodeInputKeyEnum.questionGuideText
)?.value || {
open: false
};

return {
welcomeText,
variableNodes,
questionGuide,
ttsConfig,
whisperConfig,
scheduledTriggerConfig
scheduledTriggerConfig,
questionGuideText
};
};
export const replaceAppChatConfig = ({
Expand Down
40 changes: 40 additions & 0 deletions packages/service/core/app/qGuideSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { TeamCollectionName } from '@fastgpt/global/support/user/team/constant';
import { connectionMongo, type Model } from '../../common/mongo';
const { Schema, model, models } = connectionMongo;

export const AppQGuideCollectionName = 'app_question_guides';

type AppQGuideSchemaType = {
_id: string;
appId: string;
teamId: string;
text: string;
};

const AppQGuideSchema = new Schema({
appId: {
type: Schema.Types.ObjectId,
ref: AppQGuideCollectionName,
required: true
},
teamId: {
type: Schema.Types.ObjectId,
ref: TeamCollectionName,
required: true
},
text: {
type: String,
default: ''
}
});

try {
AppQGuideSchema.index({ appId: 1 });
} catch (error) {
console.log(error);
}

export const MongoAppQGuide: Model<AppQGuideSchemaType> =
models[AppQGuideCollectionName] || model(AppQGuideCollectionName, AppQGuideSchema);

MongoAppQGuide.syncIndexes();
3 changes: 3 additions & 0 deletions packages/web/components/common/Icon/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck

export const iconPaths = {
book: () => import('./icons/book.svg'),
change: () => import('./icons/change.svg'),
chatSend: () => import('./icons/chatSend.svg'),
closeSolid: () => import('./icons/closeSolid.svg'),
Expand Down Expand Up @@ -64,6 +65,7 @@ export const iconPaths = {
'core/app/appApiLight': () => import('./icons/core/app/appApiLight.svg'),
'core/app/customFeedback': () => import('./icons/core/app/customFeedback.svg'),
'core/app/headphones': () => import('./icons/core/app/headphones.svg'),
'core/app/inputGuides': () => import('./icons/core/app/inputGuides.svg'),
'core/app/logsLight': () => import('./icons/core/app/logsLight.svg'),
'core/app/markLight': () => import('./icons/core/app/markLight.svg'),
'core/app/publish/lark': () => import('./icons/core/app/publish/lark.svg'),
Expand Down Expand Up @@ -219,6 +221,7 @@ export const iconPaths = {
'support/user/userFill': () => import('./icons/support/user/userFill.svg'),
'support/user/userLight': () => import('./icons/support/user/userLight.svg'),
text: () => import('./icons/text.svg'),
union: () => import('./icons/union.svg'),
user: () => import('./icons/user.svg'),
wx: () => import('./icons/wx.svg')
};
3 changes: 3 additions & 0 deletions packages/web/components/common/Icon/icons/book.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/web/components/common/Icon/icons/union.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions packages/web/hooks/useScrollPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ export function useScrollPagination<
...props
}: { children: React.ReactNode; isLoading?: boolean } & BoxProps) => {
return (
<MyBox isLoading={isLoading} ref={containerRef} overflow={'overlay'} {...props}>
<Box ref={wrapperRef}>{children}</Box>
<>
<MyBox isLoading={isLoading} ref={containerRef} overflow={'overlay'} {...props}>
<Box ref={wrapperRef}>{children}</Box>
</MyBox>
{noMore.current && (
<Box pb={2} textAlign={'center'} color={'myGray.600'} fontSize={'sm'}>
{t('common.No more data')}
</Box>
)}
</MyBox>
</>
);
}
);
Expand All @@ -115,6 +117,7 @@ export function useScrollPagination<
return {
containerRef,
list,
data,
isLoading,
ScrollList,
fetchData: loadData
Expand Down
8 changes: 8 additions & 0 deletions projects/app/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
"type": "\"{{type}}\" type\n{{description}}"
},
"modules": {
"Config Texts": "Config Texts",
"Config question guide": "Config question guide",
"Custom question guide URL": "Custom question guide URL",
"Input Guide": "Input Guide",
"Only support CSV": "Only support CSV",
"Question Guide": "Question guide",
"Question Guide Switch": "Open question guide",
"Question Guide Texts": "Texts",
"Title is required": "Module name cannot be empty"
}
}
3 changes: 3 additions & 0 deletions projects/app/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"Move": "Move",
"Name": "Name",
"New Create": "Create New",
"No data": "No data",
"Rename": "Rename",
"Running": "Running",
"UnKnow": "Unknown",
Expand Down Expand Up @@ -45,6 +46,7 @@
"Delete Tip": "Delete Tip",
"Delete Warning": "Delete Warning",
"Detail": "Detail",
"Documents": "Documents",
"Done": "Done",
"Edit": "Edit",
"Exit": "Exit",
Expand Down Expand Up @@ -101,6 +103,7 @@
"Search": "Search",
"Select File Failed": "Select File Failed",
"Select One Folder": "Select a folder",
"Select all": "Select all",
"Select template": "Select template",
"Set Avatar": "Click to set avatar",
"Set Name": "Set a name",
Expand Down
8 changes: 8 additions & 0 deletions projects/app/i18n/zh/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
"type": "\"{{type}}\"类型\n{{description}}"
},
"modules": {
"Config Texts": "配置词库",
"Config question guide": "配置输入提示",
"Custom question guide URL": "自定义词库地址",
"Input Guide": "智能推荐",
"Only support CSV": "仅支持 CSV 导入,点击下载模板",
"Question Guide": "输入提示",
"Question Guide Switch": "是否开启",
"Question Guide Texts": "词库",
"Title is required": "模块名不能为空"
}
}
3 changes: 3 additions & 0 deletions projects/app/i18n/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"Move": "移动",
"Name": "名称",
"New Create": "新建",
"No data": "暂无数据",
"Rename": "重命名",
"Running": "运行中",
"UnKnow": "未知",
Expand Down Expand Up @@ -45,6 +46,7 @@
"Delete Tip": "删除提示",
"Delete Warning": "删除警告",
"Detail": "详情",
"Documents": "文档",
"Done": "完成",
"Edit": "编辑",
"Exit": "退出",
Expand Down Expand Up @@ -102,6 +104,7 @@
"Search": "搜索",
"Select File Failed": "选择文件异常",
"Select One Folder": "选择一个目录",
"Select all": "全选",
"Select template": "选择模板",
"Set Avatar": "点击设置头像",
"Set Name": "取个名字",
Expand Down
Loading

0 comments on commit e35ce2c

Please sign in to comment.