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
9280a21d
authored
Mar 27, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 提示词
parent
650a9dd6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
src/pages/data/detail.tsx
+1
-0
src/service/events/generateAbstract.ts
+13
-8
No files found.
src/pages/data/detail.tsx
View file @
9280a21d
...
@@ -33,6 +33,7 @@ const DataDetail = ({ dataName, dataId }: { dataName: string; dataId: string })
...
@@ -33,6 +33,7 @@ const DataDetail = ({ dataName, dataId }: { dataName: string; dataId: string })
requesting=
{
requesting
}
requesting=
{
requesting
}
nextPage=
{
nextPage
}
nextPage=
{
nextPage
}
fontSize=
{
'xs'
}
fontSize=
{
'xs'
}
whiteSpace=
{
'pre-wrap'
}
>
>
{
dataItems
.
map
((
item
)
=>
(
{
dataItems
.
map
((
item
)
=>
(
<
Box
key=
{
item
.
_id
}
>
<
Box
key=
{
item
.
_id
}
>
...
...
src/service/events/generateAbstract.ts
View file @
9280a21d
...
@@ -12,7 +12,7 @@ export async function generateAbstract(next = false): Promise<any> {
...
@@ -12,7 +12,7 @@ export async function generateAbstract(next = false): Promise<any> {
const
systemPrompt
:
ChatCompletionRequestMessage
=
{
const
systemPrompt
:
ChatCompletionRequestMessage
=
{
role
:
'system'
,
role
:
'system'
,
content
:
`
请从长文本中总结出5至15个摘要,尽量详细,并按以下格式返回: "A:"\n"A:"\n"A:"
\n`
content
:
`
总结助手,我会向你发送一段长文本,请从文本中归纳总结5至15条信息,请直接输出总结内容,并按以下格式输出: 'A1:'\n'A2:'\n'A3:'
\n`
};
};
let
dataItem
:
DataItemSchema
|
null
=
null
;
let
dataItem
:
DataItemSchema
|
null
=
null
;
...
@@ -80,7 +80,7 @@ export async function generateAbstract(next = false): Promise<any> {
...
@@ -80,7 +80,7 @@ export async function generateAbstract(next = false): Promise<any> {
const
rawContent
:
string
=
abstractResponse
?.
data
.
choices
[
0
].
message
?.
content
||
''
;
const
rawContent
:
string
=
abstractResponse
?.
data
.
choices
[
0
].
message
?.
content
||
''
;
// 从 content 中提取摘要内容
// 从 content 中提取摘要内容
const
splitContents
=
splitText
(
rawContent
);
const
splitContents
=
splitText
(
rawContent
);
console
.
log
(
rawContent
);
// 生成词向量
// 生成词向量
const
vectorResponse
=
await
Promise
.
allSettled
(
const
vectorResponse
=
await
Promise
.
allSettled
(
splitContents
.
map
((
item
)
=>
splitContents
.
map
((
item
)
=>
...
@@ -135,17 +135,16 @@ export async function generateAbstract(next = false): Promise<any> {
...
@@ -135,17 +135,16 @@ export async function generateAbstract(next = false): Promise<any> {
rawContent
.
substring
(
0
,
Math
.
floor
(
dataItem
.
text
.
length
/
10
))
// 向量价格是 gpt35 的1/10
rawContent
.
substring
(
0
,
Math
.
floor
(
dataItem
.
text
.
length
/
10
))
// 向量价格是 gpt35 的1/10
});
});
console
.
log
(
console
.
log
(
'生成摘要成功,time:'
,
`生成摘要成功,time:
${(
Date
.
now
()
-
startTime
)
/
1000
}
s`
,
`
${(
Date
.
now
()
-
startTime
)
/
1000
}
s`
,
`摘要匹配数量:
${
splitContents
.
length
}
`
,
'摘要数量:'
,
`有向量摘要数量:
${
vectorSuccessResponse
.
length
}
`
vectorSuccessResponse
.
length
);
);
}
catch
(
error
:
any
)
{
}
catch
(
error
:
any
)
{
console
.
log
(
'error: 生成摘要错误'
,
dataItem
?.
_id
);
console
.
log
(
'error: 生成摘要错误'
,
dataItem
?.
_id
);
console
.
log
(
'response:'
,
error
);
console
.
log
(
'response:'
,
error
);
if
(
dataItem
?.
_id
)
{
if
(
dataItem
?.
_id
)
{
await
DataItem
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
await
DataItem
.
findByIdAndUpdate
(
dataItem
.
_id
,
{
status
:
dataItem
.
times
>
0
?
1
:
0
,
// 还有重试次数则可以继续进行
status
:
dataItem
.
times
>
1
?
1
:
0
,
// 还有重试次数则可以继续进行
$inc
:
{
$inc
:
{
// 剩余尝试次数-1
// 剩余尝试次数-1
times
:
-
1
times
:
-
1
...
@@ -161,7 +160,7 @@ export async function generateAbstract(next = false): Promise<any> {
...
@@ -161,7 +160,7 @@ export async function generateAbstract(next = false): Promise<any> {
* 检查文本是否按格式返回
* 检查文本是否按格式返回
*/
*/
function
splitText
(
text
:
string
)
{
function
splitText
(
text
:
string
)
{
const
regex
=
/A
:
(\s
*
)(
.*
)(\s
*
)
/g
;
const
regex
=
/A
\d
+:
(\s
*
)(
.*
?)\s
*
(?=
A
\d
+:|$
)
/g
s
;
const
matches
=
text
.
matchAll
(
regex
);
// 获取所有匹配到的结果
const
matches
=
text
.
matchAll
(
regex
);
// 获取所有匹配到的结果
const
result
=
[];
// 存储最终的结果
const
result
=
[];
// 存储最终的结果
...
@@ -173,5 +172,11 @@ function splitText(text: string) {
...
@@ -173,5 +172,11 @@ function splitText(text: string) {
}
}
}
}
if
(
result
.
length
===
0
)
{
result
.
push
({
abstract
:
text
});
}
return
result
;
return
result
;
}
}
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