[GH-ISSUE #7331] System and user valves are not used for functions (filters) #53372

Closed
opened 2026-05-05 14:39:54 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @clang88 on GitHub (Nov 25, 2024).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/7331

Bug Report

Installation Method

Installed via official docker repo ghcr.io/open-webui/open-webui:main

Environment

  • Open WebUI Version: 0.4.4

  • Operating System: Ubuntu 2204 (Server), Windows 10 (Client)

  • Browser (if applicable): Chrome 131

Confirmation:

  • I have read and followed all the instructions provided in the README.md.
  • I am on the latest version of both Open WebUI and Ollama.
  • [] I have included the browser console logs.
  • [] I have included the Docker container logs.
  • I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.

Expected Behavior:

When setting a valve via user valves or system valves, the value of that particular item is set in the class "Valves" oder "UserValves".
E.g. if I set Source Language to "English" I expect that self.UserValves.sourceLanguage returns "English"

Actual Behavior:

self.UserValves.sourceLanguage and self.Vavlves.sourceLanguage always return the default value, no matter what is set in the user valves or the system valves (valves in "Functions" of admin panel).

Reproduction Details

Steps to Reproduce:

  1. Create a new filter/function
  • You may use the default template for the conversation turns or the attached modified one, that outputs the Valve values.
  1. Set the UserValues for the filter function "Conversation turns" to 1 (you may also try to set the valves in "Functions" menu as Admin, same result)
  2. Observe how you can still do as many turns as defined in the defaults

Logs and Screenshots

Screenshots/Screen Recordings (if applicable):
image

Additional Information

The UI says that valves are saved, whenever I change them, but this is not reflected in the filter output

Modified conversation turns code for quicker testing:

"""
title: Example Filter
author: open-webui
author_url: https://github.com/open-webui
funding_url: https://github.com/open-webui
version: 0.1
"""

from pydantic import BaseModel, Field
from typing import Optional


class Filter:
    class Valves(BaseModel):
        priority: int = Field(
            default=0, description="Priority level for the filter operations."
        )
        max_turns: int = Field(
            default=8, description="Maximum allowable conversation turns for a user."
        )
        pass

    class UserValves(BaseModel):
        max_turns: int = Field(
            default=4, description="Maximum allowable conversation turns for a user."
        )
        pass

    def __init__(self):
        # Indicates custom file handling logic. This flag helps disengage default routines in favor of custom
        # implementations, informing the WebUI to defer file-related operations to designated methods within this class.
        # Alternatively, you can remove the files directly from the body in from the inlet hook
        # self.file_handler = True

        # Initialize 'valves' with specific configurations. Using 'Valves' instance helps encapsulate settings,
        # which ensures settings are managed cohesively and not confused with operational flags like 'file_handler'.
        self.valves = self.Valves()
        self.user_valves = self.UserValves()
        pass

    def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
        # Modify the request body or validate it before processing by the chat completion API.
        # This function is the pre-processor for the API where various checks on the input can be performed.
        # It can also modify the request before sending it to the API.
        print(f"inlet:{__name__}")
        print(f"inlet:body:{body}")
        print(f"inlet:user:{__user__}")

        if __user__.get("role", "admin") in ["user", "admin"]:
            messages = body.get("messages", [])

            max_turns = min(__user__["valves"].max_turns, self.valves.max_turns)
            if len(messages) > max_turns:
                raise Exception(
                    f"Conversation turn limit exceeded. Max turns: {max_turns}"
                )

        return body

    def outlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
        # Modify or analyze the response body after processing by the API.
        # This function is the post-processor for the API, which can be used to modify the response
        # or perform additional checks and analytics.
        print(f"outlet:{__name__}")
        print(f"outlet:body:{body}")
        print(f"outlet:user:{__user__}")
        messages = body.get("messages", [])
        messages[-1]["content"] = (
            messages[-1]["content"]
            + "\n"
            + " self.Valves: "
            + str(self.valves)
            + " / "
            + "self.UserValves: "
            + str(self.user_valves)
        )

        return body```
Originally created by @clang88 on GitHub (Nov 25, 2024). Original GitHub issue: https://github.com/open-webui/open-webui/issues/7331 # Bug Report ## Installation Method Installed via official docker repo ghcr.io/open-webui/open-webui:main ## Environment - **Open WebUI Version:** 0.4.4 - **Operating System:** Ubuntu 2204 (Server), Windows 10 (Client) - **Browser (if applicable):** Chrome 131 **Confirmation:** - [x] I have read and followed all the instructions provided in the README.md. - [x] I am on the latest version of both Open WebUI and Ollama. - [] I have included the browser console logs. - [] I have included the Docker container logs. - [x] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below. ## Expected Behavior: When setting a valve via user valves or system valves, the value of that particular item is set in the class "Valves" oder "UserValves". E.g. if I set Source Language to "English" I expect that `self.UserValves.sourceLanguage` returns "English" ## Actual Behavior: `self.UserValves.sourceLanguage` and `self.Vavlves.sourceLanguage` always return the default value, no matter what is set in the user valves or the system valves (valves in "Functions" of admin panel). ## Reproduction Details **Steps to Reproduce:** 1. Create a new filter/function * You may use the default template for the conversation turns or the attached modified one, that outputs the Valve values. 3. Set the UserValues for the filter function "Conversation turns" to 1 (you may also try to set the valves in "Functions" menu as Admin, same result) 4. Observe how you can still do as many turns as defined in the defaults ## Logs and Screenshots **Screenshots/Screen Recordings (if applicable):** ![image](https://github.com/user-attachments/assets/7fdc7144-8cd8-4390-9432-857b43a55289) ## Additional Information The UI says that valves are saved, whenever I change them, but this is not reflected in the filter output Modified conversation turns code for quicker testing: ```python """ title: Example Filter author: open-webui author_url: https://github.com/open-webui funding_url: https://github.com/open-webui version: 0.1 """ from pydantic import BaseModel, Field from typing import Optional class Filter: class Valves(BaseModel): priority: int = Field( default=0, description="Priority level for the filter operations." ) max_turns: int = Field( default=8, description="Maximum allowable conversation turns for a user." ) pass class UserValves(BaseModel): max_turns: int = Field( default=4, description="Maximum allowable conversation turns for a user." ) pass def __init__(self): # Indicates custom file handling logic. This flag helps disengage default routines in favor of custom # implementations, informing the WebUI to defer file-related operations to designated methods within this class. # Alternatively, you can remove the files directly from the body in from the inlet hook # self.file_handler = True # Initialize 'valves' with specific configurations. Using 'Valves' instance helps encapsulate settings, # which ensures settings are managed cohesively and not confused with operational flags like 'file_handler'. self.valves = self.Valves() self.user_valves = self.UserValves() pass def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict: # Modify the request body or validate it before processing by the chat completion API. # This function is the pre-processor for the API where various checks on the input can be performed. # It can also modify the request before sending it to the API. print(f"inlet:{__name__}") print(f"inlet:body:{body}") print(f"inlet:user:{__user__}") if __user__.get("role", "admin") in ["user", "admin"]: messages = body.get("messages", []) max_turns = min(__user__["valves"].max_turns, self.valves.max_turns) if len(messages) > max_turns: raise Exception( f"Conversation turn limit exceeded. Max turns: {max_turns}" ) return body def outlet(self, body: dict, __user__: Optional[dict] = None) -> dict: # Modify or analyze the response body after processing by the API. # This function is the post-processor for the API, which can be used to modify the response # or perform additional checks and analytics. print(f"outlet:{__name__}") print(f"outlet:body:{body}") print(f"outlet:user:{__user__}") messages = body.get("messages", []) messages[-1]["content"] = ( messages[-1]["content"] + "\n" + " self.Valves: " + str(self.valves) + " / " + "self.UserValves: " + str(self.user_valves) ) return body```
Author
Owner

@clang88 commented on GitHub (Nov 25, 2024):

P.S.: It seems to work fine for "Tools".
Snapshot from system valves:
image
Snapshot from returned "Tools" call
image

Correction: It only works for the system valves, not for the user valves:
image

<!-- gh-comment-id:2497866119 --> @clang88 commented on GitHub (Nov 25, 2024): P.S.: It seems to work fine for "Tools". Snapshot from system valves: ![image](https://github.com/user-attachments/assets/6226e4df-a5c4-40bf-a7d8-bedda2fbae81) Snapshot from returned "Tools" call ![image](https://github.com/user-attachments/assets/9db153cf-8053-43c7-bb2f-6460981cd262) Correction: It only works for the system valves, not for the user valves: ![image](https://github.com/user-attachments/assets/758212ec-4c54-4fc2-adbd-d48579233208)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#53372