diff --git a/.env.template b/.env.template index 89bab2cb1..166cc4ef4 100644 --- a/.env.template +++ b/.env.template @@ -14,8 +14,8 @@ PROXY_URL=http://localhost:7890 GOOGLE_API_KEY= # (optional) -# Default: https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent -# Googel Gemini Pro API url, set if you want to customize Google Gemini Pro API url. +# Default: https://generativelanguage.googleapis.com/ +# Googel Gemini Pro API url without pathname, set if you want to customize Google Gemini Pro API url. GOOGLE_URL= # Override openai api request base url. (optional) diff --git a/README.md b/README.md index 58249e090..fec3ec108 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@
-icon +icon

NextChat (ChatGPT Next Web)

diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 6eaa3c971..f0f63659f 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -9,6 +9,7 @@ import { prettyObject } from "@/app/utils/format"; import { getClientConfig } from "@/app/config/client"; import Locale from "../../locales"; import { getServerSideConfig } from "@/app/config/server"; +import de from "@/app/locales/de"; export class GeminiProApi implements LLMApi { extractMessage(res: any) { console.log("[Response] gemini-pro response: ", res); @@ -58,6 +59,24 @@ export class GeminiProApi implements LLMApi { topP: modelConfig.top_p, // "topK": modelConfig.top_k, }, + safetySettings: [ + { + category: "HARM_CATEGORY_HARASSMENT", + threshold: "BLOCK_ONLY_HIGH", + }, + { + category: "HARM_CATEGORY_HATE_SPEECH", + threshold: "BLOCK_ONLY_HIGH", + }, + { + category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", + threshold: "BLOCK_ONLY_HIGH", + }, + { + category: "HARM_CATEGORY_DANGEROUS_CONTENT", + threshold: "BLOCK_ONLY_HIGH", + }, + ], }; console.log("[Request] google payload: ", requestPayload); @@ -87,9 +106,11 @@ export class GeminiProApi implements LLMApi { "streamGenerateContent", ); let finished = false; + + let existingTexts: string[] = []; const finish = () => { finished = true; - options.onFinish(responseText + remainText); + options.onFinish(existingTexts.join("")); }; // animate response to make it looks smooth @@ -134,11 +155,26 @@ export class GeminiProApi implements LLMApi { try { let data = JSON.parse(ensureProperEnding(partialData)); - console.log(data); - let fetchText = apiClient.extractMessage(data[data.length - 1]); - console.log("[Response Animation] fetchText: ", fetchText); - remainText += fetchText; + + const textArray = data.reduce( + (acc: string[], item: { candidates: any[] }) => { + const texts = item.candidates.map((candidate) => + candidate.content.parts + .map((part: { text: any }) => part.text) + .join(""), + ); + return acc.concat(texts); + }, + [], + ); + + if (textArray.length > existingTexts.length) { + const deltaArray = textArray.slice(existingTexts.length); + existingTexts = textArray; + remainText += deltaArray.join(""); + } } catch (error) { + // console.log("[Response Animation] error: ", error,partialData); // skip error message when parsing json } diff --git a/app/constant.ts b/app/constant.ts index 7668381c1..53d47540a 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -87,8 +87,7 @@ export const Azure = { }; export const Google = { - ExampleEndpoint: - "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent", + ExampleEndpoint: "https://generativelanguage.googleapis.com/", ChatPath: "v1beta/models/gemini-pro:generateContent", // /api/openai/v1/chat/completions diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 8746047fd..4a92b6383 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -321,7 +321,7 @@ const cn = { Endpoint: { Title: "接口地址", - SubTitle: "样例:", + SubTitle: "不包含请求路径,样例:", }, ApiVerion: { diff --git a/docs/images/head-cover.png b/docs/images/head-cover.png new file mode 100644 index 000000000..859d83b05 Binary files /dev/null and b/docs/images/head-cover.png differ diff --git a/public/android-chrome-192x192.png b/public/android-chrome-192x192.png index 700c48286..b191a58ac 100644 Binary files a/public/android-chrome-192x192.png and b/public/android-chrome-192x192.png differ diff --git a/public/android-chrome-512x512.png b/public/android-chrome-512x512.png index e701ed2fb..c7e52c394 100644 Binary files a/public/android-chrome-512x512.png and b/public/android-chrome-512x512.png differ diff --git a/public/apple-touch-icon.png b/public/apple-touch-icon.png index 387303114..b0da95315 100644 Binary files a/public/apple-touch-icon.png and b/public/apple-touch-icon.png differ diff --git a/public/favicon-16x16.png b/public/favicon-16x16.png index 92f53492f..3f8e0a535 100644 Binary files a/public/favicon-16x16.png and b/public/favicon-16x16.png differ diff --git a/public/favicon-32x32.png b/public/favicon-32x32.png index f1f439e85..2fee10dfb 100644 Binary files a/public/favicon-32x32.png and b/public/favicon-32x32.png differ diff --git a/public/favicon.ico b/public/favicon.ico index a3737b350..b5e8234cd 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/macos.png b/public/macos.png index f1bd0e69f..2eb110707 100644 Binary files a/public/macos.png and b/public/macos.png differ