Merge pull request #155 from 0xThresh/enh-pipelines-docs

Added Valves document, minor updates to others
This commit is contained in:
0xThresh 2024-07-24 21:25:52 -06:00 committed by GitHub
commit 19e54a3507
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 3 deletions

View File

@ -1,9 +1,9 @@
--- ---
sidebar_position: 3 sidebar_position: 1
title: "Filter Pipelines" title: "Filters"
--- ---
# Filter Pipelines # Filters
Filters are used to perform actions against incoming user messages and outgoing assistant (LLM) messages. Potential actions that can be taken in a filter include sending messages to monitoring platforms (such as Langfuse or DataDog), modifying message contents, blocking toxic messages, translating messages to another language, or rate limiting messages from certain users. A list of examples is maintained in the [Pipelines repo](https://github.com/open-webui/pipelines/tree/main/examples/filters). The general workflow can be seen in the image below. Filters are used to perform actions against incoming user messages and outgoing assistant (LLM) messages. Potential actions that can be taken in a filter include sending messages to monitoring platforms (such as Langfuse or DataDog), modifying message contents, blocking toxic messages, translating messages to another language, or rate limiting messages from certain users. A list of examples is maintained in the [Pipelines repo](https://github.com/open-webui/pipelines/tree/main/examples/filters). The general workflow can be seen in the image below.
<p align="center"> <p align="center">

29
docs/pipelines/valves.md Normal file
View File

@ -0,0 +1,29 @@
---
sidebar_position: 3
title: "Valves"
---
# Valves
Valves are input variables that are set per pipeline. Valves are set as a subclass of the `Pipeline` class, and initialized as part of the `__init__` method of the `Pipeline` class.
When adding valves to your pipeline, include a way to ensure that valves can be reconfigured by admins in the web UI. There are a few options for this:
- Use `os.getenv()` to set an environment variable to use for the pipeline, and a default value to use if the environment variable isn't set. An example can be seen below:
```
self.valves = self.Valves(
**{
"LLAMAINDEX_OLLAMA_BASE_URL": os.getenv("LLAMAINDEX_OLLAMA_BASE_URL", "http://localhost:11434"),
"LLAMAINDEX_MODEL_NAME": os.getenv("LLAMAINDEX_MODEL_NAME", "llama3"),
"LLAMAINDEX_EMBEDDING_MODEL_NAME": os.getenv("LLAMAINDEX_EMBEDDING_MODEL_NAME", "nomic-embed-text"),
}
)
```
- Set the valve to the `Optional` type, which will allow the pipeline to load even if no value is set for the valve.
```
class Pipeline:
class Valves(BaseModel):
target_user_roles: List[str] = ["user"]
max_turns: Optional[int] = None
```
If you don't leave a way for valves to be updated in the web UI, you'll see the following error in the Pipelines server log after trying to add a pipeline to the web UI:
`WARNING:root:No Pipeline class found in <pipeline name>`