mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
perf: token count (#1509)
This commit is contained in:
@@ -77,6 +77,7 @@ export const countGptMessagesTokens = (
|
||||
clearTimeout(timer);
|
||||
};
|
||||
|
||||
// 可以进一步优化(传递100w token数据,实际需要300ms,较慢)
|
||||
worker.postMessage({
|
||||
id,
|
||||
messages,
|
||||
|
@@ -111,6 +111,7 @@ parentPort?.on(
|
||||
data: total
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
parentPort?.postMessage({
|
||||
id,
|
||||
type: 'success',
|
||||
|
@@ -1,18 +0,0 @@
|
||||
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*'
|
||||
};
|
@@ -16,8 +16,8 @@ async function handler(
|
||||
req: ApiRequestProps<tokenBody, tokenQuery>,
|
||||
res: ApiResponseType<any>
|
||||
): Promise<tokenResponse> {
|
||||
await authCert({ req, authRoot: true });
|
||||
const start = Date.now();
|
||||
await authCert({ req, authRoot: true });
|
||||
|
||||
const tokens = await countGptMessagesTokens(req.body.messages);
|
||||
|
||||
|
Reference in New Issue
Block a user