[PR #18008] [CLOSED] feat: add dynamic enum support for UserValves/Valves with API-driven dropdowns #63492

Closed
opened 2026-05-06 08:18:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/18008
Author: @Simon-Stone
Created: 10/2/2025
Status: Closed

Base: devHead: valves-dynamic-enum


📝 Commits (1)

📊 Changes

1 file changed (+208 additions, -0 deletions)

View changed files

📝 src/lib/components/common/Valves.svelte (+208 -0)

📄 Description

feat: Add dynamic enum support for UserValves/Valves with API-driven dropdowns

Description

This pull request introduces dynamic enum population for UserValves and Valves in Functions and Tools. Instead of hardcoding dropdown options, developers can now specify API endpoints that are queried at runtime with user authentication, allowing for user-specific, permission-based dropdown options.

This enhancement solves a critical limitation where dropdown options couldn't be personalized based on the authenticated user's context. For example, a UserValve for "preferred model" can now show only the models the specific user has access to, rather than all models in the system.

Key Benefits:

  • User-specific dropdown options based on permissions
  • Real-time data from API endpoints
  • Smart caching with configurable TTL
  • Manual refresh capability for testing
  • Zero breaking changes to existing code

Added

  • Dynamic enum configuration via json_schema_extra: Pydantic Field definitions now support a dynamic_enum parameter that tells the frontend which API endpoint to query
  • Frontend dynamic enum fetching in Valves.svelte:
    • Automatic detection and initialization of dynamic enum fields
    • HTTP requests with Bearer token authentication
    • Response path extraction for nested data structures
    • Per-endpoint caching with configurable TTL (default 5 minutes)
    • Request deduplication to prevent simultaneous duplicate calls
  • Refresh button UI: Manual cache invalidation button next to each dynamic enum dropdown for testing and development

Changed

  • src/lib/components/common/Valves.svelte: Extended to detect and render dynamic enum fields with API-driven options
  • Enhanced valve rendering logic to support three dropdown types: static enum, dynamic enum, and boolean switches

Deprecated

  • None

Removed

  • None

Fixed

  • None (this is a new feature)

Security

  • All API requests include user Bearer token authentication
  • Endpoints validate user permissions server-side
  • Frontend sanitizes API responses before rendering
  • No CORS issues (uses existing WEBUI_API_BASE_URL)

Breaking Changes

  • None. This is a fully backward-compatible opt-in feature. Existing Valves/UserValves continue working unchanged.

Additional Information

Configuration Example:

from pydantic import BaseModel, Field

class UserValves(BaseModel):
    preferred_model: str = Field(
        default="",
        description="Select your preferred chat model",
        json_schema_extra={
            "dynamic_enum": {
                "endpoint": "/models",
                "response_path": "data",  # Extract array from nested response
                "value_field": "id",
                "label_field": "name",
                "cache_ttl": 300,  # Cache for 5 minutes
                "fallback": []     # Fallback options if fetch fails
            }
        }
    )

Technical Implementation:

  • Pydantic extracts json_schema_extra fields to the top level of the JSON schema, making dynamic_enum directly accessible on property specs
  • Frontend reactive initialization ensures dynamic enums load when valve modal opens
  • Smart caching strategy balances performance with data freshness
  • Graceful degradation with fallback options and error messages

Use Cases:

  • Model selection filtered by user permissions
  • Knowledge base selection showing only user-accessible bases
  • Tool/resource dropdowns based on user role
  • Any scenario requiring user-context-dependent options

Screenshots or Videos

image

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/18008 **Author:** [@Simon-Stone](https://github.com/Simon-Stone) **Created:** 10/2/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `valves-dynamic-enum` --- ### 📝 Commits (1) - [`2451c2e`](https://github.com/open-webui/open-webui/commit/2451c2ef953a97baca44d394dd2a32da2211019b) feat: dynamic enums ### 📊 Changes **1 file changed** (+208 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/lib/components/common/Valves.svelte` (+208 -0) </details> ### 📄 Description # feat: Add dynamic enum support for UserValves/Valves with API-driven dropdowns ### Description This pull request introduces dynamic enum population for UserValves and Valves in Functions and Tools. Instead of hardcoding dropdown options, developers can now specify API endpoints that are queried at runtime with user authentication, allowing for user-specific, permission-based dropdown options. This enhancement solves a critical limitation where dropdown options couldn't be personalized based on the authenticated user's context. For example, a UserValve for "preferred model" can now show only the models the specific user has access to, rather than all models in the system. **Key Benefits:** - User-specific dropdown options based on permissions - Real-time data from API endpoints - Smart caching with configurable TTL - Manual refresh capability for testing - Zero breaking changes to existing code ### Added - **Dynamic enum configuration via `json_schema_extra`**: Pydantic Field definitions now support a `dynamic_enum` parameter that tells the frontend which API endpoint to query - **Frontend dynamic enum fetching in `Valves.svelte`**: - Automatic detection and initialization of dynamic enum fields - HTTP requests with Bearer token authentication - Response path extraction for nested data structures - Per-endpoint caching with configurable TTL (default 5 minutes) - Request deduplication to prevent simultaneous duplicate calls - **Refresh button UI**: Manual cache invalidation button next to each dynamic enum dropdown for testing and development ### Changed - **`src/lib/components/common/Valves.svelte`**: Extended to detect and render dynamic enum fields with API-driven options - Enhanced valve rendering logic to support three dropdown types: static enum, dynamic enum, and boolean switches ### Deprecated - None ### Removed - None ### Fixed - None (this is a new feature) ### Security - All API requests include user Bearer token authentication - Endpoints validate user permissions server-side - Frontend sanitizes API responses before rendering - No CORS issues (uses existing WEBUI_API_BASE_URL) ### Breaking Changes - None. This is a fully backward-compatible opt-in feature. Existing Valves/UserValves continue working unchanged. --- ### Additional Information **Configuration Example:** ```python from pydantic import BaseModel, Field class UserValves(BaseModel): preferred_model: str = Field( default="", description="Select your preferred chat model", json_schema_extra={ "dynamic_enum": { "endpoint": "/models", "response_path": "data", # Extract array from nested response "value_field": "id", "label_field": "name", "cache_ttl": 300, # Cache for 5 minutes "fallback": [] # Fallback options if fetch fails } } ) ``` **Technical Implementation:** - Pydantic extracts `json_schema_extra` fields to the top level of the JSON schema, making `dynamic_enum` directly accessible on property specs - Frontend reactive initialization ensures dynamic enums load when valve modal opens - Smart caching strategy balances performance with data freshness - Graceful degradation with fallback options and error messages **Use Cases:** - Model selection filtered by user permissions - Knowledge base selection showing only user-accessible bases - Tool/resource dropdowns based on user role - Any scenario requiring user-context-dependent options ### Screenshots or Videos <img width="551" height="410" alt="image" src="https://github.com/user-attachments/assets/147278c4-e29a-4ab4-aa08-0960235c955a" /> ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-06 08:18:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#63492