Skip to content

Commit

Permalink
Perf input guide (#1557)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
c121914yu authored May 21, 2024
1 parent 8e8ceb7 commit fb368a5
Show file tree
Hide file tree
Showing 123 changed files with 2,126 additions and 1,807 deletions.
1 change: 1 addition & 0 deletions .vscode/i18n-ally-custom-framework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ usageMatchRegex:
- "[^\\w\\d]publishT\\(['\"`]({key})['\"`]"
- "[^\\w\\d]workflowT\\(['\"`]({key})['\"`]"
- "[^\\w\\d]userT\\(['\"`]({key})['\"`]"
- "[^\\w\\d]chatT\\(['\"`]({key})['\"`]"

# A RegEx to set a custom scope range. This scope will be used as a prefix when detecting keys
# and works like how the i18next framework identifies the namespace scope from the
Expand Down
48 changes: 48 additions & 0 deletions docSite/content/docs/course/chat_input_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "对话问题引导"
description: "FastGPT 对话问题引导"
icon: "code"
draft: false
toc: true
weight: 350
---

![](/imgs/questionGuide.png)

## 什么是自定义问题引导

你可以为你的应用提前预设一些问题,用户在输入时,会根据输入的内容,动态搜索这些问题作为提示,从而引导用户更快的进行提问。

你可以直接在 FastGPT 中配置词库,或者提供自定义词库接口。

## 自定义词库接口

**请求:**

```bash
curl --location --request GET 'http://localhost:3000/api/core/chat/inputGuide/query?appId=663c75302caf8315b1c00194&searchKey=你'
```

**响应**

```json
{
"code": 200,
"statusText": "",
"message": "",
"data": [
"是你",
"你是谁呀",
"你好好呀",
"你好呀",
"你是谁!",
"你好"
]
}
```


**参数说明:**

- appId - 应用ID
- searchKey - 搜索关键字
43 changes: 0 additions & 43 deletions docSite/content/docs/course/custom_link.md

This file was deleted.

8 changes: 5 additions & 3 deletions packages/global/core/app/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppWhisperConfigType } from './type';
import { AppTTSConfigType, AppWhisperConfigType } from './type';

export enum AppTypeEnum {
simple = 'simple',
Expand All @@ -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 changes: 16 additions & 30 deletions packages/global/core/app/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down
94 changes: 36 additions & 58 deletions packages/global/core/app/utils.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand Down Expand Up @@ -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;

Expand All @@ -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
});
}
});

Expand Down
2 changes: 2 additions & 0 deletions packages/global/core/app/version.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { StoreNodeItemType } from '../workflow/type';
import { StoreEdgeItemType } from '../workflow/type/edge';
import { AppChatConfigType } from './type';

export type AppVersionSchemaType = {
_id: string;
appId: string;
time: Date;
nodes: StoreNodeItemType[];
edges: StoreEdgeItemType[];
chatConfig: AppChatConfigType;
};
5 changes: 5 additions & 0 deletions packages/global/core/chat/inputGuide/type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type ChatInputGuideSchemaType = {
_id: string;
appId: string;
text: string;
};
2 changes: 1 addition & 1 deletion packages/global/core/chat/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/global/core/workflow/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export enum NodeInputKeyEnum {
whisper = 'whisper',
variables = 'variables',
scheduleTrigger = 'scheduleTrigger',
questionGuideText = 'questionGuideText',
chatInputGuide = 'chatInputGuide',

// entry
userChatInput = 'userChatInput',
Expand Down
Loading

0 comments on commit fb368a5

Please sign in to comment.