From 24bf7950d85c7894a38677bffe5771ae981993b6 Mon Sep 17 00:00:00 2001 From: YeungYeah Date: Wed, 12 Jun 2024 21:59:28 +0800 Subject: [PATCH 1/4] chore: set the google safety setting to lowest --- app/client/platforms/google.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index a786f5275f4..953aacb065b 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -85,19 +85,19 @@ export class GeminiProApi implements LLMApi { safetySettings: [ { category: "HARM_CATEGORY_HARASSMENT", - threshold: "BLOCK_ONLY_HIGH", + threshold: "BLOCK_NONE", }, { category: "HARM_CATEGORY_HATE_SPEECH", - threshold: "BLOCK_ONLY_HIGH", + threshold: "BLOCK_NONE", }, { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", - threshold: "BLOCK_ONLY_HIGH", + threshold: "BLOCK_NONE", }, { category: "HARM_CATEGORY_DANGEROUS_CONTENT", - threshold: "BLOCK_ONLY_HIGH", + threshold: "BLOCK_NONE", }, ], }; From 74986803db5241392f4044e9493661113e955ee0 Mon Sep 17 00:00:00 2001 From: YeungYeah Date: Sat, 15 Jun 2024 12:09:58 +0800 Subject: [PATCH 2/4] feat: add google api safety setting --- app/client/platforms/google.ts | 19 +++++++++++-------- app/components/settings.tsx | 30 ++++++++++++++++++++++++++++++ app/constant.ts | 9 +++++++++ app/locales/cn.ts | 4 ++++ app/locales/en.ts | 4 ++++ app/store/access.ts | 2 ++ 6 files changed, 60 insertions(+), 8 deletions(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 953aacb065b..e62d1078eab 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -64,6 +64,9 @@ export class GeminiProApi implements LLMApi { // if (visionModel && messages.length > 1) { // options.onError?.(new Error("Multiturn chat is not enabled for models/gemini-pro-vision")); // } + + const accessStore = useAccessStore.getState(); + const modelConfig = { ...useAppConfig.getState().modelConfig, ...useChatStore.getState().currentSession().mask.modelConfig, @@ -85,25 +88,23 @@ export class GeminiProApi implements LLMApi { safetySettings: [ { category: "HARM_CATEGORY_HARASSMENT", - threshold: "BLOCK_NONE", + threshold: accessStore.googleSafetySettings, }, { category: "HARM_CATEGORY_HATE_SPEECH", - threshold: "BLOCK_NONE", + threshold: accessStore.googleSafetySettings, }, { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", - threshold: "BLOCK_NONE", + threshold: accessStore.googleSafetySettings, }, { category: "HARM_CATEGORY_DANGEROUS_CONTENT", - threshold: "BLOCK_NONE", + threshold: accessStore.googleSafetySettings, }, ], }; - const accessStore = useAccessStore.getState(); - let baseUrl = ""; if (accessStore.useCustomConfig) { @@ -120,7 +121,9 @@ export class GeminiProApi implements LLMApi { if (!baseUrl) { baseUrl = isApp - ? DEFAULT_API_HOST + "/api/proxy/google/" + Google.ChatPath(modelConfig.model) + ? DEFAULT_API_HOST + + "/api/proxy/google/" + + Google.ChatPath(modelConfig.model) : this.path(Google.ChatPath(modelConfig.model)); } @@ -139,7 +142,7 @@ export class GeminiProApi implements LLMApi { () => controller.abort(), REQUEST_TIMEOUT_MS, ); - + if (shouldStream) { let responseText = ""; let remainText = ""; diff --git a/app/components/settings.tsx b/app/components/settings.tsx index db08b48a9ff..fd28723a534 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -54,6 +54,7 @@ import { Anthropic, Azure, Google, + GoogleSafetySettingsThreshold, OPENAI_BASE_URL, Path, RELEASE_URL, @@ -1122,6 +1123,35 @@ export function Settings() { } > + + + )} {accessStore.provider === ServiceProvider.Anthropic && ( diff --git a/app/constant.ts b/app/constant.ts index 411e481508d..43660d6da07 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -72,6 +72,15 @@ export enum ServiceProvider { Anthropic = "Anthropic", } +// Google API safety settings, see https://ai.google.dev/gemini-api/docs/safety-settings +// BLOCK_NONE will not block any content, and BLOCK_ONLY_HIGH will block only high-risk content. +export enum GoogleSafetySettingsThreshold { + BLOCK_NONE = "BLOCK_NONE", + BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH", + BLOCK_MEDIUM_AND_ABOVE = "BLOCK_MEDIUM_AND_ABOVE", + BLOCK_LOW_AND_ABOVE = "BLOCK_LOW_AND_ABOVE", +} + export enum ModelProvider { GPT = "GPT", GeminiPro = "GeminiPro", diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 2ff94e32d43..fa75b0e38e1 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -346,6 +346,10 @@ const cn = { Title: "API 版本(仅适用于 gemini-pro)", SubTitle: "选择一个特定的 API 版本", }, + GoogleSafetySettings: { + Title: "Google 安全过滤级别", + SubTitle: "设置内容过滤级别", + }, }, CustomModel: { Title: "自定义模型名", diff --git a/app/locales/en.ts b/app/locales/en.ts index aa153f52369..e546ce0f822 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -354,6 +354,10 @@ const en: LocaleType = { Title: "API Version (specific to gemini-pro)", SubTitle: "Select a specific API version", }, + GoogleSafetySettings: { + Title: "Google Safety Settings", + SubTitle: "Select a safety filtering level", + }, }, }, diff --git a/app/store/access.ts b/app/store/access.ts index 64909609e05..737bcc807bb 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -1,6 +1,7 @@ import { ApiPath, DEFAULT_API_HOST, + GoogleSafetySettingsThreshold, ServiceProvider, StoreKey, } from "../constant"; @@ -36,6 +37,7 @@ const DEFAULT_ACCESS_STATE = { googleUrl: "", googleApiKey: "", googleApiVersion: "v1", + googleSafetySettings: GoogleSafetySettingsThreshold.BLOCK_ONLY_HIGH, // anthropic anthropicApiKey: "", From 26c2598f56b82b0b1082aeb05b58aacdb2de0cd9 Mon Sep 17 00:00:00 2001 From: YeungYeah Date: Thu, 18 Jul 2024 23:41:20 +0800 Subject: [PATCH 3/4] fix: fix bug in generating wrong gemini request url --- app/client/platforms/google.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 100067e8e21..dbcc3579b68 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -123,8 +123,10 @@ export class GeminiProApi implements LLMApi { const controller = new AbortController(); options.onController?.(controller); try { - if (!baseUrl && isApp) { - baseUrl = DEFAULT_API_HOST + "/api/proxy/google/"; + if (!baseUrl) { + baseUrl = isApp + ? DEFAULT_API_HOST + "/api/proxy/google/" + : this.path(""); } baseUrl = `${baseUrl}/${Google.ChatPath(modelConfig.model)}`.replaceAll( "//", From 0236e13187d396e627c1d3475653d08d75a41f4a Mon Sep 17 00:00:00 2001 From: Chenglong Wang Date: Fri, 19 Jul 2024 23:36:57 +0800 Subject: [PATCH 4/4] Change gpt summary model to gpt-4o-mini. --- app/constant.ts | 2 +- app/store/chat.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/constant.ts b/app/constant.ts index f5d3c77f463..de1500e840d 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -176,7 +176,7 @@ Latex inline: \\(x^2\\) Latex block: $$e=mc^2$$ `; -export const SUMMARIZE_MODEL = "gpt-3.5-turbo"; +export const SUMMARIZE_MODEL = "gpt-4o-mini"; export const GEMINI_SUMMARIZE_MODEL = "gemini-pro"; export const KnowledgeCutOffDate: Record = { diff --git a/app/store/chat.ts b/app/store/chat.ts index 9372b8b2e8d..5892ef0c8c6 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -90,7 +90,7 @@ function createEmptySession(): ChatSession { } function getSummarizeModel(currentModel: string) { - // if it is using gpt-* models, force to use 3.5 to summarize + // if it is using gpt-* models, force to use 4o-mini to summarize if (currentModel.startsWith("gpt")) { const configStore = useAppConfig.getState(); const accessStore = useAccessStore.getState();