Skip to content

Commit

Permalink
fix: Gemini 500
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazee6 committed Jun 4, 2024
1 parent c892727 commit 10d8b85
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 35 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RUN npm i -g [email protected]

COPY package.json ./

COPY patches ./patches

RUN pnpm install

COPY . .
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloudflare-ai-web",
"version": "3.0.0",
"version": "3.0.1",
"private": true,
"type": "module",
"scripts": {
Expand All @@ -27,5 +27,10 @@
"highlight.js": "^11.9.0",
"markdown-it": "^14.1.0"
},
"packageManager": "[email protected]+sha512.9df9cf27c91715646c7d675d1c9c8e41f6fce88246f1318c1aa6a1ed1aeb3c4f032fcdf4ba63cc69c4fe6d634279176b5358727d8f2cc1e65b65f43ce2f8bfb0"
"packageManager": "[email protected]+sha512.9df9cf27c91715646c7d675d1c9c8e41f6fce88246f1318c1aa6a1ed1aeb3c4f032fcdf4ba63cc69c4fe6d634279176b5358727d8f2cc1e65b65f43ce2f8bfb0",
"pnpm": {
"patchedDependencies": {
"@google/[email protected]": "patches/@[email protected]"
}
}
}
26 changes: 26 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -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
38 changes: 14 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions server/api/auth/gemini.post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {GoogleGenerativeAI, HarmBlockThreshold, HarmCategory} from '@google/generative-ai'
import {GoogleGenerativeAI} from '@google/generative-ai'
import {headers} from '~/utils/helper';
import {OpenAIMessage} from "~/utils/types";

Expand All @@ -12,14 +12,6 @@ export default defineEventHandler(async (event) => {

const m = genAI.getGenerativeModel({model})
let msg = messages.slice(1)
// let flag = ['user', 'assistant']
// for (let i = 0; i < msg.length; i++) {
// if (msg[i].role !== flag[i % 2]) {
// flag = []
// break
// }
// }
// if (!flag.length) return new Response('对话失效,请重新开始对话', {status: 400})

let res
if (files.length) {
Expand Down

0 comments on commit 10d8b85

Please sign in to comment.