Skip to content

Commit

Permalink
fix: fix google safety category
Browse files Browse the repository at this point in the history
  • Loading branch information
adolphnov committed Dec 16, 2024
1 parent ef4e26f commit c7c00f5
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ export async function createLlmModel(model: string, context: AgentUserConfig) {
if (!model_id) {
model_id = context[`${agent.toUpperCase()}_CHAT_MODEL`];
}
const GOOGLE_SAFETY = [
{ category: 'HARM_CATEGORY_UNSPECIFIED', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_DANGEROUS_CONTENT', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_HARASSMENT', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_HATE_SPEECH', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', threshold: 'BLOCK_NONE' }];

switch (agent) {
case 'openai':
case 'gpt':
Expand All @@ -200,12 +207,7 @@ export async function createLlmModel(model: string, context: AgentUserConfig) {
baseURL: context.GOOGLE_API_BASE,
apiKey: context.GOOGLE_API_KEY || undefined,
}).languageModel(model_id, {
safetySettings: [
{ category: 'HARM_CATEGORY_DANGEROUS_CONTENT', threshold: 'BLOCK_LOW_AND_ABOVE' },
{ category: 'HARM_CATEGORY_HATE_SPEECH', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_HARASSMENT', threshold: 'BLOCK_NONE' },
],
safetySettings: GOOGLE_SAFETY,

Check failure on line 210 in src/agent/index.ts

View workflow job for this annotation

GitHub Actions / Deploy

Type '{ category: string; threshold: string; }[]' is not assignable to type '{ category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_CIVIC_INTEGRITY"; threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | ... 3 more ... | "BLOCK_NONE"; }[]'.

Check failure on line 210 in src/agent/index.ts

View workflow job for this annotation

GitHub Actions / build-and-push

Type '{ category: string; threshold: string; }[]' is not assignable to type '{ category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_CIVIC_INTEGRITY"; threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | ... 3 more ... | "BLOCK_NONE"; }[]'.
useSearchGrounding: context.SEARCH_GROUNDING,
});
case 'cohere':
Expand All @@ -224,13 +226,7 @@ export async function createLlmModel(model: string, context: AgentUserConfig) {
credentials: context.VERTEX_CREDENTIALS,
},
}).languageModel(model_id, {
safetySettings: [
{ category: 'HARM_CATEGORY_UNSPECIFIED', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_DANGEROUS_CONTENT', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_HARASSMENT', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_HATE_SPEECH', threshold: 'BLOCK_NONE' },
{ category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', threshold: 'BLOCK_NONE' },
],
safetySettings: GOOGLE_SAFETY,

Check failure on line 229 in src/agent/index.ts

View workflow job for this annotation

GitHub Actions / Deploy

Type '{ category: string; threshold: string; }[]' is not assignable to type '{ category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_CIVIC_INTEGRITY"; threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | ... 3 more ... | "BLOCK_NONE"; }[]'.

Check failure on line 229 in src/agent/index.ts

View workflow job for this annotation

GitHub Actions / build-and-push

Type '{ category: string; threshold: string; }[]' is not assignable to type '{ category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_CIVIC_INTEGRITY"; threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | ... 3 more ... | "BLOCK_NONE"; }[]'.
useSearchGrounding: context.SEARCH_GROUNDING,
});
case 'xai':
Expand Down

0 comments on commit c7c00f5

Please sign in to comment.