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
5128bbcc
authored
May 22, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: insert kb data
parent
51a5d450
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
27 deletions
+44
-27
src/pages/api/openapi/kb/pushData.ts
+5
-9
src/pages/api/openapi/text/splitText.ts
+8
-9
src/service/events/generateQA.ts
+5
-9
src/service/pg.ts
+26
-0
No files found.
src/pages/api/openapi/kb/pushData.ts
View file @
5128bbcc
...
@@ -4,7 +4,7 @@ import { jsonRes } from '@/service/response';
...
@@ -4,7 +4,7 @@ import { jsonRes } from '@/service/response';
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
connectToDatabase
}
from
'@/service/mongo'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
generateVector
}
from
'@/service/events/generateVector'
;
import
{
generateVector
}
from
'@/service/events/generateVector'
;
import
{
PgClient
}
from
'@/service/pg'
;
import
{
PgClient
,
insertKbItem
}
from
'@/service/pg'
;
import
{
authKb
}
from
'@/service/utils/auth'
;
import
{
authKb
}
from
'@/service/utils/auth'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
...
@@ -68,14 +68,10 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -68,14 +68,10 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
.
map
<
{
q
:
string
;
a
:
string
}
>
((
item
:
any
)
=>
item
.
value
);
.
map
<
{
q
:
string
;
a
:
string
}
>
((
item
:
any
)
=>
item
.
value
);
// 插入记录
// 插入记录
const
insertRes
=
await
PgClient
.
insert
(
'modelData'
,
{
const
insertRes
=
await
insertKbItem
({
values
:
filterData
.
map
((
item
)
=>
[
userId
,
{
key
:
'user_id'
,
value
:
userId
},
kbId
,
{
key
:
'kb_id'
,
value
:
kbId
},
data
:
filterData
{
key
:
'q'
,
value
:
item
.
q
},
{
key
:
'a'
,
value
:
item
.
a
},
{
key
:
'status'
,
value
:
'waiting'
}
])
});
});
generateVector
();
generateVector
();
...
...
src/pages/api/openapi/text/splitText.ts
View file @
5128bbcc
...
@@ -4,7 +4,7 @@ import { connectToDatabase, SplitData } from '@/service/mongo';
...
@@ -4,7 +4,7 @@ import { connectToDatabase, SplitData } from '@/service/mongo';
import
{
authKb
,
authUser
}
from
'@/service/utils/auth'
;
import
{
authKb
,
authUser
}
from
'@/service/utils/auth'
;
import
{
generateVector
}
from
'@/service/events/generateVector'
;
import
{
generateVector
}
from
'@/service/events/generateVector'
;
import
{
generateQA
}
from
'@/service/events/generateQA'
;
import
{
generateQA
}
from
'@/service/events/generateQA'
;
import
{
PgClient
}
from
'@/service/pg'
;
import
{
insertKbItem
}
from
'@/service/pg'
;
import
{
SplitTextTypEnum
}
from
'@/constants/plugin'
;
import
{
SplitTextTypEnum
}
from
'@/constants/plugin'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
...
@@ -43,14 +43,13 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -43,14 +43,13 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
}
else
if
(
mode
===
SplitTextTypEnum
.
subsection
)
{
}
else
if
(
mode
===
SplitTextTypEnum
.
subsection
)
{
// 待优化,直接调用另一个接口
// 待优化,直接调用另一个接口
// 插入记录
// 插入记录
await
PgClient
.
insert
(
'modelData'
,
{
await
insertKbItem
({
values
:
chunks
.
map
((
item
)
=>
[
userId
,
{
key
:
'user_id'
,
value
:
userId
},
kbId
,
{
key
:
'kb_id'
,
value
:
kbId
},
data
:
chunks
.
map
((
item
)
=>
({
{
key
:
'q'
,
value
:
item
},
q
:
item
,
{
key
:
'a'
,
value
:
''
},
a
:
''
{
key
:
'status'
,
value
:
'waiting'
}
}))
])
});
});
generateVector
();
generateVector
();
...
...
src/service/events/generateQA.ts
View file @
5128bbcc
...
@@ -4,7 +4,7 @@ import { OpenAiChatEnum } from '@/constants/model';
...
@@ -4,7 +4,7 @@ import { OpenAiChatEnum } from '@/constants/model';
import
{
pushSplitDataBill
}
from
'@/service/events/pushBill'
;
import
{
pushSplitDataBill
}
from
'@/service/events/pushBill'
;
import
{
generateVector
}
from
'./generateVector'
;
import
{
generateVector
}
from
'./generateVector'
;
import
{
openaiError2
}
from
'../errorCode'
;
import
{
openaiError2
}
from
'../errorCode'
;
import
{
PgClient
}
from
'@/service/pg'
;
import
{
insertKbItem
}
from
'@/service/pg'
;
import
{
SplitDataSchema
}
from
'@/types/mongoSchema'
;
import
{
SplitDataSchema
}
from
'@/types/mongoSchema'
;
import
{
modelServiceToolMap
}
from
'../utils/chat'
;
import
{
modelServiceToolMap
}
from
'../utils/chat'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
import
{
ChatRoleEnum
}
from
'@/constants/chat'
;
...
@@ -133,14 +133,10 @@ A2:
...
@@ -133,14 +133,10 @@ A2:
textList
:
dataItem
.
textList
.
slice
(
0
,
-
5
)
textList
:
dataItem
.
textList
.
slice
(
0
,
-
5
)
}),
}),
// 生成的内容插入 pg
// 生成的内容插入 pg
PgClient
.
insert
(
'modelData'
,
{
insertKbItem
({
values
:
resultList
.
map
((
item
)
=>
[
userId
:
dataItem
.
userId
,
{
key
:
'user_id'
,
value
:
dataItem
.
userId
},
kbId
:
dataItem
.
kbId
,
{
key
:
'kb_id'
,
value
:
dataItem
.
kbId
},
data
:
resultList
{
key
:
'q'
,
value
:
item
.
q
},
{
key
:
'a'
,
value
:
item
.
a
},
{
key
:
'status'
,
value
:
'waiting'
}
])
})
})
]);
]);
console
.
log
(
'生成QA成功,time:'
,
`
${(
Date
.
now
()
-
startTime
)
/
1000
}
s`
);
console
.
log
(
'生成QA成功,time:'
,
`
${(
Date
.
now
()
-
startTime
)
/
1000
}
s`
);
...
...
src/service/pg.ts
View file @
5128bbcc
...
@@ -156,3 +156,29 @@ class Pg {
...
@@ -156,3 +156,29 @@ class Pg {
}
}
export const PgClient = new Pg();
export const PgClient = new Pg();
/**
* data insert kb
*/
export const insertKbItem = ({
userId,
kbId,
data
}: {
userId: string;
kbId: string;
data: {
q: string;
a: string;
}[];
}) => {
return PgClient.insert('modelData', {
values: data.map((item) => [
{ key: 'user_id', value: userId },
{ key: 'kb_id', value: kbId },
{ key: 'q', value: item.q },
{ key: 'a', value: item.a },
{ key: 'status', value: 'waiting' }
])
});
};
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