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
1cbcc624
authored
Mar 26, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 正则提取文本,
parent
da31ef28
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
13 deletions
+10
-13
src/pages/data/components/ImportDataModal.tsx
+3
-1
src/service/events/generateQA.ts
+6
-11
src/service/models/dataItem.ts
+1
-1
No files found.
src/pages/data/components/ImportDataModal.tsx
View file @
1cbcc624
...
@@ -102,7 +102,9 @@ const ImportDataModal = ({
...
@@ -102,7 +102,9 @@ const ImportDataModal = ({
}
}
})
})
)
)
).
join
(
'\n'
);
)
.
join
(
'\n'
)
.
replace
(
/
\n
+/g
,
'\n'
);
setFileText
(
fileTexts
);
setFileText
(
fileTexts
);
}
catch
(
error
:
any
)
{
}
catch
(
error
:
any
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
...
src/service/events/generateQA.ts
View file @
1cbcc624
...
@@ -12,12 +12,7 @@ export async function generateQA(next = false): Promise<any> {
...
@@ -12,12 +12,7 @@ export async function generateQA(next = false): Promise<any> {
const
systemPrompt
:
ChatCompletionRequestMessage
=
{
const
systemPrompt
:
ChatCompletionRequestMessage
=
{
role
:
'system'
,
role
:
'system'
,
content
:
`总结助手。我会向你发送一段长文本,请从中总结出10个问题和答案,答案请尽量详细,请按以下格式返回:
content
:
`总结助手。我会向你发送一段长文本,请从中总结出5至15个问题和答案,答案请尽量详细,请按以下格式返回: "Q1:"\n"A1:"\n"Q2:"\n"A2:"\n`
"Q1:"
"A1:"
"Q2:"
"A2:"
`
};
};
let
dataItem
:
DataItemSchema
|
null
=
null
;
let
dataItem
:
DataItemSchema
|
null
=
null
;
...
@@ -34,7 +29,7 @@ export async function generateQA(next = false): Promise<any> {
...
@@ -34,7 +29,7 @@ export async function generateQA(next = false): Promise<any> {
return
;
return
;
}
}
//
减少一次重试次数, 并
更新状态为生成中
// 更新状态为生成中
await
DataItem
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
await
DataItem
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
status
:
2
status
:
2
});
});
...
@@ -86,8 +81,8 @@ export async function generateQA(next = false): Promise<any> {
...
@@ -86,8 +81,8 @@ export async function generateQA(next = false): Promise<any> {
await
DataItem
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
await
DataItem
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
status
:
dataItem
.
temperature
>=
90
?
0
:
1
,
// 需要生成 4 组内容。0,0.3,0.6,0.9
status
:
dataItem
.
temperature
>=
90
?
0
:
1
,
// 需要生成 4 组内容。0,0.3,0.6,0.9
temperature
:
dataItem
.
temperature
>=
90
?
dataItem
.
temperature
:
dataItem
.
temperature
+
30
,
temperature
:
dataItem
.
temperature
>=
90
?
dataItem
.
temperature
:
dataItem
.
temperature
+
30
,
rawResponse
:
content
,
$push
:
{
$push
:
{
rawResponse
:
content
,
result
:
{
result
:
{
$each
:
splitResponse
$each
:
splitResponse
}
}
...
@@ -128,13 +123,13 @@ export async function generateQA(next = false): Promise<any> {
...
@@ -128,13 +123,13 @@ export async function generateQA(next = false): Promise<any> {
* 检查文本是否按格式返回
* 检查文本是否按格式返回
*/
*/
function
splitText
(
text
:
string
)
{
function
splitText
(
text
:
string
)
{
const
regex
=
/Q
\d
+:
\s(
.+
)?\n
A
\d
+:
\s(
.+
)?
/g
;
// 匹配Q和A的正则表达式
const
regex
=
/Q
\d
+:
(\s
*
)(
.*
)(\s
*
)
A
\d
+:
(\s
*
)(
.*
)(\s
*
)
/g
;
// 匹配Q和A的正则表达式
const
matches
=
text
.
matchAll
(
regex
);
// 获取所有匹配到的结果
const
matches
=
text
.
matchAll
(
regex
);
// 获取所有匹配到的结果
const
result
=
[];
// 存储最终的结果
const
result
=
[];
// 存储最终的结果
for
(
const
match
of
matches
)
{
for
(
const
match
of
matches
)
{
const
q
=
match
[
1
];
const
q
=
match
[
2
];
const
a
=
match
[
2
];
const
a
=
match
[
5
];
if
(
q
&&
a
)
{
if
(
q
&&
a
)
{
result
.
push
({
q
,
a
});
// 如果Q和A都存在,就将其添加到结果中
result
.
push
({
q
,
a
});
// 如果Q和A都存在,就将其添加到结果中
}
}
...
...
src/service/models/dataItem.ts
View file @
1cbcc624
...
@@ -26,7 +26,7 @@ const DataItemSchema = new Schema({
...
@@ -26,7 +26,7 @@ const DataItemSchema = new Schema({
},
},
rawResponse
:
{
rawResponse
:
{
type
:
[
String
],
type
:
[
String
],
default
:
''
default
:
[]
},
},
result
:
{
result
:
{
type
:
[
type
:
[
...
...
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