-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
193 changed files
with
2,120 additions
and
15,778 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ git clone [email protected]:<github_username>/FastGPT.git | |
|
||
- `vectorMaxProcess`: 向量生成最大进程,根据数据库和 key 的并发数来决定,通常单个 120 号,2c4g 服务器设置 10~15。 | ||
- `qaMaxProcess`: QA 生成最大进程 | ||
- `pgIvfflatProbe`: PostgreSQL vector 搜索探针,没有添加 vector 索引时可忽略。 | ||
- `pgHNSWEfSearch`: PostgreSQL vector 索引参数,越大搜索精度越高但是速度越慢,具体可看 pgvector 官方说明。 | ||
|
||
### 5. 运行 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
export default mongoose; | ||
export * from 'mongoose'; | ||
|
||
export const connectionMongo = global.mongodb || mongoose; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import mongoose from './index'; | ||
import 'winston-mongodb'; | ||
import { createLogger, format, transports } from 'winston'; | ||
|
||
/** | ||
* connect MongoDB and init data | ||
*/ | ||
export async function connectMongo({ | ||
beforeHook, | ||
afterHook | ||
}: { | ||
beforeHook?: () => any; | ||
afterHook?: () => any; | ||
}): Promise<void> { | ||
if (global.mongodb) { | ||
return; | ||
} | ||
global.mongodb = mongoose; | ||
|
||
beforeHook && (await beforeHook()); | ||
|
||
// logger | ||
initLogger(); | ||
|
||
console.log('mongo start connect'); | ||
try { | ||
mongoose.set('strictQuery', true); | ||
await mongoose.connect(process.env.MONGODB_URI as string, { | ||
bufferCommands: true, | ||
maxConnecting: Number(process.env.DB_MAX_LINK || 5), | ||
maxPoolSize: Number(process.env.DB_MAX_LINK || 5), | ||
minPoolSize: 2 | ||
}); | ||
|
||
console.log('mongo connected'); | ||
|
||
afterHook && (await afterHook()); | ||
} catch (error) { | ||
console.log('error->', 'mongo connect error', error); | ||
global.mongodb = undefined; | ||
} | ||
} | ||
|
||
function initLogger() { | ||
global.logger = createLogger({ | ||
transports: [ | ||
new transports.MongoDB({ | ||
db: process.env.MONGODB_URI as string, | ||
collection: 'server_logs', | ||
options: { | ||
useUnifiedTopology: true | ||
}, | ||
cappedSize: 500000000, | ||
tryReconnect: true, | ||
metaKey: 'meta', | ||
format: format.combine(format.timestamp(), format.json()) | ||
}), | ||
new transports.Console({ | ||
format: format.combine( | ||
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), | ||
format.printf((info) => { | ||
if (info.level === 'error') { | ||
console.log(info.meta); | ||
return `[${info.level.toLocaleUpperCase()}]: ${[info.timestamp]}: ${info.message}`; | ||
} | ||
return `[${info.level.toLocaleUpperCase()}]: ${[info.timestamp]}: ${info.message}${ | ||
info.meta ? `: ${JSON.stringify(info.meta)}` : '' | ||
}`; | ||
}) | ||
) | ||
}) | ||
] | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
{ | ||
"name": "@fastgpt/common", | ||
"version": "1.0.0" | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"mongoose": "^7.0.2", | ||
"winston": "^3.10.0", | ||
"winston-mongodb": "^5.1.1", | ||
"axios": "^1.5.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.8.5" | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...cts/app/src/service/common/api/plugins.ts → packages/common/plusApi/censor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
import crypto from 'crypto'; | ||
|
||
export function strIsLink(str?: string) { | ||
if (!str) return false; | ||
if (/^((http|https)?:\/\/|www\.|\/)[^\s/$.?#].[^\s]*$/i.test(str)) return true; | ||
return false; | ||
} | ||
|
||
export const hashStr = (psw: string) => { | ||
return crypto.createHash('sha256').update(psw).digest('hex'); | ||
}; | ||
|
||
/* simple text, remove chinese space and extra \n */ | ||
export const simpleText = (text: string) => { | ||
text = text.replace(/([\u4e00-\u9fa5])[\s&&[^\n]]+([\u4e00-\u9fa5])/g, '$1$2'); | ||
text = text.replace(/\n{2,}/g, '\n'); | ||
text = text.replace(/[\s&&[^\n]]{2,}/g, ' '); | ||
text = text.replace(/[\x00-\x08]/g, ' '); | ||
|
||
// replace empty \n | ||
let newText = ''; | ||
let lastChar = ''; | ||
for (let i = 0; i < text.length; i++) { | ||
const currentChar = text[i]; | ||
if (currentChar === '\n' && !/[。?!;.?!;]/g.test(lastChar)) { | ||
} else { | ||
newText += currentChar; | ||
} | ||
lastChar = currentChar; | ||
} | ||
return newText; | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Mongoose } from '../mongo'; | ||
import type { Logger } from 'winston'; | ||
|
||
export type FeConfigsType = { | ||
show_emptyChat?: boolean; | ||
show_register?: boolean; | ||
show_appStore?: boolean; | ||
show_contact?: boolean; | ||
show_git?: boolean; | ||
show_doc?: boolean; | ||
show_pay?: boolean; | ||
show_openai_account?: boolean; | ||
show_promotion?: boolean; | ||
hide_app_flow?: boolean; | ||
openAPIUrl?: string; | ||
systemTitle?: string; | ||
authorText?: string; | ||
googleClientVerKey?: string; | ||
isPlus?: boolean; | ||
oauth?: { | ||
github?: string; | ||
google?: string; | ||
}; | ||
limit?: { | ||
exportLimitMinutes?: number; | ||
}; | ||
scripts?: { [key: string]: string }[]; | ||
}; | ||
|
||
export type SystemEnvType = { | ||
pluginBaseUrl?: string; | ||
openapiPrefix?: string; | ||
vectorMaxProcess: number; | ||
qaMaxProcess: number; | ||
pgHNSWEfSearch: number; | ||
}; | ||
|
||
declare global { | ||
var mongodb: Mongoose | undefined; | ||
var logger: Logger; | ||
var feConfigs: FeConfigsType; | ||
var systemEnv: SystemEnvType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { DatasetTypeEnum } from './constant'; | ||
|
||
export type DatasetSchemaType = { | ||
_id: string; | ||
userId: string; | ||
parentId: string; | ||
updateTime: Date; | ||
avatar: string; | ||
name: string; | ||
vectorModel: string; | ||
tags: string[]; | ||
type: `${DatasetTypeEnum}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.