mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-03 00:26:40 +08:00
commit
aaf71e2c62
4
.github/workflows/dockerToHub-dev.yml
vendored
4
.github/workflows/dockerToHub-dev.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: build image to aly
|
name: build image to aly
|
||||||
# runs-on: "103.200"
|
# runs-on: "103.200"
|
||||||
runs-on: z4
|
runs-on: thinkpad
|
||||||
# runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
# runs-on: self-hosted
|
# runs-on: self-hosted
|
||||||
steps:
|
steps:
|
||||||
@ -34,7 +34,7 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
name: 部署到dev服务器
|
name: 部署到dev服务器
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: z4
|
runs-on: thinkpad
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
4
.github/workflows/dockerToHub.yml
vendored
4
.github/workflows/dockerToHub.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: build image to aly
|
name: build image to aly
|
||||||
# runs-on: "103.200"
|
# runs-on: "103.200"
|
||||||
runs-on: z4
|
runs-on: thinkpad
|
||||||
# runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
# runs-on: self-hosted
|
# runs-on: self-hosted
|
||||||
steps:
|
steps:
|
||||||
@ -33,7 +33,7 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
name: 部署到服务器
|
name: 部署到服务器
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: z4
|
runs-on: thinkpad
|
||||||
steps:
|
steps:
|
||||||
- name: Check out the repo
|
- name: Check out the repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
@ -21,6 +21,9 @@ RUN # 清理遗留的缓存
|
|||||||
RUN yarn cache clean
|
RUN yarn cache clean
|
||||||
RUN yarn install
|
RUN yarn install
|
||||||
|
|
||||||
|
# 避免下面那个报错
|
||||||
|
RUN mkdir -p "/app/node_modules/tiktoken"
|
||||||
|
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
|
|
||||||
ENV OPENAI_API_KEY=""
|
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/static ./.next/static
|
||||||
COPY --from=builder /app/.next/server ./.next/server
|
COPY --from=builder /app/.next/server ./.next/server
|
||||||
|
|
||||||
|
# 一个插件一直有问题。
|
||||||
|
COPY --from=deps /app/node_modules/tiktoken ./node_modules/tiktoken
|
||||||
|
|
||||||
RUN rm -f .env
|
RUN rm -f .env
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
ENV KEEP_ALIVE_TIMEOUT=30
|
ENV KEEP_ALIVE_TIMEOUT=30
|
||||||
|
ENV HOSTNAME=""
|
||||||
|
|
||||||
CMD if [ -n "$PROXY_URL" ]; then \
|
CMD if [ -n "$PROXY_URL" ]; then \
|
||||||
export HOSTNAME="127.0.0.1"; \
|
export HOSTNAME="127.0.0.1"; \
|
||||||
|
@ -1,7 +1,27 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import prisma from "@/lib/prisma";
|
import prisma from "@/lib/prisma";
|
||||||
import { insertUser } from "@/lib/auth";
|
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(
|
async function handle(
|
||||||
req: NextRequest,
|
req: NextRequest,
|
||||||
@ -13,13 +33,17 @@ async function handle(
|
|||||||
await insertUser({ name: request_data?.userName });
|
await insertUser({ name: request_data?.userName });
|
||||||
}
|
}
|
||||||
// console.log("===========4", request_data);
|
// console.log("===========4", request_data);
|
||||||
if (request_data?.logEntry) {
|
try {
|
||||||
const regex = /\[(.*)]/g;
|
if (request_data?.logEntry) {
|
||||||
const matchResponse = request_data.logEntry.match(regex);
|
const regex = /\[(.*)]/g;
|
||||||
if (matchResponse.length > 0) {
|
const matchResponse = request_data.logEntry.match(regex);
|
||||||
request_data.logToken = getTokenLength(matchResponse[0]);
|
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({
|
await prisma.logEntry.create({
|
||||||
|
@ -77,7 +77,8 @@ async function handle(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const protocol = req.headers.get("x-forwarded-proto") || "http";
|
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);
|
const ip = getIP(req);
|
||||||
// 对其进行 Base64 解码
|
// 对其进行 Base64 解码
|
||||||
let h_userName = req.headers.get("x-request-name");
|
let h_userName = req.headers.get("x-request-name");
|
||||||
|
@ -65,14 +65,16 @@ export default async function UsageByModel() {
|
|||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
const endOfTheDayInTimeZone = new Date(
|
// const endOfTheDayInTimeZone = new Date(
|
||||||
today.getFullYear(),
|
// today.getFullYear(),
|
||||||
today.getMonth(),
|
// today.getMonth(),
|
||||||
today.getDate(),
|
// today.getDate(),
|
||||||
23,
|
// 23,
|
||||||
59,
|
// 59,
|
||||||
59,
|
// 59,
|
||||||
); // 当天的结束时间
|
// ); // 当天的结束时间
|
||||||
|
const endOfTheDayInTimeZone = addHours(startOfTheDayInTimeZone, +24); // 当天的结束时间
|
||||||
|
|
||||||
// const startDate = addHours(startOfTheDayInTimeZone, -8);
|
// const startDate = addHours(startOfTheDayInTimeZone, -8);
|
||||||
// const endDate = addHours(endOfTheDayInTimeZone, -8);
|
// const endDate = addHours(endOfTheDayInTimeZone, -8);
|
||||||
console.log("===", today, startOfTheDayInTimeZone, endOfTheDayInTimeZone);
|
console.log("===", today, startOfTheDayInTimeZone, endOfTheDayInTimeZone);
|
||||||
|
@ -11,8 +11,8 @@ console.log("[Next] build with chunk: ", disableChunk);
|
|||||||
|
|
||||||
// 为了修复tiktoken的插件问题
|
// 为了修复tiktoken的插件问题
|
||||||
import CopyPlugin from "copy-webpack-plugin";
|
import CopyPlugin from "copy-webpack-plugin";
|
||||||
|
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
|
// transpilePackages: ['tiktoken'],
|
||||||
webpack(config) {
|
webpack(config) {
|
||||||
config.module.rules.push({
|
config.module.rules.push({
|
||||||
test: /\.svg$/,
|
test: /\.svg$/,
|
||||||
@ -24,17 +24,22 @@ const nextConfig = {
|
|||||||
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
config.plugins.push(
|
// turn off static file serving of WASM files
|
||||||
new CopyPlugin({
|
// we need to let Webpack handle WASM import
|
||||||
patterns: [
|
// config.module.rules
|
||||||
{
|
// .find((i) => "oneOf" in i)
|
||||||
from: ".//node_modules/tiktoken/tiktoken_bg.wasm",
|
// .oneOf.find((i) => i.type === "asset/resource")
|
||||||
to: "tiktoken_bg.wasm",
|
// .exclude.push(/\.wasm$/);
|
||||||
toType: "file",
|
// config.plugins.push(
|
||||||
}
|
// new CopyPlugin({
|
||||||
]
|
// patterns: [
|
||||||
})
|
// {
|
||||||
)
|
// from: ".//node_modules/tiktoken/,
|
||||||
|
// to: "",
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// })
|
||||||
|
// )
|
||||||
|
|
||||||
config.optimization.minimize = true
|
config.optimization.minimize = true
|
||||||
config.optimization.splitChunks = {
|
config.optimization.splitChunks = {
|
||||||
|
Loading…
Reference in New Issue
Block a user