Disable gemini content safety setting for OpenAI API and OpenRouter

function

This Filter function modifies the request payload for Google Gemini models to disable content safety filters. It adds the 'safety_settings' parameter to the request body with all harm categories set to 'BLOCK_NONE'. This is intended for use cases where Gemini's default filtering is overly restrictive. Use responsibly. Note: This function identifies Gemini models by checking if the model ID starts with 'google/gemini'. This might need adjustment depending on how your specific backend (e.g., OpenRouter, Ollama with LiteLLM Proxy) names the Gemini models.

kkoolldd
@kkoolldd
·
2 years ago
275
1
3.4K
Created Apr 8, 2025
disable_gemini_content_safety_setting_for_openai_api_and_openrouter.py
Python · 148 lines
"""
title: Gemini Safety Settings off (for OpenAI API, e.g OpenRouter)
author: Kkoolldd
author_url: Nope
version: 0.1.0
description:
  This Filter function modifies the request payload for Google Gemini models
  to disable content safety filters. It adds the 'safety_settings' parameter
  to the request body with all harm categories set to 'BLOCK_NONE'.
  This is intended for use cases where Gemini's default filtering is overly
  restrictive. Use responsibly.

This Filter function modifies the request payload for Google Gemini models to disable content safety filters. It adds the 'safety_settings' parameter to the request body with all harm categories set to 'BLOCK_NONE'. This is intended for use cases where Gemini's default filtering is overly restrictive. Use responsibly. Note: This function identifies Gemini models by checking if the model ID starts with 'google/gemini'. This might need adjustment depending on how your specific backend (e.g., OpenRouter, Ollama with LiteLLM Proxy) names the Gemini models.


1