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
2ae8d432
authored
Aug 31, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: reg failed
parent
0ea464f3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
20 deletions
+25
-20
client/src/constants/common.ts
+5
-5
client/src/pages/kb/detail/components/Import/FileSelect.tsx
+14
-14
client/src/service/events/generateQA.ts
+6
-1
No files found.
client/src/constants/common.ts
View file @
2ae8d432
...
@@ -6,11 +6,11 @@ export enum UserAuthTypeEnum {
...
@@ -6,11 +6,11 @@ export enum UserAuthTypeEnum {
export
const
PRICE_SCALE
=
100000
;
export
const
PRICE_SCALE
=
100000
;
export
const
fileImgs
=
[
export
const
fileImgs
=
[
{
reg
:
/pdf/gi
,
src
:
'/imgs/files/pdf.svg'
},
{
suffix
:
'pdf'
,
src
:
'/imgs/files/pdf.svg'
},
{
reg
:
/csv/gi
,
src
:
'/imgs/files/csv.svg'
},
{
suffix
:
'csv'
,
src
:
'/imgs/files/csv.svg'
},
{
reg
:
/
(
doc|docs
)
/gi
,
src
:
'/imgs/files/doc.svg'
},
{
suffix
:
'(doc|docs)'
,
src
:
'/imgs/files/doc.svg'
},
{
reg
:
/txt/gi
,
src
:
'/imgs/files/txt.svg'
},
{
suffix
:
'txt'
,
src
:
'/imgs/files/txt.svg'
},
{
reg
:
/md/gi
,
src
:
'/imgs/files/markdown.svg'
}
{
suffix
:
'md'
,
src
:
'/imgs/files/markdown.svg'
}
];
];
export
const
htmlTemplate
=
`<!DOCTYPE html>
export
const
htmlTemplate
=
`<!DOCTYPE html>
...
...
client/src/pages/kb/detail/components/Import/FileSelect.tsx
View file @
2ae8d432
...
@@ -76,13 +76,18 @@ const FileSelect = ({
...
@@ -76,13 +76,18 @@ const FileSelect = ({
setSelecting
(
true
);
setSelecting
(
true
);
try
{
try
{
// Parse file by file
// Parse file by file
let
promise
=
Promise
.
resolve
<
FileItemType
[]
>
([])
;
const
chunkFiles
:
FileItemType
[]
=
[]
;
files
.
forEach
((
file
)
=>
{
promise
=
promise
.
then
(
async
(
result
)
=>
{
for
await
(
let
file
of
files
)
{
const
extension
=
file
?.
name
?.
split
(
'.'
)?.
pop
()?.
toLowerCase
();
const
extension
=
file
?.
name
?.
split
(
'.'
)?.
pop
()?.
toLowerCase
();
/* text file */
/* text file */
const
icon
=
fileImgs
.
find
((
item
)
=>
new
RegExp
(
item
.
reg
).
test
(
file
.
name
))?.
src
;
const
icon
=
fileImgs
.
find
((
item
)
=>
new
RegExp
(
item
.
suffix
,
'gi'
).
test
(
file
.
name
))?.
src
;
if
(
!
icon
)
{
continue
;
}
let
text
=
await
(
async
()
=>
{
let
text
=
await
(
async
()
=>
{
switch
(
extension
)
{
switch
(
extension
)
{
case
'txt'
:
case
'txt'
:
...
@@ -97,8 +102,6 @@ const FileSelect = ({
...
@@ -97,8 +102,6 @@ const FileSelect = ({
return
''
;
return
''
;
})();
})();
if
(
!
icon
)
return
result
;
if
(
text
)
{
if
(
text
)
{
text
=
simpleText
(
text
);
text
=
simpleText
(
text
);
const
splitRes
=
splitText2Chunks
({
const
splitRes
=
splitText2Chunks
({
...
@@ -117,7 +120,8 @@ const FileSelect = ({
...
@@ -117,7 +120,8 @@ const FileSelect = ({
source
:
file
.
name
source
:
file
.
name
}))
}))
};
};
return
[
fileItem
].
concat
(
result
);
chunkFiles
.
unshift
(
fileItem
);
continue
;
}
}
/* csv file */
/* csv file */
...
@@ -138,14 +142,10 @@ const FileSelect = ({
...
@@ -138,14 +142,10 @@ const FileSelect = ({
source
:
item
[
2
]
||
file
.
name
source
:
item
[
2
]
||
file
.
name
}))
}))
};
};
return
[
fileItem
].
concat
(
result
);
}
return
result
;
});
});
const
chunkFiles
=
await
promise
;
chunkFiles
.
unshift
(
fileItem
);
}
}
onPushFiles
(
chunkFiles
);
onPushFiles
(
chunkFiles
);
}
catch
(
error
:
any
)
{
}
catch
(
error
:
any
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
...
client/src/service/events/generateQA.ts
View file @
2ae8d432
...
@@ -9,6 +9,7 @@ import { axiosConfig, getAIChatApi } from '../ai/openai';
...
@@ -9,6 +9,7 @@ import { axiosConfig, getAIChatApi } from '../ai/openai';
import
{
ChatCompletionRequestMessage
}
from
'openai'
;
import
{
ChatCompletionRequestMessage
}
from
'openai'
;
import
{
modelToolMap
}
from
'@/utils/plugin'
;
import
{
modelToolMap
}
from
'@/utils/plugin'
;
import
{
gptMessage2ChatType
}
from
'@/utils/adapt'
;
import
{
gptMessage2ChatType
}
from
'@/utils/adapt'
;
import
{
addLog
}
from
'../utils/tools'
;
const
reduceQueue
=
()
=>
{
const
reduceQueue
=
()
=>
{
global
.
qaQueueLen
=
global
.
qaQueueLen
>
0
?
global
.
qaQueueLen
-
1
:
0
;
global
.
qaQueueLen
=
global
.
qaQueueLen
>
0
?
global
.
qaQueueLen
-
1
:
0
;
...
@@ -105,12 +106,16 @@ A2:
...
@@ -105,12 +106,16 @@ A2:
const
result
=
formatSplitText
(
answer
||
''
);
// 格式化后的QA对
const
result
=
formatSplitText
(
answer
||
''
);
// 格式化后的QA对
console
.
log
(
`split result length: `
,
result
.
length
);
console
.
log
(
`split result length: `
,
result
.
length
);
// 计费
// 计费
result
.
length
>
0
&&
if
(
result
.
length
>
0
)
{
pushQABill
({
pushQABill
({
userId
:
data
.
userId
,
userId
:
data
.
userId
,
totalTokens
,
totalTokens
,
appName
:
'QA 拆分'
appName
:
'QA 拆分'
});
});
}
else
{
addLog
.
info
(
`QA result 0:`
,
{
answer
});
}
return
{
return
{
rawContent
:
answer
,
rawContent
:
answer
,
result
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