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
13439c51
authored
Aug 26, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: read file token error
parent
93030afe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
client/src/utils/file.ts
+11
-3
No files found.
client/src/utils/file.ts
View file @
13439c51
...
...
@@ -173,9 +173,16 @@ export const splitText2Chunks = ({ text, maxLen }: { text: string; maxLen: numbe
chunks
.
push
(
chunk
);
}
const
enc
=
getOpenAiEncMap
();
const
encodeText
=
enc
.
encode
(
chunks
.
join
(
''
));
const
tokens
=
encodeText
.
length
;
const
tokens
=
(()
=>
{
try
{
const
enc
=
getOpenAiEncMap
();
const
encodeText
=
enc
.
encode
(
chunks
.
join
(
''
));
const
tokens
=
encodeText
.
length
;
return
tokens
;
}
catch
(
error
)
{
return
chunks
.
join
(
''
).
length
;
}
})();
return
{
chunks
,
...
...
@@ -274,5 +281,6 @@ export const simpleText = (text: string) => {
text
=
text
.
replace
(
/
([\u
4e00-
\u
9fa5
])\s
+
([\u
4e00-
\u
9fa5
])
/g
,
'$1$2'
);
text
=
text
.
replace
(
/
\n{2,}
/g
,
'\n'
);
text
=
text
.
replace
(
/
\s{2,}
/g
,
' '
);
text
=
text
.
replace
(
/
[^\x
00-
\x
7F
]
/g
,
' '
);
return
text
;
};
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