Skip to content

Commit

Permalink
Global variables support external variable; Extract module support de…
Browse files Browse the repository at this point in the history
…fault value (labring#921)
  • Loading branch information
c121914yu authored Mar 5, 2024
1 parent 42a8184 commit af581bc
Show file tree
Hide file tree
Showing 30 changed files with 306 additions and 200 deletions.
4 changes: 2 additions & 2 deletions docSite/content/docs/agreement/privacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ weight: 1221

最后更新时间:2024年3月3日

我们非常重视您的隐私保护,在您使用FastGPT云服务时,我们将按照以下政策收集、使用、披露和保护您的个人信息。请您仔细阅读并充分理解本隐私政策。
我们非常重视您的隐私保护,在您使用FastGPT云服务时(以下简称为“本服务”),我们将按照以下政策收集、使用、披露和保护您的个人信息。请您仔细阅读并充分理解本隐私政策。

**我们可能需要收集的信息**

Expand Down Expand Up @@ -39,7 +39,7 @@ weight: 1221
2. 我们会定期对收集、存储和处理的个人信息进行安全评估,以确保个人信息安全。
3. 在发生个人信息泄露等安全事件时,我们会立即启动应急预案,并在法律法规规定的范围内向您及时告知。
4. 我们不会使用您的数据进行额外的备份存储或用于模型训练。
5. 您在本服务进行的数据删除均为物理删除,不可恢复。如有有非物理删除的操作,我们会在服务中特别指出。
5. 您在本服务进行的数据删除均为物理删除,不可恢复。如有非物理删除的操作,我们会在服务中特别指出。

**用户权利**

Expand Down
2 changes: 2 additions & 0 deletions docSite/content/docs/development/openapi/share.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ curl --location --request POST '{{host}}/shareAuth/start' \

响应值与[chat 接口格式相同](/docs/development/openapi/chat/#响应),仅多了一个`token`

重点关注:`totalPoints`(总消耗AI积分),`token`(Token消耗总数)

```bash
curl --location --request POST '{{host}}/shareAuth/finish' \
--header 'Content-Type: application/json' \
Expand Down
18 changes: 12 additions & 6 deletions docSite/content/docs/development/upgrading/469.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ curl --location --request POST 'https://{{host}}/api/init/v469' \
1. 重置计量表。
2. 执行脏数据清理(清理无效的文件、清理无效的图片、清理无效的知识库集合、清理无效的向量)

## 外部接口更新

1. 由于计费系统变更,[分享链接对话上报接口](/docs/development/openapi/share/#5-编写对话结果上报接口可选)需要做一些调整,price字段被totalPoints字段取代。inputToken和outputToken不再提供,只提供`token`字段(总token数量)。

## V4.6.9 更新说明

1. 商业版新增 - 知识库新增“增强处理”训练模式,可生成更多类型索引。
2. 新增 - 完善了HTTP模块的变量提示。
3. 新增 - HTTP模块支持OpenAI单接口导入。
4. 优化 - 问题补全。增加英文类型。同时可以设置为单独模块,方便复用。
5. 优化 - 重写了计量模式
6. 优化 - Token 过滤历史记录,保持偶数条,防止部分模型报错。
7. 优化 - 分享链接SEO,可直接展示应用名和头像。
8. 修复 - 标注功能。
9. 修复 - qa生成线程计数错误。
4. 新增 - 全局变量支持增加外部变量。可通过分享链接的Query或 API 的 variables 参数传入。
5. 新增 - 内容提取模块增加默认值。
6. 优化 - 问题补全。增加英文类型。同时可以设置为单独模块,方便复用。
7. 优化 - 重写了计量模式
8. 优化 - Token 过滤历史记录,保持偶数条,防止部分模型报错。
9. 优化 - 分享链接SEO,可直接展示应用名和头像。
10. 修复 - 标注功能。
11. 修复 - qa生成线程计数错误。
12. 修复 - 问题分类连线类型错误
20 changes: 16 additions & 4 deletions packages/global/core/module/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,29 @@ export enum ModuleOutputKeyEnum {
export enum VariableInputEnum {
input = 'input',
textarea = 'textarea',
select = 'select'
select = 'select',
external = 'external'
}
export const variableMap = {
[VariableInputEnum.input]: {
icon: 'core/app/variable/input'
icon: 'core/app/variable/input',
title: 'core.module.variable.input type',
desc: ''
},
[VariableInputEnum.textarea]: {
icon: 'core/app/variable/textarea'
icon: 'core/app/variable/textarea',
title: 'core.module.variable.textarea type',
desc: '允许用户最多输入4000字的对话框。'
},
[VariableInputEnum.select]: {
icon: 'core/app/variable/select'
icon: 'core/app/variable/select',
title: 'core.module.variable.select type',
desc: ''
},
[VariableInputEnum.external]: {
icon: 'core/app/variable/external',
title: 'core.module.variable.External type',
desc: '可以通过API接口或分享链接的Query传递变量。增加该类型变量的主要目的是用于变量提示。使用例子: 你可以通过分享链接Query中拼接Token,来实现内部系统身份鉴权。'
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const ContextExtractModule: FlowModuleTemplateType = {
{
key: ModuleInputKeyEnum.extractKeys,
type: FlowNodeInputTypeEnum.custom,
label: '目标字段',
label: '',
valueType: ModuleIOValueTypeEnum.any,
description: "由 '描述' 和 'key' 组成一个目标字段,可提取多个目标字段",
value: [], // {desc: string; key: string; required: boolean; enum: string[]}[]
Expand All @@ -76,6 +76,7 @@ export const ContextExtractModule: FlowModuleTemplateType = {
{
key: ModuleOutputKeyEnum.failed,
label: '提取字段缺失',
description: '存在一个或多个字段未提取成功。尽管使用了默认值也算缺失。',
valueType: ModuleIOValueTypeEnum.boolean,
type: FlowNodeOutputTypeEnum.source,
targets: []
Expand Down
1 change: 1 addition & 0 deletions packages/global/core/module/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type ContextExtractAgentItemType = {
desc: string;
key: string;
required: boolean;
defaultValue?: string;
enum?: string;
};

Expand Down
12 changes: 11 additions & 1 deletion packages/service/common/vectorStore/pg/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { delay } from '@fastgpt/global/common/system/utils';
import { addLog } from '../../system/log';
import { Pool } from 'pg';
import type { QueryResultRow } from 'pg';

Expand All @@ -15,10 +17,13 @@ export const connectPg = async (): Promise<Pool> => {
connectionTimeoutMillis: 20000
});

global.pgClient.on('error', (err) => {
global.pgClient.on('error', async (err) => {
console.log(err);
global.pgClient?.end();
global.pgClient = null;

await delay(1000);
addLog.info(`Retry connect pg`);
connectPg();
});

Expand All @@ -27,7 +32,12 @@ export const connectPg = async (): Promise<Pool> => {
console.log('pg connected');
return global.pgClient;
} catch (error) {
global.pgClient?.end();
global.pgClient = null;

await delay(1000);
addLog.info(`Retry connect pg`);

return connectPg();
}
};
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/tts': () => import('./icons/core/app/simpleMode/tts.svg'),
'core/app/simpleMode/variable': () => import('./icons/core/app/simpleMode/variable.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'),
'core/app/variable/select': () => import('./icons/core/app/variable/select.svg'),
'core/app/variable/textarea': () => import('./icons/core/app/variable/textarea.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.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, ModalBody, ModalFooter, useDisclosure } from '@chakra-ui/react'
import React, { useEffect } from 'react';
import { editorStateToText } from './utils';
import Editor from './Editor';
import MyModal from '../../MyModal';
import MyModal from '../../CustomModal';
import { useTranslation } from 'next-i18next';
import { $getRoot, EditorState, type LexicalEditor } from 'lexical';
import { EditorVariablePickerType } from './type.d';
Expand Down
File renamed without changes.
11 changes: 7 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions projects/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"immer": "^9.0.19",
"js-yaml": "^4.1.0",
"jschardet": "^3.0.0",
"json5": "^2.2.3",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"mermaid": "^10.2.3",
Expand Down
10 changes: 6 additions & 4 deletions projects/app/public/docs/versionIntro.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
1. 新增 - 知识库新增“增强处理”训练模式,可生成更多类型索引。
2. 新增 - 完善了HTTP模块的变量提示。
3. 新增 - HTTP模块支持OpenAI单接口导入。
4. 优化 - 问题补全。增加英文类型。同时可以设置为单独模块,方便复用。
5. [点击查看高级编排介绍文档](https://doc.fastgpt.in/docs/workflow/intro)
6. [使用文档](https://doc.fastgpt.in/docs/intro/)
7. [点击查看商业版](https://doc.fastgpt.in/docs/commercial/)
4. 新增 - 全局变量支持增加外部变量。可通过分享链接的Query或 API 的 variables 参数传入。
5. 新增 - 内容提取模块增加默认值。
6. 优化 - 问题补全。增加英文类型。同时可以设置为单独模块,方便复用。
7. [点击查看高级编排介绍文档](https://doc.fastgpt.in/docs/workflow/intro)
8. [使用文档](https://doc.fastgpt.in/docs/intro/)
9. [点击查看商业版](https://doc.fastgpt.in/docs/commercial/)
9 changes: 8 additions & 1 deletion projects/app/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@
"Input description": "",
"label": "Dataset quote"
},
"Default value": "Default ",
"Default value placeholder": "Null characters are returned by default",
"Field Description": "Description",
"Field Name": "Name",
"Field Type": "Type",
Expand All @@ -795,10 +797,14 @@
"Field Edit": "Field Edit"
},
"extract": {
"Add field": "Add",
"Enum Description": "Lists the possible values for the field, one per row",
"Enum Value": "Enum",
"Field Description Placeholder": "Name/age /sql statement......",
"Field Setting Title": "Extract field configuration"
"Field Setting Title": "Extract field configuration",
"Required": "Required",
"Required Description": "Even if the field cannot be extracted, it is returned with the default value",
"Target field": "Field"
},
"http": {
"Add props": "Add props",
Expand Down Expand Up @@ -939,6 +945,7 @@
"string": "String"
},
"variable": {
"External type": "External",
"add option": "Add Option",
"input type": "Text",
"key": "Key",
Expand Down
9 changes: 8 additions & 1 deletion projects/app/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,8 @@
"Input description": "可接收知识库搜索的结果。",
"label": "知识库引用"
},
"Default value": "默认值",
"Default value placeholder": "不填则默认返回空字符",
"Field Description": "字段描述",
"Field Name": "字段名",
"Field Type": "字段类型",
Expand All @@ -797,10 +799,14 @@
"Field Edit": "字段编辑"
},
"extract": {
"Add field": "新增字段",
"Enum Description": "列举出该字段可能的值,每行一个",
"Enum Value": "枚举值",
"Field Description Placeholder": "姓名/年龄/sql语句……",
"Field Setting Title": "提取字段配置"
"Field Setting Title": "提取字段配置",
"Required": "必须返回",
"Required Description": "即使无法提取该字段,也会使用默认值进行返回",
"Target field": "目标字段"
},
"http": {
"Add props": "添加参数",
Expand Down Expand Up @@ -941,6 +947,7 @@
"string": "字符串"
},
"variable": {
"External type": "外部传入",
"add option": "添加选项",
"input type": "文本",
"key": "变量 key",
Expand Down
23 changes: 14 additions & 9 deletions projects/app/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ const ChatBox = (
() => splitGuideModule(userGuideModule),
[userGuideModule]
);
const filterVariableModules = useMemo(
() => variableModules.filter((item) => item.type !== VariableInputEnum.external),
[variableModules]
);

// compute variable input is finish.
const chatForm = useForm<{
Expand All @@ -200,17 +204,18 @@ const ChatBox = (

const [variableInputFinish, setVariableInputFinish] = useState(false); // clicked start chat button
const variableIsFinish = useMemo(() => {
if (!variableModules || variableModules.length === 0 || chatHistory.length > 0) return true;
if (!filterVariableModules || filterVariableModules.length === 0 || chatHistory.length > 0)
return true;

for (let i = 0; i < variableModules.length; i++) {
const item = variableModules[i];
for (let i = 0; i < filterVariableModules.length; i++) {
const item = filterVariableModules[i];
if (item.required && !variables[item.key]) {
return false;
}
}

return variableInputFinish;
}, [chatHistory.length, variableInputFinish, variableModules, variables]);
}, [chatHistory.length, variableInputFinish, filterVariableModules, variables]);

// 滚动到底部
const scrollToBottom = (behavior: 'smooth' | 'auto' = 'smooth') => {
Expand Down Expand Up @@ -495,7 +500,7 @@ const ChatBox = (
getChatHistories: () => chatHistory,
resetVariables(e) {
const defaultVal: Record<string, any> = {};
variableModules?.forEach((item) => {
filterVariableModules?.forEach((item) => {
defaultVal[item.key] = '';
});

Expand All @@ -519,13 +524,13 @@ const ChatBox = (
feConfigs?.show_emptyChat &&
showEmptyIntro &&
chatHistory.length === 0 &&
!variableModules?.length &&
!filterVariableModules?.length &&
!welcomeText,
[
chatHistory.length,
feConfigs?.show_emptyChat,
showEmptyIntro,
variableModules?.length,
filterVariableModules?.length,
welcomeText
]
);
Expand Down Expand Up @@ -604,10 +609,10 @@ const ChatBox = (
{showEmpty && <Empty />}
{!!welcomeText && <WelcomeText appAvatar={appAvatar} welcomeText={welcomeText} />}
{/* variable input */}
{!!variableModules?.length && (
{!!filterVariableModules?.length && (
<VariableInput
appAvatar={appAvatar}
variableModules={variableModules}
variableModules={filterVariableModules}
variableIsFinish={variableIsFinish}
chatForm={chatForm}
onSubmitVariables={onSubmitVariables}
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/components/MyModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { ModalContentProps } from '@chakra-ui/react';
import { useSystemStore } from '@/web/common/system/useSystemStore';
import CustomModal from '@fastgpt/web/components/common/MyModal';
import CustomModal from '@fastgpt/web/components/common/CustomModal';

export interface MyModalProps extends ModalContentProps {
iconSrc?: string;
Expand Down
Loading

0 comments on commit af581bc

Please sign in to comment.