mirror of
				https://github.com/Yidadaa/ChatGPT-Next-Web.git
				synced 2025-10-31 21:59:19 +08:00 
			
		
		
		
	Merge pull request #4847 from yeung66/main
add google api safety settings by Settings page
This commit is contained in:
		| @@ -106,6 +106,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, | ||||
| @@ -127,19 +130,19 @@ export class GeminiProApi implements LLMApi { | ||||
|       safetySettings: [ | ||||
|         { | ||||
|           category: "HARM_CATEGORY_HARASSMENT", | ||||
|           threshold: "BLOCK_ONLY_HIGH", | ||||
|           threshold: accessStore.googleSafetySettings, | ||||
|         }, | ||||
|         { | ||||
|           category: "HARM_CATEGORY_HATE_SPEECH", | ||||
|           threshold: "BLOCK_ONLY_HIGH", | ||||
|           threshold: accessStore.googleSafetySettings, | ||||
|         }, | ||||
|         { | ||||
|           category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", | ||||
|           threshold: "BLOCK_ONLY_HIGH", | ||||
|           threshold: accessStore.googleSafetySettings, | ||||
|         }, | ||||
|         { | ||||
|           category: "HARM_CATEGORY_DANGEROUS_CONTENT", | ||||
|           threshold: "BLOCK_ONLY_HIGH", | ||||
|           threshold: accessStore.googleSafetySettings, | ||||
|         }, | ||||
|       ], | ||||
|     }; | ||||
|   | ||||
| @@ -57,6 +57,7 @@ import { | ||||
|   ByteDance, | ||||
|   Alibaba, | ||||
|   Google, | ||||
|   GoogleSafetySettingsThreshold, | ||||
|   OPENAI_BASE_URL, | ||||
|   Path, | ||||
|   RELEASE_URL, | ||||
| @@ -1125,6 +1126,35 @@ export function Settings() { | ||||
|                           } | ||||
|                         ></input> | ||||
|                       </ListItem> | ||||
|                       <ListItem | ||||
|                         title={ | ||||
|                           Locale.Settings.Access.Google.GoogleSafetySettings | ||||
|                             .Title | ||||
|                         } | ||||
|                         subTitle={ | ||||
|                           Locale.Settings.Access.Google.GoogleSafetySettings | ||||
|                             .SubTitle | ||||
|                         } | ||||
|                       > | ||||
|                         <Select | ||||
|                           value={accessStore.googleSafetySettings} | ||||
|                           onChange={(e) => { | ||||
|                             accessStore.update( | ||||
|                               (access) => | ||||
|                                 (access.googleSafetySettings = e.target | ||||
|                                   .value as GoogleSafetySettingsThreshold), | ||||
|                             ); | ||||
|                           }} | ||||
|                         > | ||||
|                           {Object.entries(GoogleSafetySettingsThreshold).map( | ||||
|                             ([k, v]) => ( | ||||
|                               <option value={v} key={k}> | ||||
|                                 {k} | ||||
|                               </option> | ||||
|                             ), | ||||
|                           )} | ||||
|                         </Select> | ||||
|                       </ListItem> | ||||
|                     </> | ||||
|                   )} | ||||
|                   {accessStore.provider === ServiceProvider.Anthropic && ( | ||||
|   | ||||
| @@ -90,6 +90,15 @@ export enum ServiceProvider { | ||||
|   Alibaba = "Alibaba", | ||||
| } | ||||
|  | ||||
| // 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", | ||||
|   | ||||
| @@ -346,6 +346,10 @@ const cn = { | ||||
|           Title: "API 版本(仅适用于 gemini-pro)", | ||||
|           SubTitle: "选择一个特定的 API 版本", | ||||
|         }, | ||||
|         GoogleSafetySettings: { | ||||
|           Title: "Google 安全过滤级别", | ||||
|           SubTitle: "设置内容过滤级别", | ||||
|         }, | ||||
|       }, | ||||
|       Baidu: { | ||||
|         ApiKey: { | ||||
|   | ||||
| @@ -392,6 +392,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", | ||||
|         }, | ||||
|       }, | ||||
|     }, | ||||
|  | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| import { | ||||
|   ApiPath, | ||||
|   DEFAULT_API_HOST, | ||||
|   GoogleSafetySettingsThreshold, | ||||
|   ServiceProvider, | ||||
|   StoreKey, | ||||
| } from "../constant"; | ||||
| @@ -59,6 +60,7 @@ const DEFAULT_ACCESS_STATE = { | ||||
|   googleUrl: DEFAULT_GOOGLE_URL, | ||||
|   googleApiKey: "", | ||||
|   googleApiVersion: "v1", | ||||
|   googleSafetySettings: GoogleSafetySettingsThreshold.BLOCK_ONLY_HIGH, | ||||
|  | ||||
|   // anthropic | ||||
|   anthropicUrl: DEFAULT_ANTHROPIC_URL, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user