@owndev v1.20.0 google_gemini.py
Python · 6,516 lines467 class Valves(BaseModel):468 BASE_URL: str = Field(469 default=os.getenv(470 "GOOGLE_GENAI_BASE_URL", "https://generativelanguage.googleapis.com/"471 ),472 description="Base URL for the Google Generative AI API.",473 )474 GOOGLE_API_KEY: EncryptedStr = Field(475 default=os.getenv("GOOGLE_API_KEY", ""),476 description="API key for Google Generative AI (used if USE_VERTEX_AI is false).",477 json_schema_extra={"input": {"type": "password"}},478 ) Google Gemini Pipeline
Highly optimized Google Gemini pipeline with advanced image and video generation capabilities, intelligent compression, and streamlined processing workflows.
Features
- Optimized asynchronous API calls for maximum performance
- Intelligent model caching with configurable TTL, refreshed at once when model valves change
- Streamlined dynamic model specification with automatic prefix handling
- Smart streaming response handling with safety checks
- Retries of temporary API errors for streaming and non-streaming requests
- Advanced multimodal input support (text and images)
- Unified image generation and editing with Gemini 2.5 Flash Image Preview
- Image editing across turns: earlier generated and uploaded images of a saved chat are sent with the edit request (the newest kept within the image limit, each image once; the pipeline reads only files of the requesting user)
- Nano Banana image models (gemini-3.1-flash-image, gemini-3.1-flash-lite-image, gemini-nano-banana-2.1)
- Extra image generation model IDs configurable without a code change
- Interim thought images skipped, so each generated image is uploaded once (the last one is kept if no final image arrives)
- Native tools and URL context left out for image models, which do not support them
- Search grounding left out for image models without Search support (gemini-2.5-flash-image, gemini-3.1-flash-lite-image)
- Intelligent image optimization with size-aware compression algorithms
- Automated image upload to Open WebUI with robust fallback support
- Generated images and videos linked in the answer for API clients
- Optimized text-to-image and image-to-image workflows
- Non-streaming mode for image generation to prevent chunk overflow
- Progressive status updates, each closed when a request ends, fails or is stopped
- Consolidated error handling and comprehensive logging
- Seamless Google Generative AI and Vertex AI integration
- Advanced generation parameters (temperature, max tokens, etc.)
- Configurable safety settings with environment variable support
- Military-grade encrypted storage of sensitive API keys
- Intelligent grounding with Google search integration
- Vertex AI Search grounding for RAG
- Native tool calling through Open WebUI's tool loop (built-in, workspace, MCP, OpenAPI, terminal and direct tools, tool approval)
- Thought signatures carried across tool rounds and turns
- Tool calls returned to API clients as OpenAI tool_calls (streaming and non-streaming)
- Google Search grounding together with function calling on Gemini 3
- URL context grounding for specified web pages
- Unified image processing with consolidated helper methods
- Optimized payload creation for image generation models
- Configurable image processing parameters (size, quality, compression)
- Flexible upload fallback options and optimization controls
- Configurable thinking levels for Gemini 3 models with model-specific validation
- Thinking summaries stripped from replayed history to save tokens (configurable)
- Configurable thinking budgets (0-32768 tokens) for Gemini 2.5 models
- Configurable image generation aspect ratio (1:1, 16:9, etc.) and resolution (1K, 2K, 4K)
- Model whitelist for filtering available models
- Additional model support for SDK-unsupported models
- Video generation with Google Veo models (Veo 3.1, 3, 2)
- Configurable video generation parameters (aspect ratio, resolution, duration)
- Asynchronous video generation with progressive polling status updates
- Automatic video upload to Open WebUI with chat file attachments
- Image-to-video generation support for Veo models
- Negative prompt and person generation controls for video
- Token usage reporting for streaming and non-streaming responses
- Usable as task model for title, tag and follow-up generation
Tools
- Grounding with Google search with google_search_tool.py filter
- Grounding with Vertex AI Search with vertex_ai_search_tool.py filter
GitHub
Note
For questions, problems, and feature requests, an issue must be created on GitHub.
License
0
15 
