From e1de51e6083c563040c229930d84980e79e4d8f9 Mon Sep 17 00:00:00 2001 From: Jazee6 Date: Tue, 4 Jun 2024 12:21:48 +0800 Subject: [PATCH] fix: Gemini 500 --- .github/workflows/deploy.yml | 42 --------------------- Dockerfile | 2 +- README.md | 9 +++-- package.json | 7 +++- patches/@google__generative-ai@0.12.0.patch | 26 +++++++++++++ 5 files changed, 38 insertions(+), 48 deletions(-) delete mode 100644 .github/workflows/deploy.yml create mode 100644 patches/@google__generative-ai@0.12.0.patch diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index c7143ff..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Deploy -on: - push: - branches: main - pull_request: - branches: main - -jobs: - deploy: - name: Deploy - runs-on: ubuntu-latest - - permissions: - id-token: write # Needed for auth with Deno Deploy - contents: read # Needed to clone the repository - - steps: - - name: Clone repository - uses: actions/checkout@v4 - - - name: Install Deno - uses: denoland/setup-deno@v1 - with: - deno-version: v1.x - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: lts/* - - - name: Install step - run: "npm install" - - - name: Build step - run: "NITRO_PRESET=deno-deploy npm run build_node" - - - name: Upload to Deno Deploy - uses: denoland/deployctl@v1 - with: - project: "cf-ai-web" - entrypoint: "server/index.ts" - root: ".output" diff --git a/Dockerfile b/Dockerfile index 5017815..f4dfa9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN npm i -g pnpm@9.1.4 COPY package.json ./ -#COPY patches ./patches +COPY patches ./patches RUN pnpm install diff --git a/README.md b/README.md index ce802ef..a6c4636 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ https://dash.deno.com - Build Step改为`NITRO_PRESET=deno-deploy npm run build_node` - Deploy Project - 设置环境变量 +- 部分地区可能需要Gemini反代 ### Docker @@ -33,7 +34,7 @@ docker run -d --name cloudflare-ai-web \ - 利用 Cloudflare Workers AI 快速搭建多模态AI平台 - 支持 Serverless 部署,无需服务器 - 支持开启访问密码,聊天记录本地存储 -- 轻量化(~638 kB gzip) +- 轻量化(~646 kB gzip) - 支持`ChatGPT` `Gemini Pro` `Stable Diffusion` `llama-3` `通义千问`等 ### 模型支持 @@ -54,6 +55,8 @@ https://developers.cloudflare.com/workers-ai/models/ | G_API_KEY | Google AI API Key (需要GeminiPro时填写) | | PASSWORD | 访问密码 (可选) | +示例: 查看`.env.example`文件 + #### CF_TOKEN https://dash.cloudflare.com/profile/api-tokens @@ -64,8 +67,6 @@ https://dash.cloudflare.com/profile/api-tokens - 单击创建令牌 - 复制您的令牌,设置环境变量 -示例:https://gateway.ai.cloudflare.com/v1/A484BCC718B10B73022BFE2D9AB49776/myai - #### CF_GATEWAY https://dash.cloudflare.com/ @@ -74,7 +75,7 @@ https://dash.cloudflare.com/ - 添加新 AI Gateway - 填写名称和URL slug创建 - 单击右上角API Endpoints -- 复制您的Universal Endpoint,设置环境变量 +- 复制您的Universal Endpoint(去掉末尾'/'),设置环境变量 #### G_API_KEY diff --git a/package.json b/package.json index 9c7d019..2403557 100644 --- a/package.json +++ b/package.json @@ -27,5 +27,10 @@ "highlight.js": "^11.9.0", "markdown-it": "^14.1.0" }, - "packageManager": "pnpm@9.1.4+sha512.9df9cf27c91715646c7d675d1c9c8e41f6fce88246f1318c1aa6a1ed1aeb3c4f032fcdf4ba63cc69c4fe6d634279176b5358727d8f2cc1e65b65f43ce2f8bfb0" + "packageManager": "pnpm@9.1.4+sha512.9df9cf27c91715646c7d675d1c9c8e41f6fce88246f1318c1aa6a1ed1aeb3c4f032fcdf4ba63cc69c4fe6d634279176b5358727d8f2cc1e65b65f43ce2f8bfb0", + "pnpm": { + "patchedDependencies": { + "@google/generative-ai@0.12.0": "patches/@google__generative-ai@0.12.0.patch" + } + } } diff --git a/patches/@google__generative-ai@0.12.0.patch b/patches/@google__generative-ai@0.12.0.patch new file mode 100644 index 0000000..6db2294 --- /dev/null +++ b/patches/@google__generative-ai@0.12.0.patch @@ -0,0 +1,26 @@ +diff --git a/dist/index.js b/dist/index.js +index 4290f816871d5e88e44e264fa47b2960cde864a7..64647480b2d600d8f163a15ef7ce49920b04bae5 100644 +--- a/dist/index.js ++++ b/dist/index.js +@@ -241,7 +241,7 @@ class GoogleGenerativeAIRequestInputError extends GoogleGenerativeAIError { + * See the License for the specific language governing permissions and + * limitations under the License. + */ +-const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com"; ++const DEFAULT_BASE_URL = process.env.G_API_URL || "https://generativelanguage.googleapis.com"; + const DEFAULT_API_VERSION = "v1beta"; + /** + * We can't `require` package.json if this runs on web. We will use rollup to +diff --git a/dist/index.mjs b/dist/index.mjs +index aabb1c97ad6ec5af1e8e736da9d3dc23c478cb09..b02db137b30e5f77e7a5d68657b1fbc19581c8f2 100644 +--- a/dist/index.mjs ++++ b/dist/index.mjs +@@ -239,7 +239,7 @@ class GoogleGenerativeAIRequestInputError extends GoogleGenerativeAIError { + * See the License for the specific language governing permissions and + * limitations under the License. + */ +-const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com"; ++const DEFAULT_BASE_URL = process.env.G_API_URL || "https://generativelanguage.googleapis.com"; + const DEFAULT_API_VERSION = "v1beta"; + /** + * We can't `require` package.json if this runs on web. We will use rollup to