修复日志图表的问题

This commit is contained in:
sijinhui
2023-12-28 18:34:47 +08:00
parent b0e56e17c7
commit 3a92a1b8d1
3 changed files with 44 additions and 13 deletions

View File

@@ -1,7 +1,27 @@
import { NextRequest, NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import { insertUser } from "@/lib/auth";
import { getTokenLength } from "@/app/utils/token";
// import { getTokenLength } from "@/app/utils/token";
// import { Tiktoken } from "tiktoken/lite"
// import cl100k_base from "tiktoken/encoders/cl100k_base.json"
import "tiktoken";
import { get_encoding } from "tiktoken";
function getTokenLength(input: string): number {
// const { Tiktoken } = require("tiktoken/lite");
// const cl100k_base = require("tiktoken/encoders/cl100k_base.json");
// const encoding = new Tiktoken(
// cl100k_base.bpe_ranks,
// cl100k_base.special_tokens,
// cl100k_base.pat_str,
// );
const encoding = get_encoding("cl100k_base");
const tokenLength = encoding.encode(input).length;
// console.log('[TOKEN],=========', input, tokenLength)
return tokenLength;
}
async function handle(
req: NextRequest,