[PR #5281] [CLOSED] feat: persist functions self.valves to database during function create #37292

Closed
opened 2026-04-25 10:50:11 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/5281
Author: @ndrsfel
Created: 9/8/2024
Status: Closed

Base: devHead: persist-valves-to-db-at-create


📝 Commits (9)

📊 Changes

2 files changed (+9 additions, -2 deletions)

View changed files

📝 backend/open_webui/apps/webui/models/functions.py (+3 -1)
📝 backend/open_webui/apps/webui/routers/functions.py (+6 -1)

📄 Description

Changelog Entry

Description

  • Added a feature that adds self.valves during Pipe.__init__() to function.valves entry in the database and empty if not defined during init.
  • This is especially useful, if you want to persist environment variable as valve values and follow best practice with functions valves.

Additional Information

Replicate with minimal example

import os
from typing import List, Union, Generator, Iterator
from pydantic import BaseModel, Field

class Pipe:
    class Valves(BaseModel):
        API_KEY: str = Field(default="default-value")

    def __init__(self):
        self.type = "manifold"
        self.id = "my-id"
        self.name = "my-prefix/"
        self.valves = self.Valves(
            **{"API_KEY": os.getenv("API_KEY", "")}
        )

    def pipes(self) -> List[dict]:
        print(f"{self.valves=}") # this used to be "API_KEY=default-value" previously instead of API_KEY from env
        return {"id": "my-id", "name": "my-name"}
    
    def pipe(self, body: dict) -> Union[str, Generator, Iterator]:
        return body

🔄 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/5281 **Author:** [@ndrsfel](https://github.com/ndrsfel) **Created:** 9/8/2024 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `persist-valves-to-db-at-create` --- ### 📝 Commits (9) - [`05c0423`](https://github.com/open-webui/open-webui/commit/05c0423d6eba64c78fbcfeda4059e54160d2fd35) Merge pull request #5197 from open-webui/dev - [`4617f3a`](https://github.com/open-webui/open-webui/commit/4617f3a4e277a716ab75460934257813d8865663) Merge pull request #5200 from open-webui/dev - [`e2ef36b`](https://github.com/open-webui/open-webui/commit/e2ef36b582b06f1edef0fe84064ce4ae45fa085b) Merge pull request #5238 from open-webui/dev - [`71a2bd2`](https://github.com/open-webui/open-webui/commit/71a2bd2fea32052204fc5198d66e6aa919c9b419) Merge pull request #5247 from open-webui/dev - [`98eaec2`](https://github.com/open-webui/open-webui/commit/98eaec22d4a28f81885cd69fc45bfa20b8cc6fd1) Merge pull request #5248 from open-webui/dev - [`2544f7e`](https://github.com/open-webui/open-webui/commit/2544f7eaf0c71bc668963b9a0c0d160e6c0a7707) Merge pull request #5249 from open-webui/dev - [`50db51e`](https://github.com/open-webui/open-webui/commit/50db51ebe08c018bf46acfaf55985ff998da50bc) Merge pull request #5262 from open-webui/dev - [`e510c8b`](https://github.com/open-webui/open-webui/commit/e510c8b11f0f898796635cf09aa93a3d72c4c2ee) Merge pull request #5263 from open-webui/dev - [`289207e`](https://github.com/open-webui/open-webui/commit/289207e3deab8c126a2073ab50326a39b41615d9) persist valves to db during create ### 📊 Changes **2 files changed** (+9 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/apps/webui/models/functions.py` (+3 -1) 📝 `backend/open_webui/apps/webui/routers/functions.py` (+6 -1) </details> ### 📄 Description # Changelog Entry ### Description - Added a feature that adds `self.valves` during `Pipe.__init__()` to `function.valves` entry in the database and empty if not defined during init. - This is especially useful, if you want to persist environment variable as valve values and follow best practice with functions valves. --- ### Additional Information Replicate with minimal example ```python import os from typing import List, Union, Generator, Iterator from pydantic import BaseModel, Field class Pipe: class Valves(BaseModel): API_KEY: str = Field(default="default-value") def __init__(self): self.type = "manifold" self.id = "my-id" self.name = "my-prefix/" self.valves = self.Valves( **{"API_KEY": os.getenv("API_KEY", "")} ) def pipes(self) -> List[dict]: print(f"{self.valves=}") # this used to be "API_KEY=default-value" previously instead of API_KEY from env return {"id": "my-id", "name": "my-name"} def pipe(self, body: dict) -> Union[str, Generator, Iterator]: return body ``` --- <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-04-25 10:50:11 -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#37292