Skip to content

Commit 2991c07

Browse files
Fix share page whisper auth (labring#1161)
Co-authored-by: heheer <[email protected]>
1 parent adfad8f commit 2991c07

File tree

55 files changed

+465
-250
lines changed

Some content is hidden

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

55 files changed

+465
-250
lines changed

docSite/content/docs/development/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ llm模型全部合并
2020
```json
2121
{
2222
"feConfigs": {
23-
"lafEnv": "https://laf.dev" // laf环境
23+
"lafEnv": "https://laf.dev" // laf环境。 https://laf.run (杭州阿里云) ,或者私有化的laf环境。如果使用 Laf openapi 功能,需要最新版的 laf 。
2424
},
2525
"systemEnv": {
2626
"vectorMaxProcess": 15,

docSite/content/docs/development/custom-models/bge-rerank.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ docker run -d --name reranker -p 6006:6006 -e ACCESS_TOKEN=mytoken --gpus all re
100100
version: "3"
101101
services:
102102
reranker:
103-
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/rerank:v0.2
103+
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/bge-rerank-base:v0.1
104104
container_name: reranker
105105
# GPU运行环境,如果宿主机未安装,将deploy配置隐藏即可
106106
deploy:

docSite/content/docs/development/upgrading/471.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ curl --location --request POST 'https://{{host}}/api/admin/clearInvalidData' \
1919

2020
该请求会执行脏数据清理(清理无效的文件、清理无效的图片、清理无效的知识库集合、清理无效的向量)
2121

22+
23+
## 修改配置文件
24+
25+
增加了Laf环境配置:[点击查看最新的配置文件](/docs/development/configuration/)
26+
27+
2228
## V4.7.1 更新说明
2329

2430
1. 新增 - 语音输入完整配置。支持选择是否打开语音输入(包括分享页面),支持语音输入后自动发送,支持语音输入后自动语音播放(流式)。
25-
2. 新增 - Pptx 和 xlsx 文件读取。但所有文件读取都放服务端,会消耗更多的服务器资源,以及无法在上传时预览更多内容。
31+
2. 新增 - pptx 和 xlsx 文件读取。但所有文件读取都放服务端,会消耗更多的服务器资源,以及无法在上传时预览更多内容。
2632
3. 新增 - 集成 Laf 云函数,可以读取 Laf 账号中的云函数作为 HTTP 模块。
2733
4. 新增 - 定时器,清理垃圾数据。(采用小范围清理,会清理最近n个小时的,所以请保证服务持续运行,长时间不允许,可以继续执行 clearInvalidData 的接口进行全量清理。)
2834
5. 商业版新增 - 后台配置系统通知。

docSite/content/docs/workflow/examples/dalle3.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Response:
8888
[
8989
{
9090
"moduleId": "userGuide",
91-
"name": "core.module.template.User guide",
91+
"name": "core.module.template.App system setting",
9292
"flowType": "userGuide",
9393
"position": {
9494
"x": 454.98510354678695,

docSite/content/docs/workflow/examples/feishu_webhook.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ weight: 404
2727
[
2828
{
2929
"moduleId": "userGuide",
30-
"name": "core.module.template.User guide",
30+
"name": "core.module.template.App system setting",
3131
"intro": "core.app.tip.userGuideTip",
3232
"avatar": "/imgs/module/userGuide.png",
3333
"flowType": "userGuide",

docSite/content/docs/workflow/examples/google_search.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default async function (ctx: FunctionContext) {
8484
[
8585
{
8686
"moduleId": "userGuide",
87-
"name": "core.module.template.User guide",
87+
"name": "core.module.template.App system setting",
8888
"intro": "core.app.tip.userGuideTip",
8989
"avatar": "/imgs/module/userGuide.png",
9090
"flowType": "userGuide",

docSite/content/docs/workflow/modules/laf.md

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Laf 提供了 PAT(访问凭证) 来实现 Laf 平台外的快捷登录,可以
2727

2828
填入 PAT 验证后,选择需要绑定的应用(应用需要是 Running 状态),即可调用该应用下的云函数。
2929

30-
> 如果需要解绑则取消绑定后,点击“更新”即可
31-
3230
![](/imgs/laf2.webp)
3331

3432
## 编写云函数

packages/global/common/string/textSplitter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getErrText } from '../error/utils';
2-
import { countPromptTokens } from './tiktoken';
2+
import { replaceRegChars } from './tools';
33

44
/**
55
* text split into chunks
@@ -31,7 +31,7 @@ export const splitText2Chunks = (props: {
3131
// The larger maxLen is, the next sentence is less likely to trigger splitting
3232
const stepReges: { reg: RegExp; maxLen: number }[] = [
3333
...customReg.map((text) => ({
34-
reg: new RegExp(`(${text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'g'),
34+
reg: new RegExp(`(${replaceRegChars(text)})`, 'g'),
3535
maxLen: chunkLen * 1.4
3636
})),
3737
{ reg: /^(#\s[^\n]+)\n/gm, maxLen: chunkLen * 1.2 },

packages/global/common/string/tools.ts

+2
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ export const replaceSensitiveText = (text: string) => {
5151
export const getNanoid = (size = 12) => {
5252
return customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890', size)();
5353
};
54+
55+
export const replaceRegChars = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

packages/global/core/module/template/system/userGuide.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { FlowNodeInputTypeEnum, FlowNodeTypeEnum } from '../../node/constant';
22
import { FlowNodeTemplateType } from '../../type.d';
3-
import { userGuideTip } from '../tip';
43
import {
54
ModuleIOValueTypeEnum,
65
ModuleInputKeyEnum,
@@ -12,8 +11,8 @@ export const UserGuideModule: FlowNodeTemplateType = {
1211
templateType: FlowNodeTemplateTypeEnum.userGuide,
1312
flowType: FlowNodeTypeEnum.userGuide,
1413
avatar: '/imgs/module/userGuide.png',
15-
name: '全局配置',
16-
intro: userGuideTip,
14+
name: '系统配置',
15+
intro: '可以配置应用的系统参数。',
1716
inputs: [
1817
{
1918
key: ModuleInputKeyEnum.welcomeText,
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export const chatNodeSystemPromptTip = 'core.app.tip.chatNodeSystemPromptTip';
2-
export const userGuideTip = 'core.app.tip.userGuideTip';
32
export const welcomeTextTip = 'core.app.tip.welcomeTextTip';
43
export const variableTip = 'core.app.tip.variableTip';

packages/global/support/user/team/type.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ export type TeamTagItemType = {
8181
export type LafAccountType = {
8282
token: string;
8383
appid: string;
84+
pat: string;
8485
};

packages/global/support/wallet/bill/type.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type BillSchemaType = {
1818
month?: number;
1919
datasetSize?: number;
2020
extraPoints?: number;
21+
invoice: boolean;
2122
};
2223
username: string;
2324
};

packages/service/common/file/image/schema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ try {
3535
ImageSchema.index({ expiredTime: 1 }, { expireAfterSeconds: 60 });
3636
ImageSchema.index({ type: 1 });
3737
ImageSchema.index({ createTime: 1 });
38+
// delete related img
3839
ImageSchema.index({ teamId: 1, 'metadata.relatedId': 1 });
3940
} catch (error) {
4041
console.log(error);

packages/service/common/vectorStore/controller.d.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
export type DeleteDatasetVectorProps = {
1+
export type DeleteDatasetVectorProps = (
2+
| { id: string }
3+
| { datasetIds: string[]; collectionIds?: string[] }
4+
| { idList: string[] }
5+
) & {
26
teamId: string;
3-
4-
id?: string;
5-
datasetIds?: string[];
6-
collectionIds?: string[];
7-
idList?: string[];
87
};
98

109
export type InsertVectorProps = {

packages/service/common/vectorStore/pg/controller.ts

+15-19
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ export async function initPg() {
2626
`CREATE INDEX CONCURRENTLY IF NOT EXISTS vector_index ON ${PgDatasetTableName} USING hnsw (vector vector_ip_ops) WITH (m = 32, ef_construction = 64);`
2727
);
2828
await PgClient.query(
29-
`CREATE INDEX CONCURRENTLY IF NOT EXISTS team_dataset_index ON ${PgDatasetTableName} USING btree(team_id, dataset_id);`
30-
);
31-
await PgClient.query(
32-
` CREATE INDEX CONCURRENTLY IF NOT EXISTS team_collection_index ON ${PgDatasetTableName} USING btree(team_id, collection_id);`
33-
);
34-
await PgClient.query(
35-
`CREATE INDEX CONCURRENTLY IF NOT EXISTS team_id_index ON ${PgDatasetTableName} USING btree(team_id, id);`
29+
`CREATE INDEX CONCURRENTLY IF NOT EXISTS team_dataset_collection_index ON ${PgDatasetTableName} USING btree(team_id, dataset_id, collection_id);`
3630
);
3731
await PgClient.query(
3832
`CREATE INDEX CONCURRENTLY IF NOT EXISTS create_time_index ON ${PgDatasetTableName} USING btree(createtime);`
@@ -83,31 +77,33 @@ export const deleteDatasetDataVector = async (
8377
retry?: number;
8478
}
8579
): Promise<any> => {
86-
const { teamId, id, datasetIds, collectionIds, idList, retry = 2 } = props;
80+
const { teamId, retry = 2 } = props;
8781

8882
const teamIdWhere = `team_id='${String(teamId)}' AND`;
8983

9084
const where = await (() => {
91-
if (id) return `${teamIdWhere} id=${id}`;
85+
if ('id' in props && props.id) return `${teamIdWhere} id=${props.id}`;
9286

93-
if (datasetIds) {
94-
return `${teamIdWhere} dataset_id IN (${datasetIds
87+
if ('datasetIds' in props && props.datasetIds) {
88+
const datasetIdWhere = `dataset_id IN (${props.datasetIds
9589
.map((id) => `'${String(id)}'`)
9690
.join(',')})`;
97-
}
9891

99-
if (collectionIds) {
100-
return `${teamIdWhere} collection_id IN (${collectionIds
101-
.map((id) => `'${String(id)}'`)
102-
.join(',')})`;
92+
if ('collectionIds' in props && props.collectionIds) {
93+
return `${teamIdWhere} ${datasetIdWhere} AND collection_id IN (${props.collectionIds
94+
.map((id) => `'${String(id)}'`)
95+
.join(',')})`;
96+
}
97+
98+
return `${teamIdWhere} ${datasetIdWhere}`;
10399
}
104100

105-
if (idList) {
106-
return `${teamIdWhere} id IN (${idList.map((id) => `'${String(id)}'`).join(',')})`;
101+
if ('idList' in props && props.idList) {
102+
return `${teamIdWhere} id IN (${props.idList.map((id) => `'${String(id)}'`).join(',')})`;
107103
}
108104
return Promise.reject('deleteDatasetData: no where');
109105
})();
110-
106+
console.log(where, '===');
111107
try {
112108
await PgClient.delete(PgDatasetTableName, {
113109
where: [where]

packages/service/core/dataset/collection/controller.ts

+50-17
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,37 @@ export function createDefaultCollection({
118118
);
119119
}
120120

121+
/* delete collection related images/files */
122+
export const delCollectionRelatedSource = async ({
123+
collections,
124+
session
125+
}: {
126+
collections: (CollectionWithDatasetType | DatasetCollectionSchemaType)[];
127+
session: ClientSession;
128+
}) => {
129+
if (collections.length === 0) return;
130+
131+
const teamId = collections[0].teamId;
132+
133+
if (!teamId) return Promise.reject('teamId is not exist');
134+
135+
const fileIdList = collections.map((item) => item?.fileId || '').filter(Boolean);
136+
const relatedImageIds = collections
137+
.map((item) => item?.metadata?.relatedImgId || '')
138+
.filter(Boolean);
139+
140+
// delete images
141+
await delImgByRelatedId({
142+
teamId,
143+
relateIds: relatedImageIds,
144+
session
145+
});
146+
// delete files
147+
await delFileByFileIdList({
148+
bucketName: BucketNameEnum.dataset,
149+
fileIdList
150+
});
151+
};
121152
/**
122153
* delete collection and it related data
123154
*/
@@ -134,26 +165,32 @@ export async function delCollectionAndRelatedSources({
134165

135166
if (!teamId) return Promise.reject('teamId is not exist');
136167

168+
const datasetIds = Array.from(
169+
new Set(
170+
collections.map((item) => {
171+
if (typeof item.datasetId === 'string') {
172+
return String(item.datasetId);
173+
}
174+
return String(item.datasetId._id);
175+
})
176+
)
177+
);
137178
const collectionIds = collections.map((item) => String(item._id));
138-
const fileIdList = collections.map((item) => item?.fileId || '').filter(Boolean);
139-
const relatedImageIds = collections
140-
.map((item) => item?.metadata?.relatedImgId || '')
141-
.filter(Boolean);
179+
180+
await delCollectionRelatedSource({ collections, session });
142181

143182
// delete training data
144183
await MongoDatasetTraining.deleteMany({
145184
teamId,
185+
datasetIds: { $in: datasetIds },
146186
collectionId: { $in: collectionIds }
147187
});
148-
149188
// delete dataset.datas
150-
await MongoDatasetData.deleteMany({ teamId, collectionId: { $in: collectionIds } }, { session });
151-
// delete imgs
152-
await delImgByRelatedId({
153-
teamId,
154-
relateIds: relatedImageIds,
155-
session
156-
});
189+
await MongoDatasetData.deleteMany(
190+
{ teamId, datasetIds: { $in: datasetIds }, collectionId: { $in: collectionIds } },
191+
{ session }
192+
);
193+
157194
// delete collections
158195
await MongoDatasetCollection.deleteMany(
159196
{
@@ -163,9 +200,5 @@ export async function delCollectionAndRelatedSources({
163200
);
164201

165202
// no session delete: delete files, vector data
166-
await deleteDatasetDataVector({ teamId, collectionIds });
167-
await delFileByFileIdList({
168-
bucketName: BucketNameEnum.dataset,
169-
fileIdList
170-
});
203+
await deleteDatasetDataVector({ teamId, datasetIds, collectionIds });
171204
}

packages/service/core/dataset/controller.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { CollectionWithDatasetType, DatasetSchemaType } from '@fastgpt/global/core/dataset/type';
22
import { MongoDatasetCollection } from './collection/schema';
33
import { MongoDataset } from './schema';
4-
import { delCollectionAndRelatedSources } from './collection/controller';
4+
import { delCollectionRelatedSource } from './collection/controller';
55
import { ClientSession } from '../../common/mongo';
6+
import { MongoDatasetTraining } from './training/schema';
7+
import { MongoDatasetData } from './data/schema';
8+
import { deleteDatasetDataVector } from '../../common/vectorStore/controller';
69

710
/* ============= dataset ========== */
811
/* find all datasetId by top datasetId */
@@ -82,5 +85,26 @@ export async function delDatasetRelevantData({
8285
'_id teamId fileId metadata'
8386
).lean();
8487

85-
await delCollectionAndRelatedSources({ collections, session });
88+
// image and file
89+
await delCollectionRelatedSource({ collections, session });
90+
91+
// delete training data
92+
await MongoDatasetTraining.deleteMany({
93+
teamId,
94+
datasetId: { $in: datasetIds }
95+
});
96+
// delete dataset.datas
97+
await MongoDatasetData.deleteMany({ teamId, datasetId: { $in: datasetIds } }, { session });
98+
99+
// delete collections
100+
await MongoDatasetCollection.deleteMany(
101+
{
102+
teamId,
103+
datasetId: { $in: datasetIds }
104+
},
105+
{ session }
106+
);
107+
108+
// no session delete: delete files, vector data
109+
await deleteDatasetDataVector({ teamId, datasetIds });
86110
}

packages/service/core/dataset/data/controller.ts

-2
This file was deleted.

packages/service/core/dataset/data/schema.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@ const DatasetDataSchema = new Schema({
7777
});
7878

7979
try {
80-
// list collection and count data; list data
80+
// list collection and count data; list data; delete collection(relate data)
8181
DatasetDataSchema.index(
8282
{ teamId: 1, datasetId: 1, collectionId: 1, chunkIndex: 1, updateTime: -1 },
8383
{ background: true }
8484
);
85-
// same data check
86-
DatasetDataSchema.index({ teamId: 1, collectionId: 1, q: 1, a: 1 }, { background: true });
8785
// full text index
8886
DatasetDataSchema.index({ teamId: 1, datasetId: 1, fullTextToken: 'text' }, { background: true });
8987
// Recall vectors after data matching
90-
DatasetDataSchema.index({ teamId: 1, datasetId: 1, 'indexes.dataId': 1 }, { background: true });
88+
DatasetDataSchema.index(
89+
{ teamId: 1, datasetId: 1, collectionId: 1, 'indexes.dataId': 1 },
90+
{ background: true }
91+
);
9192
DatasetDataSchema.index({ updateTime: 1 }, { background: true });
9293
} catch (error) {
9394
console.log(error);

packages/service/core/dataset/search/controller.ts

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export async function searchDatasetData(props: SearchDatasetDataProps) {
9393
{
9494
teamId,
9595
datasetId: { $in: datasetIds },
96+
collectionId: { $in: results.map((item) => item.collectionId) },
9697
'indexes.dataId': { $in: results.map((item) => item.id?.trim()) }
9798
},
9899
'datasetId collectionId q a chunkIndex indexes'

packages/service/core/dataset/training/controller.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
} from '@fastgpt/global/core/dataset/api.d';
77
import { TrainingModeEnum } from '@fastgpt/global/core/dataset/constants';
88
import { simpleText } from '@fastgpt/global/common/string/tools';
9-
import { countPromptTokens } from '@fastgpt/global/common/string/tiktoken';
109
import { ClientSession } from '../../../common/mongo';
1110
import { getLLMModel, getVectorModel } from '../../ai/model';
1211
import { addLog } from '../../../common/system/log';

0 commit comments

Comments
 (0)