mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
fix: 46 tmbId empty (#480)
* mongo init * perf: mongo connect * perf: favicon * fix: member id * 46fix sh * doc
This commit is contained in:
@@ -53,3 +53,15 @@ curl --location --request POST 'https://{{host}}/api/admin/initv46-2' \
|
|||||||
4. 新增 - 支持知识库配置文本预处理模型
|
4. 新增 - 支持知识库配置文本预处理模型
|
||||||
5. 线上环境新增 - ReRank向量召回,提高召回精度
|
5. 线上环境新增 - ReRank向量召回,提高召回精度
|
||||||
6. 优化 - 知识库导出,可直接触发流下载,无需等待转圈圈
|
6. 优化 - 知识库导出,可直接触发流下载,无需等待转圈圈
|
||||||
|
|
||||||
|
## 4.6缺陷修复
|
||||||
|
|
||||||
|
旧的 4.6 版本由于缺少一个字段,导致文件导入时知识库数据无法显示,可执行下面的脚本:
|
||||||
|
|
||||||
|
https://xxxxx/api/admin/initv46-fix
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl --location --request POST 'https://{{host}}/api/admin/initv46-fix' \
|
||||||
|
--header 'rootkey: {{rootkey}}' \
|
||||||
|
--header 'Content-Type: application/json'
|
||||||
|
```
|
@@ -101,7 +101,7 @@ function App({ Component, pageProps }: AppProps) {
|
|||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no, viewport-fit=cover"
|
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no, viewport-fit=cover"
|
||||||
/>
|
/>
|
||||||
<link rel="icon" href={feConfigs.favicon || '/favicon.ico'} />
|
<link rel="icon" href={feConfigs.favicon || process.env.SYSTEM_FAVICON} />
|
||||||
</Head>
|
</Head>
|
||||||
{scripts?.map((item, i) => <Script key={i} strategy="lazyOnload" {...item}></Script>)}
|
{scripts?.map((item, i) => <Script key={i} strategy="lazyOnload" {...item}></Script>)}
|
||||||
|
|
||||||
|
@@ -10,6 +10,8 @@ import {
|
|||||||
|
|
||||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||||
import { MongoDatasetData } from '@fastgpt/service/core/dataset/data/schema';
|
import { MongoDatasetData } from '@fastgpt/service/core/dataset/data/schema';
|
||||||
|
import { Types, connectionMongo } from '@fastgpt/service/common/mongo';
|
||||||
|
import { TeamMemberCollectionName } from '@fastgpt/global/support/user/team/constant';
|
||||||
|
|
||||||
let success = 0;
|
let success = 0;
|
||||||
/* pg 中的数据搬到 mongo dataset.datas 中,并做映射 */
|
/* pg 中的数据搬到 mongo dataset.datas 中,并做映射 */
|
||||||
@@ -43,57 +45,59 @@ type PgItemType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async function init(limit: number): Promise<any> {
|
async function init(limit: number): Promise<any> {
|
||||||
const { rows: idList } = await PgClient.query<{ id: string }>(
|
const { rows } = await PgClient.query<{ id: string; data_id: string }>(
|
||||||
`SELECT id FROM ${PgDatasetTableName} WHERE inited=1`
|
`SELECT id,data_id FROM ${PgDatasetTableName} WHERE team_id = tmb_id`
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('totalCount', idList.length);
|
console.log('totalCount', rows.length);
|
||||||
|
|
||||||
await delay(2000);
|
await delay(2000);
|
||||||
|
|
||||||
if (idList.length === 0) return;
|
if (rows.length === 0) return;
|
||||||
|
|
||||||
for (let i = 0; i < limit; i++) {
|
for (let i = 0; i < limit; i++) {
|
||||||
initData(i);
|
initData(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initData(index: number): Promise<any> {
|
async function initData(index: number): Promise<any> {
|
||||||
const dataId = idList[index]?.id;
|
const item = rows[index];
|
||||||
if (!dataId) {
|
if (!item) {
|
||||||
console.log('done');
|
console.log('done');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// get limit data where data_id is null
|
// get mongo
|
||||||
const { rows } = await PgClient.query<PgItemType>(
|
const mongoData = await MongoDatasetData.findById(item.data_id, '_id teamId tmbId');
|
||||||
`SELECT id,q,a,dataset_id,collection_id,data_id FROM ${PgDatasetTableName} WHERE id=${dataId};`
|
if (!mongoData) {
|
||||||
);
|
return initData(index + limit);
|
||||||
const data = rows[0];
|
|
||||||
if (!data) {
|
|
||||||
console.log('done');
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// update mongo data and update inited
|
// find team owner
|
||||||
await MongoDatasetData.findByIdAndUpdate(data.data_id, {
|
const db = connectionMongo?.connection?.db;
|
||||||
q: data.q,
|
const TeamMember = db.collection(TeamMemberCollectionName);
|
||||||
a: data.a,
|
|
||||||
indexes: [
|
const tmb = await TeamMember.findOne({
|
||||||
{
|
teamId: new Types.ObjectId(mongoData.teamId),
|
||||||
defaultIndex: !data.a,
|
role: 'owner'
|
||||||
type: data.a ? DatasetDataIndexTypeEnum.qa : DatasetDataIndexTypeEnum.chunk,
|
|
||||||
dataId: data.id,
|
|
||||||
text: data.q
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
// update pg data_id
|
|
||||||
await PgClient.query(`UPDATE ${PgDatasetTableName} SET inited=0 WHERE id=${dataId};`);
|
if (!tmb) {
|
||||||
|
return initData(index + limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// update mongo and pg tmb_id
|
||||||
|
await MongoDatasetData.findByIdAndUpdate(item.data_id, {
|
||||||
|
tmbId: tmb._id
|
||||||
|
});
|
||||||
|
await PgClient.query(
|
||||||
|
`UPDATE ${PgDatasetTableName} SET tmb_id = '${String(tmb._id)}' WHERE id = '${item.id}'`
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(++success);
|
||||||
|
|
||||||
return initData(index + limit);
|
return initData(index + limit);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
console.log(data);
|
|
||||||
await delay(500);
|
await delay(500);
|
||||||
return initData(index);
|
return initData(index);
|
||||||
}
|
}
|
@@ -29,6 +29,9 @@ export async function insertData2Dataset({
|
|||||||
if (!q || !datasetId || !collectionId || !model) {
|
if (!q || !datasetId || !collectionId || !model) {
|
||||||
return Promise.reject('q, datasetId, collectionId, model is required');
|
return Promise.reject('q, datasetId, collectionId, model is required');
|
||||||
}
|
}
|
||||||
|
if (String(teamId) === String(tmbId)) {
|
||||||
|
return Promise.reject("teamId and tmbId can't be the same");
|
||||||
|
}
|
||||||
|
|
||||||
q = q.trim();
|
q = q.trim();
|
||||||
a = a.trim();
|
a = a.trim();
|
||||||
|
@@ -113,7 +113,7 @@ export async function generateVector(): Promise<any> {
|
|||||||
// insert data to pg
|
// insert data to pg
|
||||||
const { tokenLen } = await insertData2Dataset({
|
const { tokenLen } = await insertData2Dataset({
|
||||||
teamId: data.teamId,
|
teamId: data.teamId,
|
||||||
tmbId: data.teamId,
|
tmbId: data.tmbId,
|
||||||
datasetId: data.datasetId,
|
datasetId: data.datasetId,
|
||||||
collectionId: data.collectionId,
|
collectionId: data.collectionId,
|
||||||
q: dataItem.q,
|
q: dataItem.q,
|
||||||
@@ -124,7 +124,7 @@ export async function generateVector(): Promise<any> {
|
|||||||
// push bill
|
// push bill
|
||||||
pushGenerateVectorBill({
|
pushGenerateVectorBill({
|
||||||
teamId: data.teamId,
|
teamId: data.teamId,
|
||||||
tmbId: data.teamId,
|
tmbId: data.tmbId,
|
||||||
tokenLen: tokenLen,
|
tokenLen: tokenLen,
|
||||||
model: data.model,
|
model: data.model,
|
||||||
billId: data.billId
|
billId: data.billId
|
||||||
|
Reference in New Issue
Block a user