mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-21 11:30:06 +00:00
perf: token count (#1509)
This commit is contained in:
@@ -77,6 +77,7 @@ export const countGptMessagesTokens = (
|
|||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 可以进一步优化(传递100w token数据,实际需要300ms,较慢)
|
||||||
worker.postMessage({
|
worker.postMessage({
|
||||||
id,
|
id,
|
||||||
messages,
|
messages,
|
||||||
|
@@ -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',
|
||||||
|
@@ -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>,
|
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);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user