Merge pull request #6 from sijinhui/dev

修复日志图表问题
This commit is contained in:
sijinhui 2023-12-28 18:37:47 +08:00 committed by GitHub
commit aaf71e2c62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 32 deletions

View File

@ -15,7 +15,7 @@ jobs:
build:
name: build image to aly
# runs-on: "103.200"
runs-on: z4
runs-on: thinkpad
# runs-on: ubuntu-latest
# runs-on: self-hosted
steps:
@ -34,7 +34,7 @@ jobs:
deploy:
name: 部署到dev服务器
needs: build
runs-on: z4
runs-on: thinkpad
steps:
- name: Check out the repo
uses: actions/checkout@v3

View File

@ -15,7 +15,7 @@ jobs:
build:
name: build image to aly
# runs-on: "103.200"
runs-on: z4
runs-on: thinkpad
# runs-on: ubuntu-latest
# runs-on: self-hosted
steps:
@ -33,7 +33,7 @@ jobs:
deploy:
name: 部署到服务器
needs: build
runs-on: z4
runs-on: thinkpad
steps:
- name: Check out the repo
uses: actions/checkout@v3

View File

@ -21,6 +21,9 @@ RUN # 清理遗留的缓存
RUN yarn cache clean
RUN yarn install
# 避免下面那个报错
RUN mkdir -p "/app/node_modules/tiktoken"
FROM base AS builder
ENV OPENAI_API_KEY=""
@ -48,10 +51,14 @@ COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/.next/server ./.next/server
# 一个插件一直有问题。
COPY --from=deps /app/node_modules/tiktoken ./node_modules/tiktoken
RUN rm -f .env
EXPOSE 3000
ENV KEEP_ALIVE_TIMEOUT=30
ENV HOSTNAME=""
CMD if [ -n "$PROXY_URL" ]; then \
export HOSTNAME="127.0.0.1"; \

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,
@ -13,13 +33,17 @@ async function handle(
await insertUser({ name: request_data?.userName });
}
// console.log("===========4", request_data);
if (request_data?.logEntry) {
const regex = /\[(.*)]/g;
const matchResponse = request_data.logEntry.match(regex);
if (matchResponse.length > 0) {
request_data.logToken = getTokenLength(matchResponse[0]);
try {
if (request_data?.logEntry) {
const regex = /\[(.*)]/g;
const matchResponse = request_data.logEntry.match(regex);
if (matchResponse.length > 0) {
request_data.logToken = getTokenLength(matchResponse[0]);
}
}
// console.log('=======', request_data.logEntry, '=====', matchResponse);
} catch (e) {
console.log("[LOG]", "logToken", e);
request_data.logToken = 0;
}
await prisma.logEntry.create({

View File

@ -77,7 +77,8 @@ async function handle(
try {
const protocol = req.headers.get("x-forwarded-proto") || "http";
const baseUrl = process.env.NEXTAUTH_URL ?? "http://localhost:3000";
//const baseUrl = process.env.NEXTAUTH_URL ?? "http://localhost:3000";
const baseUrl = "http://localhost:3000";
const ip = getIP(req);
// 对其进行 Base64 解码
let h_userName = req.headers.get("x-request-name");

View File

@ -65,14 +65,16 @@ export default async function UsageByModel() {
0,
0,
);
const endOfTheDayInTimeZone = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate(),
23,
59,
59,
); // 当天的结束时间
// const endOfTheDayInTimeZone = new Date(
// today.getFullYear(),
// today.getMonth(),
// today.getDate(),
// 23,
// 59,
// 59,
// ); // 当天的结束时间
const endOfTheDayInTimeZone = addHours(startOfTheDayInTimeZone, +24); // 当天的结束时间
// const startDate = addHours(startOfTheDayInTimeZone, -8);
// const endDate = addHours(endOfTheDayInTimeZone, -8);
console.log("===", today, startOfTheDayInTimeZone, endOfTheDayInTimeZone);

View File

@ -11,8 +11,8 @@ console.log("[Next] build with chunk: ", disableChunk);
// 为了修复tiktoken的插件问题
import CopyPlugin from "copy-webpack-plugin";
const nextConfig = {
// transpilePackages: ['tiktoken'],
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
@ -24,17 +24,22 @@ const nextConfig = {
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
)
}
config.plugins.push(
new CopyPlugin({
patterns: [
{
from: ".//node_modules/tiktoken/tiktoken_bg.wasm",
to: "tiktoken_bg.wasm",
toType: "file",
}
]
})
)
// turn off static file serving of WASM files
// we need to let Webpack handle WASM import
// config.module.rules
// .find((i) => "oneOf" in i)
// .oneOf.find((i) => i.type === "asset/resource")
// .exclude.push(/\.wasm$/);
// config.plugins.push(
// new CopyPlugin({
// patterns: [
// {
// from: ".//node_modules/tiktoken/,
// to: "",
// }
// ]
// })
// )
config.optimization.minimize = true
config.optimization.splitChunks = {