I'm developing a command line client for Gemini, using the API on Vertex AI. I am referring to Gemini Pro 1.0 REST API. I would like to report a strange behavior. For testing purposes I use simple prompts, such as "In about {NUMBER} words describe {CITY NAME}". If the city is Paris, the token generation, i.e. the response, is blocked with "finish Reason": "SAFETY" and "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT".
When the API parameter "temperature" is set to 0 the behavior is systematic (90%). When set to 1 it happens less often (30%).
By default the threshold of "safetySettings" is "BLOCK_MEDIUM_AND_ABOVE" for all categories.
If I set the threshold to "BLOCK_ONLY_HIGH", for the category "HARM_CATEGORY_SEXUALLY_EXPLICIT", the token generation completes without problems. More details below.
PROMPT: "In about 80 words describe Paris."
PAYLOAD:
{
"generationConfig": {
"temperature": 0,
"topP": 1,
"topK": 40,
"candidateCount": 1,
"maxOutputTokens": 1000
},
"contents": [
{
"parts": [
{
"text": "In about 80 words describe Paris."
}
],
"role": "USER"
}
],
"safetySettings": [
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
}
]
}
INCOMPLETE RESPONSE:
Paris, the City of Lights, is a captivating metropolis renowned for its iconic landmarks, rich history, and vibrant culture. From the majestic Eiffel Tower to the historic Louvre Museum, Paris exudes an unparalleled charm. Its cobblestone streets, charming cafes, and world-class fashion boutiques create an enchanting atmosphere. The city is {STOP HERE: finish reason: SAFETY "HARM_CATEGORY_SEXUALLY_EXPLICIT"}.
CHANGE THRESHOLD:
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_ONLY_HIGH"
}
RESPONSE OK:
Paris, the City of Lights, is a captivating metropolis renowned for its iconic landmarks, rich history, and vibrant culture. From the majestic Eiffel Tower to the historic Louvre Museum, Paris exudes an unparalleled charm. Its cobblestone streets, charming cafes, and world-class fashion boutiques create an enchanting atmosphere. The city is a melting pot of art, music, and literature, with countless museums, theaters, and bookstores. Paris is a city that captivates the senses, offering a blend of elegance, romance, and cultural immersion.
As you can see the follow-up is a normal description: "The city is {HERE WAS STOPPED} a melting pot of art, music, etc... {NOT SEXUALLY RELATED}".
It doesn't hurt my work, I just wanted to point it out.
Ciao
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 |