Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
23cc2f81
authored
Sep 01, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: code
parent
68cdf50c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
68 deletions
+61
-68
client/public/locales/zh/common.json
+1
-1
client/src/pages/api/system/getInitData.ts
+2
-0
client/src/pages/kb/detail/index.tsx
+5
-1
client/src/service/events/pushBill.ts
+3
-3
client/src/service/mongo.ts
+3
-27
client/src/service/pg.ts
+26
-0
client/src/service/response.ts
+2
-34
client/src/service/utils/tools.ts
+19
-2
No files found.
client/public/locales/zh/common.json
View file @
23cc2f81
...
@@ -83,7 +83,7 @@
...
@@ -83,7 +83,7 @@
},
},
"dataset"
:
{
"dataset"
:
{
"Confirm to delete the data"
:
"确认删除该数据?"
,
"Confirm to delete the data"
:
"确认删除该数据?"
,
"Queue Desc"
:
"该数据是指整个系统当前待训练的数量。
FastGPT
采用排队训练的方式,如果待训练的数据过多,可能需要等待一段时间"
,
"Queue Desc"
:
"该数据是指整个系统当前待训练的数量。
{{title}}
采用排队训练的方式,如果待训练的数据过多,可能需要等待一段时间"
,
"System Data Queue"
:
"排队长度"
"System Data Queue"
:
"排队长度"
},
},
"file"
:
{
"file"
:
{
...
...
client/src/pages/api/system/getInitData.ts
View file @
23cc2f81
...
@@ -88,6 +88,8 @@ const defaultVectorModels: VectorModelItemType[] = [
...
@@ -88,6 +88,8 @@ const defaultVectorModels: VectorModelItemType[] = [
export
async
function
getInitConfig
()
{
export
async
function
getInitConfig
()
{
try
{
try
{
if
(
global
.
feConfigs
)
return
;
const
filename
=
const
filename
=
process
.
env
.
NODE_ENV
===
'development'
?
'data/config.local.json'
:
'/app/data/config.json'
;
process
.
env
.
NODE_ENV
===
'development'
?
'data/config.local.json'
:
'/app/data/config.json'
;
const
res
=
JSON
.
parse
(
readFileSync
(
filename
,
'utf-8'
));
const
res
=
JSON
.
parse
(
readFileSync
(
filename
,
'utf-8'
));
...
...
client/src/pages/kb/detail/index.tsx
View file @
23cc2f81
...
@@ -22,6 +22,7 @@ import { useTranslation } from 'react-i18next';
...
@@ -22,6 +22,7 @@ import { useTranslation } from 'react-i18next';
import
{
getTrainingQueueLen
}
from
'@/api/plugins/kb'
;
import
{
getTrainingQueueLen
}
from
'@/api/plugins/kb'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
{
QuestionOutlineIcon
}
from
'@chakra-ui/icons'
;
import
{
QuestionOutlineIcon
}
from
'@chakra-ui/icons'
;
import
{
feConfigs
}
from
'@/store/static'
;
const
ImportData
=
dynamic
(()
=>
import
(
'./components/Import'
),
{
const
ImportData
=
dynamic
(()
=>
import
(
'./components/Import'
),
{
ssr
:
false
ssr
:
false
...
@@ -119,7 +120,10 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` }
...
@@ -119,7 +120,10 @@ const Detail = ({ kbId, currentTab }: { kbId: string; currentTab: `${TabEnum}` }
<
Flex
justifyContent=
{
'center'
}
alignItems=
{
'center'
}
>
<
Flex
justifyContent=
{
'center'
}
alignItems=
{
'center'
}
>
<
MyIcon
mr=
{
1
}
name=
"overviewLight"
w=
{
'16px'
}
color=
{
'green.500'
}
/>
<
MyIcon
mr=
{
1
}
name=
"overviewLight"
w=
{
'16px'
}
color=
{
'green.500'
}
/>
<
Box
>
{
t
(
'dataset.System Data Queue'
)
}
</
Box
>
<
Box
>
{
t
(
'dataset.System Data Queue'
)
}
</
Box
>
<
MyTooltip
label=
{
t
(
'dataset.Queue Desc'
)
}
placement=
{
'top'
}
>
<
MyTooltip
label=
{
t
(
'dataset.Queue Desc'
,
{
title
:
feConfigs
?.
systemTitle
})
}
placement=
{
'top'
}
>
<
QuestionOutlineIcon
ml=
{
1
}
w=
{
'16px'
}
/>
<
QuestionOutlineIcon
ml=
{
1
}
w=
{
'16px'
}
/>
</
MyTooltip
>
</
MyTooltip
>
</
Flex
>
</
Flex
>
...
...
client/src/service/events/pushBill.ts
View file @
23cc2f81
...
@@ -72,7 +72,7 @@ export const updateShareChatBill = async ({
...
@@ -72,7 +72,7 @@ export const updateShareChatBill = async ({
}
}
);
);
}
catch
(
err
)
{
}
catch
(
err
)
{
addLog
.
error
(
'update shareChat error'
,
{
err
}
);
addLog
.
error
(
'update shareChat error'
,
err
);
}
}
};
};
...
@@ -111,7 +111,7 @@ export const pushQABill = async ({
...
@@ -111,7 +111,7 @@ export const pushQABill = async ({
$inc
:
{
balance
:
-
total
}
$inc
:
{
balance
:
-
total
}
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
addLog
.
error
(
'Create completions bill error'
,
{
err
}
);
addLog
.
error
(
'Create completions bill error'
,
err
);
billId
&&
Bill
.
findByIdAndDelete
(
billId
);
billId
&&
Bill
.
findByIdAndDelete
(
billId
);
}
}
};
};
...
@@ -160,7 +160,7 @@ export const pushGenerateVectorBill = async ({
...
@@ -160,7 +160,7 @@ export const pushGenerateVectorBill = async ({
$inc
:
{
balance
:
-
total
}
$inc
:
{
balance
:
-
total
}
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
addLog
.
error
(
'Create generateVector bill error'
,
{
err
}
);
addLog
.
error
(
'Create generateVector bill error'
,
err
);
billId
&&
Bill
.
findByIdAndDelete
(
billId
);
billId
&&
Bill
.
findByIdAndDelete
(
billId
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
client/src/service/mongo.ts
View file @
23cc2f81
...
@@ -4,9 +4,8 @@ import { startQueue } from './utils/tools';
...
@@ -4,9 +4,8 @@ import { startQueue } from './utils/tools';
import
{
getInitConfig
}
from
'@/pages/api/system/getInitData'
;
import
{
getInitConfig
}
from
'@/pages/api/system/getInitData'
;
import
{
User
}
from
'./models/user'
;
import
{
User
}
from
'./models/user'
;
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
import
{
connectPg
,
PgClient
}
from
'./pg'
;
import
{
initPg
}
from
'./pg'
;
import
{
createHashPassword
}
from
'@/utils/tools'
;
import
{
createHashPassword
}
from
'@/utils/tools'
;
import
{
PgTrainingTableName
}
from
'@/constants/plugin'
;
import
{
createLogger
,
format
,
transports
}
from
'winston'
;
import
{
createLogger
,
format
,
transports
}
from
'winston'
;
import
'winston-mongodb'
;
import
'winston-mongodb'
;
...
@@ -81,9 +80,9 @@ function initLogger() {
...
@@ -81,9 +80,9 @@ function initLogger() {
format
.
printf
((
info
)
=>
{
format
.
printf
((
info
)
=>
{
if
(
info
.
level
===
'error'
)
{
if
(
info
.
level
===
'error'
)
{
console
.
log
(
info
.
meta
);
console
.
log
(
info
.
meta
);
return
`
${
info
.
level
}
:
${[
info
.
timestamp
]}
:
${
info
.
message
}
`
;
return
`
[
${
info
.
level
.
toLocaleUpperCase
()}
]
:
${[
info
.
timestamp
]}
:
${
info
.
message
}
`
;
}
}
return
`
${
info
.
level
}
:
${[
info
.
timestamp
]}
:
${
info
.
message
}${
return
`
[
${
info
.
level
.
toLocaleUpperCase
()}
]
:
${[
info
.
timestamp
]}
:
${
info
.
message
}${
info
.
meta
?
`:
${
JSON
.
stringify
(
info
.
meta
)}
`
:
''
info
.
meta
?
`:
${
JSON
.
stringify
(
info
.
meta
)}
`
:
''
}
`
;
}
`
;
})
})
...
@@ -123,29 +122,6 @@ async function initRootUser() {
...
@@ -123,29 +122,6 @@ async function initRootUser() {
console
.
log
(
'init root user error'
,
error
);
console
.
log
(
'init root user error'
,
error
);
}
}
}
}
async
function
initPg
()
{
try
{
await
connectPg
();
await
PgClient
.
query
(
`
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS
${
PgTrainingTableName
}
(
id BIGSERIAL PRIMARY KEY,
vector VECTOR(1536) NOT NULL,
user_id VARCHAR(50) NOT NULL,
kb_id VARCHAR(50) NOT NULL,
source VARCHAR(100),
q TEXT NOT NULL,
a TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS modelData_userId_index ON
${
PgTrainingTableName
}
USING HASH (user_id);
CREATE INDEX IF NOT EXISTS modelData_kbId_index ON
${
PgTrainingTableName
}
USING HASH (kb_id);
CREATE INDEX IF NOT EXISTS idx_model_data_md5_q_a_user_id_kb_id ON
${
PgTrainingTableName
}
(md5(q), md5(a), user_id, kb_id);
`
);
console
.
log
(
'init pg successful'
);
}
catch
(
error
)
{
console
.
log
(
'init pg error'
,
error
);
}
}
export
*
from
'./models/chat'
;
export
*
from
'./models/chat'
;
export
*
from
'./models/chatItem'
;
export
*
from
'./models/chatItem'
;
...
...
client/src/service/pg.ts
View file @
23cc2f81
import
{
Pool
}
from
'pg'
;
import
{
Pool
}
from
'pg'
;
import
type
{
QueryResultRow
}
from
'pg'
;
import
type
{
QueryResultRow
}
from
'pg'
;
import
{
PgTrainingTableName
}
from
'@/constants/plugin'
;
import
{
PgTrainingTableName
}
from
'@/constants/plugin'
;
import
{
exit
}
from
'process'
;
import
{
addLog
}
from
'./utils/tools'
;
export
const
connectPg
=
async
():
Promise
<
Pool
>
=>
{
export
const
connectPg
=
async
():
Promise
<
Pool
>
=>
{
if
(
global
.
pgClient
)
{
if
(
global
.
pgClient
)
{
...
@@ -184,3 +186,27 @@ export const insertKbItem = ({
...
@@ -184,3 +186,27 @@ export const insertKbItem = ({
])
])
});
});
};
};
export async function initPg() {
try {
await connectPg();
await PgClient.query(`
CREATE
EXTENSION
IF
NOT
EXISTS
vector
;
CREATE
TABLE
IF
NOT
EXISTS
$
{
PgTrainingTableName
}
(
id
BIGSERIAL
PRIMARY
KEY
,
vector
VECTOR
(
1536
)
NOT
NULL
,
user_id
VARCHAR
(
50
)
NOT
NULL
,
kb_id
VARCHAR
(
50
)
NOT
NULL
,
source
VARCHAR
(
100
),
q
TEXT
NOT
NULL
,
a
TEXT
NOT
NULL
);
CREATE
INDEX
IF
NOT
EXISTS
modelData_userId_index
ON
$
{
PgTrainingTableName
}
USING
HASH
(
user_id
);
CREATE
INDEX
IF
NOT
EXISTS
modelData_kbId_index
ON
$
{
PgTrainingTableName
}
USING
HASH
(
kb_id
);
CREATE
INDEX
IF
NOT
EXISTS
idx_model_data_md5_q_a_user_id_kb_id
ON
$
{
PgTrainingTableName
}
(
md5
(
q
),
md5
(
a
),
user_id
,
kb_id
);
`);
console.log('init pg successful');
} catch (error) {
addLog.error('init pg error', error);
}
}
client/src/service/response.ts
View file @
23cc2f81
...
@@ -53,23 +53,7 @@ export const jsonRes = <T = any>(
...
@@ -53,23 +53,7 @@ export const jsonRes = <T = any>(
msg
=
openaiError
[
error
.
response
.
statusText
];
msg
=
openaiError
[
error
.
response
.
statusText
];
}
}
addLog
.
error
(
msg
,
{
addLog
.
error
(
`response error:
${
msg
}
`
,
error
);
message
:
msg
,
stack
:
error
?.
stack
,
...(
error
?.
config
&&
{
config
:
{
headers
:
error
.
config
.
headers
,
url
:
error
.
config
.
url
,
data
:
error
.
config
.
data
}
}),
...(
error
?.
response
&&
{
response
:
{
status
:
error
.
response
.
status
,
statusText
:
error
.
response
.
statusText
}
})
});
}
}
res
.
status
(
code
).
json
({
res
.
status
(
code
).
json
({
...
@@ -110,23 +94,7 @@ export const sseErrRes = (res: NextApiResponse, error: any) => {
...
@@ -110,23 +94,7 @@ export const sseErrRes = (res: NextApiResponse, error: any) => {
msg
=
openaiError
[
error
.
response
.
statusText
];
msg
=
openaiError
[
error
.
response
.
statusText
];
}
}
addLog
.
error
(
`sse error:
${
msg
}
`
,
{
addLog
.
error
(
`sse error:
${
msg
}
`
,
error
);
message
:
msg
,
stack
:
error
?.
stack
,
...(
error
?.
config
&&
{
config
:
{
headers
:
error
.
config
.
headers
,
url
:
error
.
config
.
url
,
data
:
error
.
config
.
data
}
}),
...(
error
?.
response
&&
{
response
:
{
status
:
error
.
response
.
status
,
statusText
:
error
.
response
.
statusText
}
})
});
sseResponse
({
sseResponse
({
res
,
res
,
...
...
client/src/service/utils/tools.ts
View file @
23cc2f81
...
@@ -94,7 +94,24 @@ export const addLog = {
...
@@ -94,7 +94,24 @@ export const addLog = {
info
:
(
msg
:
string
,
obj
?:
Record
<
string
,
any
>
)
=>
{
info
:
(
msg
:
string
,
obj
?:
Record
<
string
,
any
>
)
=>
{
global
.
logger
?.
info
(
msg
,
{
meta
:
obj
});
global
.
logger
?.
info
(
msg
,
{
meta
:
obj
});
},
},
error
:
(
msg
:
string
,
obj
?:
Record
<
string
,
any
>
)
=>
{
error
:
(
msg
:
string
,
error
?:
any
)
=>
{
global
.
logger
?.
error
(
msg
,
{
meta
:
obj
});
global
.
logger
?.
error
(
msg
,
{
meta
:
{
stack
:
error
?.
stack
,
...(
error
?.
config
&&
{
config
:
{
headers
:
error
.
config
.
headers
,
url
:
error
.
config
.
url
,
data
:
error
.
config
.
data
}
}),
...(
error
?.
response
&&
{
response
:
{
status
:
error
.
response
.
status
,
statusText
:
error
.
response
.
statusText
}
})
}
});
}
}
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment