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
2d1ec9b3
authored
May 16, 2024
by
Archer
Committed by
GitHub
May 16, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: token count (#1509)
parent
6067f5af
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
3 additions
and
19 deletions
+3
-19
packages/service/common/string/tiktoken/index.ts
+1
-0
packages/service/worker/tiktoken/countGptMessagesTokens.ts
+1
-0
projects/app/src/middleware.ts
+0
-18
projects/app/src/pages/api/core/ai/token.ts
+1
-1
No files found.
packages/service/common/string/tiktoken/index.ts
View file @
2d1ec9b3
...
@@ -77,6 +77,7 @@ export const countGptMessagesTokens = (
...
@@ -77,6 +77,7 @@ export const countGptMessagesTokens = (
clearTimeout
(
timer
);
clearTimeout
(
timer
);
};
};
// 可以进一步优化(传递100w token数据,实际需要300ms,较慢)
worker
.
postMessage
({
worker
.
postMessage
({
id
,
id
,
messages
,
messages
,
...
...
packages/service/worker/tiktoken/countGptMessagesTokens.ts
View file @
2d1ec9b3
...
@@ -111,6 +111,7 @@ parentPort?.on(
...
@@ -111,6 +111,7 @@ parentPort?.on(
data: total
data: total
});
});
} catch (error) {
} catch (error) {
console.log(error);
parentPort?.postMessage({
parentPort?.postMessage({
id,
id,
type: 'success',
type: 'success',
...
...
projects/app/src/middleware.ts
deleted
100644 → 0
View file @
6067f5af
import
{
addLog
}
from
'@fastgpt/service/common/system/log'
;
import
{
NextResponse
}
from
'next/server'
;
import
type
{
NextRequest
}
from
'next/server'
;
export
function
middleware
(
request
:
NextRequest
)
{
const
response
=
NextResponse
.
next
();
addLog
.
info
(
`Request URL:
${
request
.
url
}
`
,
{
body
:
request
.
body
});
return
response
;
}
// See "Matching Paths" below to learn more
export
const
config
=
{
matcher
:
'/api/:path*'
};
projects/app/src/pages/api/core/ai/token.ts
View file @
2d1ec9b3
...
@@ -16,8 +16,8 @@ async function handler(
...
@@ -16,8 +16,8 @@ async function handler(
req
:
ApiRequestProps
<
tokenBody
,
tokenQuery
>
,
req
:
ApiRequestProps
<
tokenBody
,
tokenQuery
>
,
res
:
ApiResponseType
<
any
>
res
:
ApiResponseType
<
any
>
):
Promise
<
tokenResponse
>
{
):
Promise
<
tokenResponse
>
{
await
authCert
({
req
,
authRoot
:
true
});
const
start
=
Date
.
now
();
const
start
=
Date
.
now
();
await
authCert
({
req
,
authRoot
:
true
});
const
tokens
=
await
countGptMessagesTokens
(
req
.
body
.
messages
);
const
tokens
=
await
countGptMessagesTokens
(
req
.
body
.
messages
);
...
...
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