feat: add google api safety setting
This commit is contained in:
parent
24bf7950d8
commit
74986803db
|
@ -64,6 +64,9 @@ export class GeminiProApi implements LLMApi {
|
||||||
// if (visionModel && messages.length > 1) {
|
// if (visionModel && messages.length > 1) {
|
||||||
// options.onError?.(new Error("Multiturn chat is not enabled for models/gemini-pro-vision"));
|
// options.onError?.(new Error("Multiturn chat is not enabled for models/gemini-pro-vision"));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
const accessStore = useAccessStore.getState();
|
||||||
|
|
||||||
const modelConfig = {
|
const modelConfig = {
|
||||||
...useAppConfig.getState().modelConfig,
|
...useAppConfig.getState().modelConfig,
|
||||||
...useChatStore.getState().currentSession().mask.modelConfig,
|
...useChatStore.getState().currentSession().mask.modelConfig,
|
||||||
|
@ -85,25 +88,23 @@ export class GeminiProApi implements LLMApi {
|
||||||
safetySettings: [
|
safetySettings: [
|
||||||
{
|
{
|
||||||
category: "HARM_CATEGORY_HARASSMENT",
|
category: "HARM_CATEGORY_HARASSMENT",
|
||||||
threshold: "BLOCK_NONE",
|
threshold: accessStore.googleSafetySettings,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
category: "HARM_CATEGORY_HATE_SPEECH",
|
category: "HARM_CATEGORY_HATE_SPEECH",
|
||||||
threshold: "BLOCK_NONE",
|
threshold: accessStore.googleSafetySettings,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||||
threshold: "BLOCK_NONE",
|
threshold: accessStore.googleSafetySettings,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
category: "HARM_CATEGORY_DANGEROUS_CONTENT",
|
category: "HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||||
threshold: "BLOCK_NONE",
|
threshold: accessStore.googleSafetySettings,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const accessStore = useAccessStore.getState();
|
|
||||||
|
|
||||||
let baseUrl = "";
|
let baseUrl = "";
|
||||||
|
|
||||||
if (accessStore.useCustomConfig) {
|
if (accessStore.useCustomConfig) {
|
||||||
|
@ -120,7 +121,9 @@ export class GeminiProApi implements LLMApi {
|
||||||
|
|
||||||
if (!baseUrl) {
|
if (!baseUrl) {
|
||||||
baseUrl = isApp
|
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));
|
: this.path(Google.ChatPath(modelConfig.model));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +142,7 @@ export class GeminiProApi implements LLMApi {
|
||||||
() => controller.abort(),
|
() => controller.abort(),
|
||||||
REQUEST_TIMEOUT_MS,
|
REQUEST_TIMEOUT_MS,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (shouldStream) {
|
if (shouldStream) {
|
||||||
let responseText = "";
|
let responseText = "";
|
||||||
let remainText = "";
|
let remainText = "";
|
||||||
|
|
|
@ -54,6 +54,7 @@ import {
|
||||||
Anthropic,
|
Anthropic,
|
||||||
Azure,
|
Azure,
|
||||||
Google,
|
Google,
|
||||||
|
GoogleSafetySettingsThreshold,
|
||||||
OPENAI_BASE_URL,
|
OPENAI_BASE_URL,
|
||||||
Path,
|
Path,
|
||||||
RELEASE_URL,
|
RELEASE_URL,
|
||||||
|
@ -1122,6 +1123,35 @@ export function Settings() {
|
||||||
}
|
}
|
||||||
></input>
|
></input>
|
||||||
</ListItem>
|
</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 && (
|
{accessStore.provider === ServiceProvider.Anthropic && (
|
||||||
|
|
|
@ -72,6 +72,15 @@ export enum ServiceProvider {
|
||||||
Anthropic = "Anthropic",
|
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 {
|
export enum ModelProvider {
|
||||||
GPT = "GPT",
|
GPT = "GPT",
|
||||||
GeminiPro = "GeminiPro",
|
GeminiPro = "GeminiPro",
|
||||||
|
|
|
@ -346,6 +346,10 @@ const cn = {
|
||||||
Title: "API 版本(仅适用于 gemini-pro)",
|
Title: "API 版本(仅适用于 gemini-pro)",
|
||||||
SubTitle: "选择一个特定的 API 版本",
|
SubTitle: "选择一个特定的 API 版本",
|
||||||
},
|
},
|
||||||
|
GoogleSafetySettings: {
|
||||||
|
Title: "Google 安全过滤级别",
|
||||||
|
SubTitle: "设置内容过滤级别",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
CustomModel: {
|
CustomModel: {
|
||||||
Title: "自定义模型名",
|
Title: "自定义模型名",
|
||||||
|
|
|
@ -354,6 +354,10 @@ const en: LocaleType = {
|
||||||
Title: "API Version (specific to gemini-pro)",
|
Title: "API Version (specific to gemini-pro)",
|
||||||
SubTitle: "Select a specific API version",
|
SubTitle: "Select a specific API version",
|
||||||
},
|
},
|
||||||
|
GoogleSafetySettings: {
|
||||||
|
Title: "Google Safety Settings",
|
||||||
|
SubTitle: "Select a safety filtering level",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
ApiPath,
|
ApiPath,
|
||||||
DEFAULT_API_HOST,
|
DEFAULT_API_HOST,
|
||||||
|
GoogleSafetySettingsThreshold,
|
||||||
ServiceProvider,
|
ServiceProvider,
|
||||||
StoreKey,
|
StoreKey,
|
||||||
} from "../constant";
|
} from "../constant";
|
||||||
|
@ -36,6 +37,7 @@ const DEFAULT_ACCESS_STATE = {
|
||||||
googleUrl: "",
|
googleUrl: "",
|
||||||
googleApiKey: "",
|
googleApiKey: "",
|
||||||
googleApiVersion: "v1",
|
googleApiVersion: "v1",
|
||||||
|
googleSafetySettings: GoogleSafetySettingsThreshold.BLOCK_ONLY_HIGH,
|
||||||
|
|
||||||
// anthropic
|
// anthropic
|
||||||
anthropicApiKey: "",
|
anthropicApiKey: "",
|
||||||
|
|
Loading…
Reference in New Issue