Add safety settings support

Created on 6 August 2024, 9 months ago

Problem/Motivation

We need to implement safety settings (similar to moderation in openai terms).

Proposed resolution

First, in Gemini's settings form needs to be added relevant fields to define default safety settings and then, in plugin's chat() method, we need to pass safety settings (now defaults are used).

πŸ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡ͺGeorgia jibla

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @jibla
  • Status changed to Active 9 months ago
  • πŸ‡¬πŸ‡ͺGeorgia jibla
  • πŸ‡¬πŸ‡ͺGeorgia jibla
  • Assigned to vasike
  • Status changed to Needs work 3 months ago
  • πŸ‡·πŸ‡΄Romania vasike Ramnicu Valcea
  • πŸ‡·πŸ‡΄Romania vasike Ramnicu Valcea

    Created a Draft MR for this ... trying to cover issue description ... as I could imagined.

    However not sure about:
    - Not All Combination of Category - Thresholds works ... and from documentation is not clear if there is a mapping or some rules
    Also if they different per Model in Use.
    As results - a lot of "combinations" tried throws errors ...

    - If those safety settings should be at the Provider level ... or they should be at the "usage" level ... where actually the "request" are built/"prepared".

    - Maybe, also the PHP client library should provide more on this "subject".

    I'll set on Needs Review - temporarily - just ot gain some attention and find a plan for this - at least.

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    a.dmitriiev β†’ made their first commit to this issue’s fork.

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    I have also added moderation operation type support to the provider. There is still some work needed. For some reason the request with safety settings fail with the error:

    * GenerateContentRequest.safety_settings[0]: element predicate failed: $.category in (HarmCategory.HARM_CATEGORY_HATE_SPEECH, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, HarmCategory.HARM_CATEGORY_HARASSMENT, HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY)
    * GenerateContentRequest.safety_settings[1]: element predicate failed: $.category in (HarmCategory.HARM_CATEGORY_HATE_SPEECH, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, HarmCategory.HARM_CATEGORY_HARASSMENT, HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY)
    * GenerateContentRequest.safety_settings[2]: element predicate failed: $.category in (HarmCategory.HARM_CATEGORY_HATE_SPEECH, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, HarmCategory.HARM_CATEGORY_HARASSMENT, HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY)
    * GenerateContentRequest.safety_settings[3]: element predicate failed: $.category in (HarmCategory.HARM_CATEGORY_HATE_SPEECH, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, HarmCategory.HARM_CATEGORY_HARASSMENT, HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY)
    * GenerateContentRequest.safety_settings[4]: element predicate failed: $.category in (HarmCategory.HARM_CATEGORY_HATE_SPEECH, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, HarmCategory.HARM_CATEGORY_HARASSMENT, HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY)
    * GenerateContentRequest.safety_settings[5]: element predicate failed: $.category in (HarmCategory.HARM_CATEGORY_HATE_SPEECH, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, HarmCategory.HARM_CATEGORY_HARASSMENT, HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY)
    * GenerateContentRequest.safety_settings[6]: element predicate failed: $.category in (HarmCategory.HARM_CATEGORY_HATE_SPEECH, HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, HarmCategory.HARM_CATEGORY_HARASSMENT, HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY)

  • Pipeline finished with Failed
    2 months ago
    Total: 159s
    #423141
  • Pipeline finished with Success
    2 months ago
    Total: 163s
    #423157
  • πŸ‡·πŸ‡΄Romania vasike Ramnicu Valcea

    Fix MR conflicts and PHP CS ...

    also put some comment on moderation code there ... It seems it tries to uses OpenAI provider "code".

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    I have removed the moderation operation support to unblock this issue as it was a bit out of scope and not ready.

  • Pipeline finished with Success
    2 months ago
    Total: 204s
    #423188
  • Pipeline finished with Success
    2 months ago
    Total: 152s
    #424383
  • πŸ‡¬πŸ‡ͺGeorgia jibla

    Assigning to Lekso for review.

Production build 0.71.5 2024