rohankaran commited on
Commit
dcb081c
1 Parent(s): 4962c42

Import and use additional HarmCategory and HarmBlockThreshold models

Browse files

The update in guardrails_models.py ensures more categories of harmful content are included in our checks and result blocking schemes. This expands the capacity of our system to flag and block dangerous content, sexually explicit content, hate speech and harassment, thereby enhancing user safety and ensuring a healthier interaction environment.

Files changed (1) hide show
  1. guardrails_models.py +2 -1
guardrails_models.py CHANGED
@@ -3,7 +3,7 @@ import random
3
  from typing import List, Optional
4
 
5
  import openai
6
- from google.generativeai.types import BlockedPromptException, StopCandidateException
7
  from langchain_community.chat_models import ChatAnyscale
8
  from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
9
  from langchain_google_genai import ChatGoogleGenerativeAI
@@ -383,6 +383,7 @@ def gemini_pro_nemoguardrails(
383
  temperature=temperature,
384
  max_retries=6,
385
  metadata={"top_p": top_p, "max_output_tokens": max_output_tokens},
 
386
  ),
387
  )
388
  completion = rails.generate(messages=messages)
 
3
  from typing import List, Optional
4
 
5
  import openai
6
+ from google.generativeai.types import BlockedPromptException, StopCandidateException, HarmCategory, HarmBlockThreshold
7
  from langchain_community.chat_models import ChatAnyscale
8
  from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
9
  from langchain_google_genai import ChatGoogleGenerativeAI
 
383
  temperature=temperature,
384
  max_retries=6,
385
  metadata={"top_p": top_p, "max_output_tokens": max_output_tokens},
386
+ safety_settings={ HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_NONE, HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_NONE, },
387
  ),
388
  )
389
  completion = rails.generate(messages=messages)