From 6a004421fc64a882f85ca56385dcdecfe59bc7fb Mon Sep 17 00:00:00 2001 From: sijinhui Date: Sat, 4 May 2024 11:48:16 +0800 Subject: [PATCH 01/11] test pack --- .github/workflows/dockerToHub-dev.yml | 2 +- .github/workflows/dockerToHub-dev.yml.bak | 109 ++++++++++++++++++++++ Dockerfile | 91 +++++++++--------- Dockerfile.linux-build | 83 ++++++++++++++++ next.config.mjs | 15 ++- package.json | 2 + 6 files changed, 254 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/dockerToHub-dev.yml.bak create mode 100644 Dockerfile.linux-build diff --git a/.github/workflows/dockerToHub-dev.yml b/.github/workflows/dockerToHub-dev.yml index 053e289b1..60ab7ffa3 100644 --- a/.github/workflows/dockerToHub-dev.yml +++ b/.github/workflows/dockerToHub-dev.yml @@ -23,7 +23,7 @@ jobs: echo ${{ secrets.ALY_DOCKER_PASSWORD }} | docker login registry.cn-hangzhou.aliyuncs.com -u ${{ secrets.ALY_DOCKER_USERNAME }} --password-stdin echo "${{ secrets.DOCKER_ENV }}" > .env echo "COMPOSE_PROJECT_NAME=test-chatgpt-web" >> .env - bash ./start.sh + #bash ./start.sh # 替换测试镜像 sed -i 's@image: registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web@image: registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:test@g' docker-compose.yml sed -i 's|23000:|23001:|g' docker-compose.yml diff --git a/.github/workflows/dockerToHub-dev.yml.bak b/.github/workflows/dockerToHub-dev.yml.bak new file mode 100644 index 000000000..053e289b1 --- /dev/null +++ b/.github/workflows/dockerToHub-dev.yml.bak @@ -0,0 +1,109 @@ +name: DEV DEPLOY TO TX +on: + workflow_dispatch: +# push: +# branches: +# - dev + +jobs: + build: + name: build test image to aly + # runs-on: thinkpad + runs-on: self + # runs-on: self-hosted + steps: + - name: Check out the repo + uses: actions/checkout@v4 + with: + ref: 'dev' + clean: false + github-server-url: 'https://gh.siji.ci' + - name: build and deploy to Docker Hub + run: | + echo ${{ secrets.ALY_DOCKER_PASSWORD }} | docker login registry.cn-hangzhou.aliyuncs.com -u ${{ secrets.ALY_DOCKER_USERNAME }} --password-stdin + echo "${{ secrets.DOCKER_ENV }}" > .env + echo "COMPOSE_PROJECT_NAME=test-chatgpt-web" >> .env + bash ./start.sh + # 替换测试镜像 + sed -i 's@image: registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web@image: registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:test@g' docker-compose.yml + sed -i 's|23000:|23001:|g' docker-compose.yml + docker-compose build + docker-compose push + yes | docker system prune --filter "until=168h" + deploy: + name: 部署到dev服务器 + runs-on: self + needs: build + steps: + - name: Check out the repo + uses: actions/checkout@v4 + with: + clean: true + ref: 'dev' + github-server-url: 'https://gh.siji.ci' + - name: Set up SSH key + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + - name: Sync repository to tx + run: | + yes | docker image prune + ssh -o StrictHostKeyChecking=no -p${{ secrets.SSH_PORT }} root@${{ secrets.TX_SSH_IP }} 'mkdir -p /data/test/ChatGPT-Next-Web' + rsync -az -e 'ssh -o StrictHostKeyChecking=no -p${{ secrets.SSH_PORT }}' --delete $GITHUB_WORKSPACE/ root@tx.xiaosi.cc:/data/test/ChatGPT-Next-Web + - name: deploy-to-tx + uses: appleboy/ssh-action@master + env: + SERVER_WORKDIR: ${{ secrets.SERVER_WORKDIR }} #传递工作目录变量 + with: + host: ${{ secrets.TX_SSH_IP }} #服务器地址 + username: root #用户名 + port: ${{ secrets.SSH_PORT }} + key: ${{ secrets.SSH_PRIVATE_KEY }} #私钥 安全问题一定都以变量的方式传递!!! + envs: SERVER_WORKDIR,ALY_DOCKER_PASSWORD,ALY_DOCKER_USERNAME,DOCKER_ENV #使用工作目录变量 + script: | + cd /data/test/ChatGPT-Next-Web + echo "${{ secrets.DOCKER_ENV }}" > .env + # 测试分支, + echo "COMPOSE_PROJECT_NAME=test-chatgpt-web" >> .env + sed -i 's@image: registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web@image: registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:test@g' docker-compose.yml + echo ${{ secrets.ALY_DOCKER_PASSWORD }} | docker login registry.cn-hangzhou.aliyuncs.com -u ${{ secrets.ALY_DOCKER_USERNAME }} --password-stdin + sed -i 's|23000:|23001:|g' docker-compose.yml + sed -i 's|container_name:|#container_name:|g' docker-compose.yml + docker network ls | grep -qw chatgpt-ns || docker network create chatgpt-ns + docker-compose pull && docker-compose up -d + yes | docker image prune + rm -rf /www/server/nginx/proxy_cache_dir/* || true + rm -rf /www/server/nginx/proxy_temp_dir/* || true + + + - name: Sync repository to xy-nm + run: | + yes | docker image prune + ssh -o StrictHostKeyChecking=no -p${{ secrets.SSH_PORT }} root@${{ secrets.NM_SSH_IP }} 'mkdir -p /data/test/ChatGPT-Next-Web' + rsync -az -e 'ssh -o StrictHostKeyChecking=no -p${{ secrets.SSH_PORT }}' --delete $GITHUB_WORKSPACE/ root@xy-nm.xiaosi.cc:/data/test/ChatGPT-Next-Web + - name: deploy-to-xy-nm + uses: appleboy/ssh-action@master + env: + SERVER_WORKDIR: ${{ secrets.SERVER_WORKDIR }} #传递工作目录变量 + with: + host: ${{ secrets.NM_SSH_IP }} #服务器地址 + username: root #用户名 + port: ${{ secrets.SSH_PORT }} + key: ${{ secrets.SSH_PRIVATE_KEY }} #私钥 安全问题一定都以变量的方式传递!!! + envs: SERVER_WORKDIR,ALY_DOCKER_PASSWORD,ALY_DOCKER_USERNAME,DOCKER_ENV #使用工作目录变量 + script: | + cd /data/test/ChatGPT-Next-Web + echo "${{ secrets.DOCKER_ENV }}" > .env + # 测试分支, + echo "COMPOSE_PROJECT_NAME=test-chatgpt-web" >> .env + sed -i 's@image: registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web@image: registry.cn-hangzhou.aliyuncs.com/si-private/chatgpt-next-web:test@g' docker-compose.yml + echo ${{ secrets.ALY_DOCKER_PASSWORD }} | docker login registry.cn-hangzhou.aliyuncs.com -u ${{ secrets.ALY_DOCKER_USERNAME }} --password-stdin + sed -i 's|23000:|23001:|g' docker-compose.yml + sed -i 's|container_name:|#container_name:|g' docker-compose.yml + docker network ls | grep -qw chatgpt-ns || docker network create chatgpt-ns + docker-compose pull && docker-compose up -d + yes | docker image prune + rm -rf /www/server/nginx/proxy_cache_dir/* || true + rm -rf /www/server/nginx/proxy_temp_dir/* || true + + diff --git a/Dockerfile b/Dockerfile index c35822a35..cd15a087e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,59 +1,60 @@ #FROM registry.cn-hangzhou.aliyuncs.com/sijinhui/node:18-alpine AS base FROM hub.siji.ci/library/node:20-alpine AS base RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories -RUN apk update && apk add --no-cache git tzdata +RUN apk update && apk add --no-cache git tzdata vips-dev # 设置时区环境变量 ENV TZ=Asia/Chongqing # 更新并安装时区工具 RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -#FROM base AS deps -#RUN apk add --no-cache libc6-compat g++ make -# -#WORKDIR /app -# -#COPY package.json ./ -# -#RUN yarn config set registry 'https://registry.npmmirror.com/' -#RUN yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp" -#RUN yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips" +FROM base AS deps +RUN apk add --no-cache libc6-compat g++ make + +WORKDIR /app + +COPY package.json ./ + +RUN yarn config set registry 'https://registry.npmmirror.com/' +RUN yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp" +RUN yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips" #RUN # 清理遗留的缓存 -#RUN yarn cache clean -#RUN yarn install -# -## 避免下面那个报错 -#RUN mkdir -p "/app/node_modules/tiktoken" -# -#FROM base AS builder -# -#ENV OPENAI_API_KEY="" -#ENV GOOGLE_API_KEY="" -#ENV CODE="" -# -#WORKDIR /app -#COPY . . -#COPY --from=deps /app/node_modules ./node_modules -# -#RUN yarn build -# +RUN yarn cache clean +RUN yarn install + +FROM base AS builder + +ENV OPENAI_API_KEY="" +ENV GOOGLE_API_KEY="" +ENV CODE="" + +WORKDIR /app +COPY . . +COPY --from=deps /app/node_modules ./node_modules +# 避免下面那个报错 +RUN mkdir -p "/app/node_modules/tiktoken" +RUN mkdir -p "/app/node_modules/sharp" + +RUN yarn build + FROM base AS runner WORKDIR /app -# -#RUN apk add proxychains-ng -# -#ENV PROXY_URL="" -#ENV OPENAI_API_KEY="" -#ENV GOOGLE_API_KEY="" -#ENV CODE="" -# -#COPY --from=builder /app/public ./public -#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 -COPY out/ . + +RUN apk add proxychains-ng + +ENV PROXY_URL="" +ENV OPENAI_API_KEY="" +ENV GOOGLE_API_KEY="" +ENV CODE="" + +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/.next/server ./.next/server + +# 一个插件一直有问题。 +COPY --from=builder /app/node_modules/tiktoken ./node_modules/tiktoken +COPY --from=builder /app/node_modules/sharp ./node_modules/sharp +#COPY out/ . RUN rm -f .env diff --git a/Dockerfile.linux-build b/Dockerfile.linux-build new file mode 100644 index 000000000..c35822a35 --- /dev/null +++ b/Dockerfile.linux-build @@ -0,0 +1,83 @@ +#FROM registry.cn-hangzhou.aliyuncs.com/sijinhui/node:18-alpine AS base +FROM hub.siji.ci/library/node:20-alpine AS base +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories +RUN apk update && apk add --no-cache git tzdata +# 设置时区环境变量 +ENV TZ=Asia/Chongqing +# 更新并安装时区工具 +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +#FROM base AS deps +#RUN apk add --no-cache libc6-compat g++ make +# +#WORKDIR /app +# +#COPY package.json ./ +# +#RUN yarn config set registry 'https://registry.npmmirror.com/' +#RUN yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp" +#RUN yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips" +#RUN # 清理遗留的缓存 +#RUN yarn cache clean +#RUN yarn install +# +## 避免下面那个报错 +#RUN mkdir -p "/app/node_modules/tiktoken" +# +#FROM base AS builder +# +#ENV OPENAI_API_KEY="" +#ENV GOOGLE_API_KEY="" +#ENV CODE="" +# +#WORKDIR /app +#COPY . . +#COPY --from=deps /app/node_modules ./node_modules +# +#RUN yarn build +# +FROM base AS runner +WORKDIR /app +# +#RUN apk add proxychains-ng +# +#ENV PROXY_URL="" +#ENV OPENAI_API_KEY="" +#ENV GOOGLE_API_KEY="" +#ENV CODE="" +# +#COPY --from=builder /app/public ./public +#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 +COPY out/ . + +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"; \ + protocol=$(echo $PROXY_URL | cut -d: -f1); \ + host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \ + port=$(echo $PROXY_URL | cut -d: -f3); \ + conf=/etc/proxychains.conf; \ + echo "strict_chain" > $conf; \ + echo "proxy_dns" >> $conf; \ + echo "remote_dns_subnet 224" >> $conf; \ + echo "tcp_read_time_out 15000" >> $conf; \ + echo "tcp_connect_time_out 8000" >> $conf; \ + echo "localnet 127.0.0.0/255.0.0.0" >> $conf; \ + echo "localnet ::1/128" >> $conf; \ + echo "[ProxyList]" >> $conf; \ + echo "$protocol $host $port" >> $conf; \ + cat /etc/proxychains.conf; \ + proxychains -f $conf node server.js; \ + else \ + node server.js; \ + fi diff --git a/next.config.mjs b/next.config.mjs index 736a714b1..0c75dedc2 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,12 @@ import webpack from "webpack"; +// debug build +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); +const withBundleAnalyzer = require('@next/bundle-analyzer')({ + enabled: process.env.ANALYZE === 'true', +}); + + // import CssMinimizerPlugin from "css-minimizer-webpack-plugin"; const mode = process.env.BUILD_MODE ?? "standalone"; console.log("[Next] build mode", mode); @@ -11,7 +19,7 @@ console.log("[Next] build with chunk: ", disableChunk); // const isProd = process.env.NODE_ENV === 'production' // 为了修复tiktoken的插件问题 -const nextConfig = { +const nextConfig = withBundleAnalyzer({ // transpilePackages: ['tiktoken'], webpack(config) { config.module.rules.push({ @@ -81,8 +89,11 @@ const nextConfig = { experimental: { forceSwcTransforms: true, }, + // externals: { + // 'sharp': 'commonjs sharp' + // }, swcMinify: true, -}; +}); const CorsHeaders = [ { key: "Access-Control-Allow-Credentials", value: "true" }, diff --git a/package.json b/package.json index a05221076..e161f1d69 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "zustand": "^4.5.0" }, "devDependencies": { + "@next/bundle-analyzer": "^14.2.3", "@tauri-apps/cli": "1.5.11", "@types/bcryptjs": "^2.4.6", "@types/cookie": "^0.6.0", @@ -82,6 +83,7 @@ "prettier": "^3.2.4", "prettier-plugin-tailwindcss": "^0.5.11", "prisma": "^5.13.0", + "speed-measure-webpack-plugin": "^1.5.0", "tailwindcss": "^3.4.1", "tailwindcss-animate": "^1.0.7", "typescript": "^5.3.3", From 14faccb1a63a2098b5da4099befd962fbf50777a Mon Sep 17 00:00:00 2001 From: sijinhui Date: Sat, 4 May 2024 12:39:19 +0800 Subject: [PATCH 02/11] test pack --- Dockerfile | 14 ++++++++++---- package.json | 6 ++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index cd15a087e..ca27bc04e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,13 @@ #FROM registry.cn-hangzhou.aliyuncs.com/sijinhui/node:18-alpine AS base FROM hub.siji.ci/library/node:20-alpine AS base RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories -RUN apk update && apk add --no-cache git tzdata vips-dev +RUN apk update && apk add --no-cache git tzdata +RUN apk add --no-cache \ + vips-dev \ + fftw-dev \ + glib-dev \ + glib \ + expat-dev # 设置时区环境变量 ENV TZ=Asia/Chongqing # 更新并安装时区工具 @@ -14,9 +20,9 @@ WORKDIR /app COPY package.json ./ -RUN yarn config set registry 'https://registry.npmmirror.com/' -RUN yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp" -RUN yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips" +#RUN yarn config set registry 'https://registry.npmmirror.com/' +#RUN yarn config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp" +#RUN yarn config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips" #RUN # 清理遗留的缓存 RUN yarn cache clean RUN yarn install diff --git a/package.json b/package.json index e161f1d69..4baeb9bf1 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@hello-pangea/dnd": "^16.5.0", "@next-auth/prisma-adapter": "^1.0.7", "@next/third-parties": "^14.2.1", - "@prisma/client": "5.13.0", + "@prisma/client": "5.12.1", "@svgr/webpack": "^8.1.0", "@vercel/analytics": "^1.1.2", "@vercel/speed-insights": "^1.0.9", @@ -59,7 +59,6 @@ "zustand": "^4.5.0" }, "devDependencies": { - "@next/bundle-analyzer": "^14.2.3", "@tauri-apps/cli": "1.5.11", "@types/bcryptjs": "^2.4.6", "@types/cookie": "^0.6.0", @@ -82,8 +81,7 @@ "postcss": "^8.4.33", "prettier": "^3.2.4", "prettier-plugin-tailwindcss": "^0.5.11", - "prisma": "^5.13.0", - "speed-measure-webpack-plugin": "^1.5.0", + "prisma": "^5.12.1", "tailwindcss": "^3.4.1", "tailwindcss-animate": "^1.0.7", "typescript": "^5.3.3", From 942b48de69346eb776573c381c66726961a6de76 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Sat, 4 May 2024 12:41:49 +0800 Subject: [PATCH 03/11] test pack --- next.config.mjs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/next.config.mjs b/next.config.mjs index 0c75dedc2..74af2af50 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,10 +1,10 @@ import webpack from "webpack"; // debug build -import { createRequire } from 'module'; -const require = createRequire(import.meta.url); -const withBundleAnalyzer = require('@next/bundle-analyzer')({ - enabled: process.env.ANALYZE === 'true', -}); +// import { createRequire } from 'module'; +// const require = createRequire(import.meta.url); +// const withBundleAnalyzer = require('@next/bundle-analyzer')({ +// enabled: process.env.ANALYZE === 'true', +// }); // import CssMinimizerPlugin from "css-minimizer-webpack-plugin"; @@ -19,7 +19,7 @@ console.log("[Next] build with chunk: ", disableChunk); // const isProd = process.env.NODE_ENV === 'production' // 为了修复tiktoken的插件问题 -const nextConfig = withBundleAnalyzer({ +const nextConfig = { // transpilePackages: ['tiktoken'], webpack(config) { config.module.rules.push({ @@ -93,7 +93,7 @@ const nextConfig = withBundleAnalyzer({ // 'sharp': 'commonjs sharp' // }, swcMinify: true, -}); +}; const CorsHeaders = [ { key: "Access-Control-Allow-Credentials", value: "true" }, From 3dce5e2b89060b5553eaa266997e7610e791d503 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Sat, 4 May 2024 19:01:22 +0800 Subject: [PATCH 04/11] test pack --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 4baeb9bf1..fc7b2d813 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,8 @@ "@fortaine/fetch-event-source": "^3.0.6", "@hello-pangea/dnd": "^16.5.0", "@next-auth/prisma-adapter": "^1.0.7", - "@next/third-parties": "^14.2.1", - "@prisma/client": "5.12.1", + "@next/third-parties": "14.2.3", + "@prisma/client": "^5.13.0", "@svgr/webpack": "^8.1.0", "@vercel/analytics": "^1.1.2", "@vercel/speed-insights": "^1.0.9", @@ -35,7 +35,7 @@ "mermaid": "^10.7.0", "microsoft-cognitiveservices-speech-sdk": "^1.36.0", "nanoid": "^5.0.3", - "next": "^14.2.1", + "next": "14.2.3", "next-auth": "^4.24.7", "node-fetch": "^3.3.1", "nodemailer": "^6.9.13", @@ -53,7 +53,7 @@ "sharp": "^0.33.3", "spark-md5": "^3.0.2", "tailwind-merge": "^2.2.1", - "tiktoken": "^1.0.13", + "tiktoken": "1.0.14", "tiny-pinyin": "^1.3.2", "use-debounce": "^10.0.0", "zustand": "^4.5.0" @@ -62,8 +62,8 @@ "@tauri-apps/cli": "1.5.11", "@types/bcryptjs": "^2.4.6", "@types/cookie": "^0.6.0", - "@types/node": "^20.11.30", - "@types/nodemailer": "^6.4.14", + "@types/node": "20.12.8", + "@types/nodemailer": "6.4.15", "@types/react": "^18.2.70", "@types/react-dom": "^18.2.7", "@types/react-highlight-words": "^0.16.7", @@ -73,7 +73,7 @@ "cross-env": "^7.0.3", "date-fns": "^3.6.0", "eslint": "^8.55.0", - "eslint-config-next": "^14.2.1", + "eslint-config-next": "^14.2.3", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", "husky": "^9.0.7", @@ -81,7 +81,7 @@ "postcss": "^8.4.33", "prettier": "^3.2.4", "prettier-plugin-tailwindcss": "^0.5.11", - "prisma": "^5.12.1", + "prisma": "^5.13.0", "tailwindcss": "^3.4.1", "tailwindcss-animate": "^1.0.7", "typescript": "^5.3.3", From d9e0d3b19ddd8ce4217ca0535c1b77d3963e62e4 Mon Sep 17 00:00:00 2001 From: sijinhui Date: Mon, 6 May 2024 18:45:03 +0800 Subject: [PATCH 05/11] test pack --- .github/workflows/dockerToHub-dev.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dockerToHub-dev.yml b/.github/workflows/dockerToHub-dev.yml index 60ab7ffa3..5e90a0a3d 100644 --- a/.github/workflows/dockerToHub-dev.yml +++ b/.github/workflows/dockerToHub-dev.yml @@ -8,9 +8,8 @@ on: jobs: build: name: build test image to aly - # runs-on: thinkpad - runs-on: self - # runs-on: self-hosted + runs-on: ubuntu-latest + #runs-on: self steps: - name: Check out the repo uses: actions/checkout@v4 From f2e2c0178799dde7ecd522683ce4aa1577b10fff Mon Sep 17 00:00:00 2001 From: sijinhui Date: Mon, 6 May 2024 18:59:09 +0800 Subject: [PATCH 06/11] test pack --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ca27bc04e..f6d6b2712 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ #FROM registry.cn-hangzhou.aliyuncs.com/sijinhui/node:18-alpine AS base -FROM hub.siji.ci/library/node:20-alpine AS base +FROM hub.siji.ci/library/node:22.1-alpine AS base RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories RUN apk update && apk add --no-cache git tzdata RUN apk add --no-cache \ From 377e8d19b62525d38de11c2dd524b38eee81a9ac Mon Sep 17 00:00:00 2001 From: sijinhui Date: Mon, 6 May 2024 19:11:51 +0800 Subject: [PATCH 07/11] test pack --- .dockerignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index a46e23147..dbbc78a5f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -54,7 +54,7 @@ typings .env*.local # Next.js build output -.next +.next/ # out # Nuxt.js build output From b3e856df1d0aa00038f0e4048c209ce0c7def444 Mon Sep 17 00:00:00 2001 From: butterfly Date: Mon, 6 May 2024 19:26:39 +0800 Subject: [PATCH 08/11] feat: fix 1)the property named 'role' of the first message must be 'user' 2)if default summarize model 'gpt-3.5-turbo' is blocked, use currentModel instead 3)if apiurl&apikey set by location, useCustomConfig would be opened --- app/api/webdav/[...path]/route.ts | 12 +++++++----- app/client/platforms/anthropic.ts | 7 +++++++ app/components/chat.tsx | 1 + app/config/server.ts | 8 ++++---- app/constant.ts | 2 +- app/store/chat.ts | 16 ++++++++++++++-- app/utils/model.ts | 5 +---- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/api/webdav/[...path]/route.ts b/app/api/webdav/[...path]/route.ts index 3dd9ca3cd..816c2046b 100644 --- a/app/api/webdav/[...path]/route.ts +++ b/app/api/webdav/[...path]/route.ts @@ -1,12 +1,12 @@ import { NextRequest, NextResponse } from "next/server"; -import { STORAGE_KEY, internalWhiteWebDavEndpoints } from "../../../constant"; +import { STORAGE_KEY, internalAllowedWebDavEndpoints } from "../../../constant"; import { getServerSideConfig } from "@/app/config/server"; const config = getServerSideConfig(); -const mergedWhiteWebDavEndpoints = [ - ...internalWhiteWebDavEndpoints, - ...config.whiteWebDevEndpoints, +const mergedAllowedWebDavEndpoints = [ + ...internalAllowedWebDavEndpoints, + ...config.allowedWebDevEndpoints, ].filter((domain) => Boolean(domain.trim())); async function handle( @@ -24,7 +24,9 @@ async function handle( // Validate the endpoint to prevent potential SSRF attacks if ( - !mergedWhiteWebDavEndpoints.some((white) => endpoint?.startsWith(white)) + !mergedAllowedWebDavEndpoints.some( + (allowedEndpoint) => endpoint?.startsWith(allowedEndpoint), + ) ) { return NextResponse.json( { diff --git a/app/client/platforms/anthropic.ts b/app/client/platforms/anthropic.ts index ba07dcc76..54a171cda 100644 --- a/app/client/platforms/anthropic.ts +++ b/app/client/platforms/anthropic.ts @@ -161,6 +161,13 @@ export class ClaudeApi implements LLMApi { }; }); + if (prompt[0]?.role === "assistant") { + prompt.unshift({ + role: "user", + content: "", + }); + } + const requestBody: AnthropicChatRequest = { messages: prompt, stream: shouldStream, diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 85df5b9a8..c1400edc6 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1088,6 +1088,7 @@ function _Chat() { if (payload.url) { accessStore.update((access) => (access.openaiUrl = payload.url!)); } + accessStore.useCustomConfig = true; }); } } catch { diff --git a/app/config/server.ts b/app/config/server.ts index 618112172..edf58aaff 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -82,9 +82,9 @@ export const getServerSideConfig = () => { `[Server Config] using ${randomIndex + 1} of ${apiKeys.length} api key`, ); - const whiteWebDevEndpoints = (process.env.WHITE_WEBDEV_ENDPOINTS ?? "").split( - ",", - ); + const allowedWebDevEndpoints = ( + process.env.WHITE_WEBDEV_ENDPOINTS ?? "" + ).split(","); return { baseUrl: process.env.BASE_URL, @@ -120,6 +120,6 @@ export const getServerSideConfig = () => { disableFastLink: !!process.env.DISABLE_FAST_LINK, customModels, defaultModel, - whiteWebDevEndpoints, + allowedWebDevEndpoints, }; }; diff --git a/app/constant.ts b/app/constant.ts index 8b6549566..a3d9c206f 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -197,7 +197,7 @@ export const CHAT_PAGE_SIZE = 15; export const MAX_RENDER_MSG_COUNT = 45; // some famous webdav endpoints -export const internalWhiteWebDavEndpoints = [ +export const internalAllowedWebDavEndpoints = [ "https://dav.jianguoyun.com/dav/", "https://dav.dropdav.com/", "https://dav.box.com/dav", diff --git a/app/store/chat.ts b/app/store/chat.ts index b305264b6..a5412eaa9 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -21,6 +21,8 @@ import { estimateTokenLength } from "../utils/token"; import { nanoid } from "nanoid"; import { createPersistStore } from "../utils/store"; import { identifyDefaultClaudeModel } from "../utils/checkers"; +import { collectModelsWithDefaultModel } from "../utils/model"; +import { useAccessStore } from "./access"; export type ChatMessage = RequestMessage & { date: string; @@ -87,9 +89,19 @@ function createEmptySession(): ChatSession { function getSummarizeModel(currentModel: string) { // if it is using gpt-* models, force to use 3.5 to summarize if (currentModel.startsWith("gpt")) { - return SUMMARIZE_MODEL; + const configStore = useAppConfig.getState(); + const accessStore = useAccessStore.getState(); + const allModel = collectModelsWithDefaultModel( + configStore.models, + [configStore.customModels, accessStore.customModels].join(","), + accessStore.defaultModel, + ); + const summarizeModel = allModel.find( + (m) => m.name === SUMMARIZE_MODEL && m.available, + ); + return summarizeModel?.name ?? currentModel; } - if (currentModel.startsWith("gemini-pro")) { + if (currentModel.startsWith("gemini")) { return GEMINI_SUMMARIZE_MODEL; } return currentModel; diff --git a/app/utils/model.ts b/app/utils/model.ts index 6477640aa..056fff2e9 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -64,13 +64,10 @@ export function collectModelTableWithDefaultModel( ) { let modelTable = collectModelTable(models, customModels); if (defaultModel && defaultModel !== "") { - delete modelTable[defaultModel]; modelTable[defaultModel] = { + ...modelTable[defaultModel], name: defaultModel, - displayName: defaultModel, available: true, - provider: - modelTable[defaultModel]?.provider ?? customProvider(defaultModel), isDefault: true, }; } From a1493bfb4e9efe0a2e12917ab861bbf2321dbd7d Mon Sep 17 00:00:00 2001 From: Dean-YZG Date: Mon, 6 May 2024 20:46:53 +0800 Subject: [PATCH 09/11] feat: bugfix --- app/client/platforms/anthropic.ts | 2 +- app/components/chat.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/client/platforms/anthropic.ts b/app/client/platforms/anthropic.ts index 54a171cda..e90c8f057 100644 --- a/app/client/platforms/anthropic.ts +++ b/app/client/platforms/anthropic.ts @@ -164,7 +164,7 @@ export class ClaudeApi implements LLMApi { if (prompt[0]?.role === "assistant") { prompt.unshift({ role: "user", - content: "", + content: ";", }); } diff --git a/app/components/chat.tsx b/app/components/chat.tsx index c1400edc6..c8a79870c 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1088,7 +1088,7 @@ function _Chat() { if (payload.url) { accessStore.update((access) => (access.openaiUrl = payload.url!)); } - accessStore.useCustomConfig = true; + accessStore.update((access) => (access.useCustomConfig = true)); }); } } catch { From 864529cbf61925f3b85cfa698613c766efd93436 Mon Sep 17 00:00:00 2001 From: Dean-YZG Date: Mon, 6 May 2024 21:14:53 +0800 Subject: [PATCH 10/11] feat: googleApiKey & anthropicApiKey support setting multi-key --- app/config/server.ts | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/app/config/server.ts b/app/config/server.ts index edf58aaff..b5d754dde 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -51,6 +51,22 @@ const ACCESS_CODES = (function getAccessCodes(): Set { } })(); +function getApiKey(keys?: string) { + const apiKeyEnvVar = keys ?? ""; + const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim()); + const randomIndex = Math.floor(Math.random() * apiKeys.length); + const apiKey = apiKeys[randomIndex]; + if (apiKey) { + console.log( + `[Server Config] using ${randomIndex + 1} of ${ + apiKeys.length + } api key - ${apiKey}`, + ); + } + + return apiKey; +} + export const getServerSideConfig = () => { if (typeof process === "undefined") { throw Error( @@ -74,13 +90,13 @@ export const getServerSideConfig = () => { const isGoogle = !!process.env.GOOGLE_API_KEY; const isAnthropic = !!process.env.ANTHROPIC_API_KEY; - const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? ""; - const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim()); - const randomIndex = Math.floor(Math.random() * apiKeys.length); - const apiKey = apiKeys[randomIndex]; - console.log( - `[Server Config] using ${randomIndex + 1} of ${apiKeys.length} api key`, - ); + // const apiKeyEnvVar = process.env.OPENAI_API_KEY ?? ""; + // const apiKeys = apiKeyEnvVar.split(",").map((v) => v.trim()); + // const randomIndex = Math.floor(Math.random() * apiKeys.length); + // const apiKey = apiKeys[randomIndex]; + // console.log( + // `[Server Config] using ${randomIndex + 1} of ${apiKeys.length} api key`, + // ); const allowedWebDevEndpoints = ( process.env.WHITE_WEBDEV_ENDPOINTS ?? "" @@ -88,20 +104,20 @@ export const getServerSideConfig = () => { return { baseUrl: process.env.BASE_URL, - apiKey, + apiKey: getApiKey(process.env.OPENAI_API_KEY), openaiOrgId: process.env.OPENAI_ORG_ID, isAzure, azureUrl: process.env.AZURE_URL, - azureApiKey: process.env.AZURE_API_KEY, + azureApiKey: getApiKey(process.env.AZURE_API_KEY), azureApiVersion: process.env.AZURE_API_VERSION, isGoogle, - googleApiKey: process.env.GOOGLE_API_KEY, + googleApiKey: getApiKey(process.env.GOOGLE_API_KEY), googleUrl: process.env.GOOGLE_URL, isAnthropic, - anthropicApiKey: process.env.ANTHROPIC_API_KEY, + anthropicApiKey: getApiKey(process.env.ANTHROPIC_API_KEY), anthropicApiVersion: process.env.ANTHROPIC_API_VERSION, anthropicUrl: process.env.ANTHROPIC_URL, From f977c528591b8d150e4c9edaddbc68333c17ad6b Mon Sep 17 00:00:00 2001 From: sijinhui Date: Tue, 7 May 2024 16:46:38 +0800 Subject: [PATCH 11/11] merge --- app/config/server.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/config/server.ts b/app/config/server.ts index 0b19c6234..cde921e5d 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -59,11 +59,11 @@ function getApiKey(keys?: string) { const randomIndex = Math.floor(Math.random() * apiKeys.length); const apiKey = apiKeys[randomIndex]; if (apiKey) { - console.log( - `[Server Config] using ${randomIndex + 1} of ${ - apiKeys.length - } api key - ${apiKey}`, - ); + // console.log( + // `[Server Config] using ${randomIndex + 1} of ${ + // apiKeys.length + // } api key - ${apiKey}`, + // ); } return apiKey;