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
0db413ab
authored
Apr 17, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 文本截取
parent
426eceac
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
10 additions
and
38 deletions
+10
-38
src/pages/api/chat/vectorGpt.ts
+2
-2
src/pages/api/model/data/splitData.ts
+2
-2
src/pages/api/user/payRes.ts
+0
-18
src/pages/chat/index.tsx
+0
-11
src/pages/model/detail/components/SelectFileModal.tsx
+1
-1
src/service/utils/tools.ts
+5
-4
No files found.
src/pages/api/chat/vectorGpt.ts
View file @
0db413ab
...
@@ -116,8 +116,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -116,8 +116,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
});
}
else
{
}
else
{
// 有匹配情况下,添加知识库内容。
// 有匹配情况下,添加知识库内容。
// 系统提示词过滤,最多 2
8
00 tokens
// 系统提示词过滤,最多 2
0
00 tokens
const
systemPrompt
=
systemPromptFilter
(
formatRedisPrompt
,
2
8
00
);
const
systemPrompt
=
systemPromptFilter
(
formatRedisPrompt
,
2
0
00
);
prompts
.
unshift
({
prompts
.
unshift
({
obj
:
'SYSTEM'
,
obj
:
'SYSTEM'
,
...
...
src/pages/api/model/data/splitData.ts
View file @
0db413ab
...
@@ -28,10 +28,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -28,10 +28,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
throw
new
Error
(
'无权操作该模型'
);
throw
new
Error
(
'无权操作该模型'
);
}
}
const
replaceText
=
text
.
replace
(
/
(\\
n|
\n)
+/g
,
'
'
);
const
replaceText
=
text
.
replace
(
/
\\
n/g
,
'\n
'
);
// 文本拆分成 chunk
// 文本拆分成 chunk
const
chunks
=
replaceText
.
match
(
/
[^
!?.。
]
+
[
!?.。
]
/g
)
||
[]
;
const
chunks
=
replaceText
.
split
(
'\n'
).
filter
((
item
)
=>
item
.
trim
())
;
const
textList
:
string
[]
=
[];
const
textList
:
string
[]
=
[];
let
splitText
=
''
;
let
splitText
=
''
;
...
...
src/pages/api/user/payRes.ts
deleted
100644 → 0
View file @
426eceac
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
axios
from
'axios'
;
import
{
connectToDatabase
,
User
,
Pay
}
from
'@/service/mongo'
;
import
{
authToken
}
from
'@/service/utils/tools'
;
import
{
PaySchema
}
from
'@/types/mongoSchema'
;
import
dayjs
from
'dayjs'
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
try
{
res
.
send
(
''
);
}
catch
(
err
)
{
jsonRes
(
res
,
{
code
:
500
,
error
:
err
});
}
}
src/pages/chat/index.tsx
View file @
0db413ab
...
@@ -204,17 +204,6 @@ const Chat = ({ chatId }: { chatId: string }) => {
...
@@ -204,17 +204,6 @@ const Chat = ({ chatId }: { chatId: string }) => {
return
;
return
;
}
}
// 长度校验
const
model
=
modelList
.
find
((
item
)
=>
item
.
model
===
chatData
.
modelName
);
if
(
model
&&
val
.
length
>=
model
.
maxToken
)
{
toast
({
title
:
'单次输入超出 4000 字符'
,
status
:
'warning'
});
return
;
}
const
newChatList
:
ChatSiteItemType
[]
=
[
const
newChatList
:
ChatSiteItemType
[]
=
[
...
chatData
.
history
,
...
chatData
.
history
,
{
{
...
...
src/pages/model/detail/components/SelectFileModal.tsx
View file @
0db413ab
...
@@ -85,7 +85,7 @@ const SelectFileModal = ({
...
@@ -85,7 +85,7 @@ const SelectFileModal = ({
if
(
!
fileText
)
return
;
if
(
!
fileText
)
return
;
await
postModelDataSplitData
({
await
postModelDataSplitData
({
modelId
,
modelId
,
text
:
fileText
,
text
:
fileText
.
replace
(
/
\\
n/g
,
'\n'
).
replace
(
/
\n
+/g
,
'\n'
)
,
prompt
:
`下面是
${
prompt
||
'一段长文本'
}
`
prompt
:
`下面是
${
prompt
||
'一段长文本'
}
`
});
});
toast
({
toast
({
...
...
src/service/utils/tools.ts
View file @
0db413ab
...
@@ -110,12 +110,13 @@ export const openaiChatFilter = (prompts: ChatItemType[], maxTokens: number) =>
...
@@ -110,12 +110,13 @@ export const openaiChatFilter = (prompts: ChatItemType[], maxTokens: number) =>
// 从后往前截取
// 从后往前截取
for
(
let
i
=
formatPrompts
.
length
-
1
;
i
>=
0
;
i
--
)
{
for
(
let
i
=
formatPrompts
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
tokens
=
encode
(
formatPrompts
[
i
].
value
).
length
;
const
tokens
=
encode
(
formatPrompts
[
i
].
value
).
length
;
if
(
maxTokens
>=
tokens
)
{
res
.
unshift
(
formatPrompts
[
i
]);
res
.
unshift
(
formatPrompts
[
i
]);
/* 整体 tokens 超出范围 */
maxTokens
-=
tokens
;
if
(
tokens
>=
maxTokens
)
{
}
else
{
break
;
break
;
}
}
maxTokens
-=
tokens
;
}
}
return
systemPrompt
?
[
systemPrompt
,
...
res
]
:
res
;
return
systemPrompt
?
[
systemPrompt
,
...
res
]
:
res
;
...
...
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