semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net Gemini Connector - GeminiPromptExecutionSettings with multiple GeminiSafetyCategory throw a 400 exception.

Open gonsss opened this issue 1 year ago • 1 comments

Describe the bug When I specify multiple SafetySettings I get a 400 Bad Request.

To Reproduce Steps to reproduce the behavior:

  1. This code throws an exception
  2. GeminiPromptExecutionSettings proSettings = new () { Temperature=0, TopP = 1, //TopK = 20, MaxTokens = 8102, SafetySettings = [ new(GeminiSafetyCategory.Harassment, GeminiSafetyThreshold.BlockOnlyHigh), new(GeminiSafetyCategory.Dangerous, GeminiSafetyThreshold.BlockOnlyHigh), new(GeminiSafetyCategory.DangerousContent, GeminiSafetyThreshold.BlockOnlyHigh) ], ModelId=geminiProModelId,

}; This happens with Microsoft.SemanticKernel.Connectors.Google, 1.14.1-alpha . If I leave only one, the call works as expected.

Platform

  • OS: W11
  • IDE: Code -> I have reproduced this behavior on a .NET console App and a .NET Notebook.
  • Language: C#

gonsss avatar Jun 09 '24 14:06 gonsss

This functionality is implemented correctly, but during developing gemini connector I discovered documentation of gemini is often invalid. Maybe you got error due to used two similar categories Dangerous and DangerousContent.

From GEMINI DOCS

This will be enforced on the GenerateContentRequest.contents and GenerateContentResponse.candidates. There should not be more than one setting for each SafetyCategory type. The API will block any contents and responses that fail to meet the thresholds set by these settings. This list overrides the default settings for each SafetyCategory specified in the safetySettings. If there is no SafetySetting for a given SafetyCategory provided in the list, the API will use the default safety setting for that category. Harm categories HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT, HARM_CATEGORY_HARASSMENT are supported.

Krzysztof318 avatar Jun 30 '24 17:06 Krzysztof318

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Nov 11 '24 02:11 github-actions[bot]

Closing as stale

markwallace-microsoft avatar Nov 25 '24 13:11 markwallace-microsoft