Update Google safety defaults to match Google (#118084)

This commit is contained in:
Paulus Schoutsen 2024-05-25 00:02:53 -04:00 committed by GitHub
parent 676fe5a9a2
commit 69f237fa9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 19 deletions

View File

@ -22,4 +22,4 @@ CONF_HARASSMENT_BLOCK_THRESHOLD = "harassment_block_threshold"
CONF_HATE_BLOCK_THRESHOLD = "hate_block_threshold" CONF_HATE_BLOCK_THRESHOLD = "hate_block_threshold"
CONF_SEXUAL_BLOCK_THRESHOLD = "sexual_block_threshold" CONF_SEXUAL_BLOCK_THRESHOLD = "sexual_block_threshold"
CONF_DANGEROUS_BLOCK_THRESHOLD = "dangerous_block_threshold" CONF_DANGEROUS_BLOCK_THRESHOLD = "dangerous_block_threshold"
RECOMMENDED_HARM_BLOCK_THRESHOLD = "BLOCK_LOW_AND_ABOVE" RECOMMENDED_HARM_BLOCK_THRESHOLD = "BLOCK_MEDIUM_AND_ABOVE"

View File

@ -263,10 +263,20 @@ class GoogleGenerativeAIConversationEntity(
genai_types.BlockedPromptException, genai_types.BlockedPromptException,
genai_types.StopCandidateException, genai_types.StopCandidateException,
) as err: ) as err:
LOGGER.error("Error sending message: %s", err) LOGGER.error("Error sending message: %s %s", type(err), err)
if isinstance(
err, genai_types.StopCandidateException
) and "finish_reason: SAFETY\n" in str(err):
error = "The message got blocked by your safety settings"
else:
error = (
f"Sorry, I had a problem talking to Google Generative AI: {err}"
)
intent_response.async_set_error( intent_response.async_set_error(
intent.IntentResponseErrorCode.UNKNOWN, intent.IntentResponseErrorCode.UNKNOWN,
f"Sorry, I had a problem talking to Google Generative AI: {err}", error,
) )
return conversation.ConversationResult( return conversation.ConversationResult(
response=intent_response, conversation_id=conversation_id response=intent_response, conversation_id=conversation_id

View File

@ -14,10 +14,10 @@
}), }),
'model_name': 'models/gemini-1.5-flash-latest', 'model_name': 'models/gemini-1.5-flash-latest',
'safety_settings': dict({ 'safety_settings': dict({
'DANGEROUS': 'BLOCK_LOW_AND_ABOVE', 'DANGEROUS': 'BLOCK_MEDIUM_AND_ABOVE',
'HARASSMENT': 'BLOCK_LOW_AND_ABOVE', 'HARASSMENT': 'BLOCK_MEDIUM_AND_ABOVE',
'HATE': 'BLOCK_LOW_AND_ABOVE', 'HATE': 'BLOCK_MEDIUM_AND_ABOVE',
'SEXUAL': 'BLOCK_LOW_AND_ABOVE', 'SEXUAL': 'BLOCK_MEDIUM_AND_ABOVE',
}), }),
'tools': None, 'tools': None,
}), }),
@ -67,10 +67,10 @@
}), }),
'model_name': 'models/gemini-1.5-flash-latest', 'model_name': 'models/gemini-1.5-flash-latest',
'safety_settings': dict({ 'safety_settings': dict({
'DANGEROUS': 'BLOCK_LOW_AND_ABOVE', 'DANGEROUS': 'BLOCK_MEDIUM_AND_ABOVE',
'HARASSMENT': 'BLOCK_LOW_AND_ABOVE', 'HARASSMENT': 'BLOCK_MEDIUM_AND_ABOVE',
'HATE': 'BLOCK_LOW_AND_ABOVE', 'HATE': 'BLOCK_MEDIUM_AND_ABOVE',
'SEXUAL': 'BLOCK_LOW_AND_ABOVE', 'SEXUAL': 'BLOCK_MEDIUM_AND_ABOVE',
}), }),
'tools': None, 'tools': None,
}), }),
@ -120,10 +120,10 @@
}), }),
'model_name': 'models/gemini-1.5-flash-latest', 'model_name': 'models/gemini-1.5-flash-latest',
'safety_settings': dict({ 'safety_settings': dict({
'DANGEROUS': 'BLOCK_LOW_AND_ABOVE', 'DANGEROUS': 'BLOCK_MEDIUM_AND_ABOVE',
'HARASSMENT': 'BLOCK_LOW_AND_ABOVE', 'HARASSMENT': 'BLOCK_MEDIUM_AND_ABOVE',
'HATE': 'BLOCK_LOW_AND_ABOVE', 'HATE': 'BLOCK_MEDIUM_AND_ABOVE',
'SEXUAL': 'BLOCK_LOW_AND_ABOVE', 'SEXUAL': 'BLOCK_MEDIUM_AND_ABOVE',
}), }),
'tools': None, 'tools': None,
}), }),
@ -173,10 +173,10 @@
}), }),
'model_name': 'models/gemini-1.5-flash-latest', 'model_name': 'models/gemini-1.5-flash-latest',
'safety_settings': dict({ 'safety_settings': dict({
'DANGEROUS': 'BLOCK_LOW_AND_ABOVE', 'DANGEROUS': 'BLOCK_MEDIUM_AND_ABOVE',
'HARASSMENT': 'BLOCK_LOW_AND_ABOVE', 'HARASSMENT': 'BLOCK_MEDIUM_AND_ABOVE',
'HATE': 'BLOCK_LOW_AND_ABOVE', 'HATE': 'BLOCK_MEDIUM_AND_ABOVE',
'SEXUAL': 'BLOCK_LOW_AND_ABOVE', 'SEXUAL': 'BLOCK_MEDIUM_AND_ABOVE',
}), }),
'tools': None, 'tools': None,
}), }),