Skip to content

Commit 4434450

Browse files
committed
docs: explain Function activation and filter scope
1 parent 19550c5 commit 4434450

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎docs/features/extensibility/plugin/functions/filter.mdx‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Let's start with the simplest representation of a Filter Function. Don't worry i
4343

4444
### Basic Skeleton of a Filter
4545

46+
Each server worker caches the `Filter` instance by Function ID and can reuse it across requests. Keep request-specific values in hook arguments or local variables. For example, calculate a request's token count in `inlet()` using a local variable and reserve instance attributes for configuration such as `self.toggle`.
47+
4648
```python
4749
from pydantic import BaseModel
4850
from typing import Optional
@@ -315,16 +317,13 @@ Filters can exist in one of four states, controlled by two boolean flags in the
315317

316318
| State | `is_active` | `is_global` | Effect |
317319
|-------|------------|------------|--------|
318-
| **Globally Enabled** | `True` | `True` | Applied to **ALL** models automatically, cannot be disabled per-model |
320+
| **Globally Enabled** | `True` | `True` | Available on all models automatically |
319321
| **Globally Disabled** | `False` | `True` | Not applied anywhere; even though the filter is globally enabled, the filter itself is disabled |
320322
| **Model-Specific** | `True` | `False` | Only applied to models where the admin explicitly enables it |
321323
| **Inactive** | `False` | `False` | Not applied anywhere, even if filter is enabled for a model by the admin; the filter itself is turned off |
322324

323325
:::tip Global Filter Behavior
324-
When a filter is set as **Global** (`is_global=True`) and **Active** (`is_active=True`), it becomes **force-enabled** for all models:
325-
- It appears in every model's filter list as **checked and greyed out**
326-
- Admins **cannot** uncheck it in model settings
327-
- It runs on **every** chat completion request, regardless of model
326+
An active global filter is in scope for every model. It appears checked and greyed out in model settings. An always-on filter runs automatically, while a [user-toggleable filter](#toggleable-filters-making-filters-user-controllable-selftoggle) runs only when its ID is in the request's `filter_ids`. If a chat completion API caller omits `filter_ids`, the server uses an empty selection. The chat UI uses the model's `defaultFilterIds` to initialize its selection.
328327
:::
329328

330329
#### Admin Panel: Making a Filter Global
@@ -339,10 +338,7 @@ To make a filter global:
339338
5. Flip the **Global** switch in that menu
340339
6. Ensure the filter is also **Active** (green toggle switch)
341340

342-
**API Endpoint:**
343-
```http
344-
POST /api/v1/functions/id/{filter_id}/toggle/global
345-
```
341+
Use the [Function activation API](./index.mdx#activation-via-api) to read or change the **Active** and **Global** flags programmatically.
346342

347343
**Visual Indicators:**
348344
- Green toggle = `is_active=True` (filter is active)

‎docs/features/extensibility/plugin/functions/index.mdx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ Functions are managed from **Admin Panel > Functions**. The page is hidden when
177177
| **Valves** (gear icon) | Opens the admin-configurable settings for this function. |
178178
| **Export / Delete** | Export the function as a file or remove it. |
179179

180+
### Activation via API
181+
182+
These endpoints require an administrator. A successful `POST /api/v1/functions/create` creates a Function with `is_active: false` and `is_global: false`.
183+
184+
| Endpoint | Result |
185+
|:---------|:-------|
186+
| `GET /api/v1/functions/id/{id}` | Returns the Function, including its current `is_active` and `is_global` values. |
187+
| `POST /api/v1/functions/id/{id}/toggle` | Flips `is_active` and returns the updated Function. |
188+
| `POST /api/v1/functions/id/{id}/toggle/global` | Flips `is_global` and returns the updated Function. |
189+
190+
Call a toggle only when the current value differs from the desired value. If a request times out, read the current state before deciding whether to retry. For an active Filter, the Global flag controls which models it is available on. [User-toggleable filters](/features/extensibility/plugin/functions/filter#toggleable-filters-making-filters-user-controllable-selftoggle) also require a selection in the chat request.
191+
180192
### Version history
181193

182194
Functions keep a version history that works like the one for tools: the version picker next to **Back**, **Compare to current**, **Set as Production** and **Delete**. See [Version history](/features/extensibility/plugin/tools#version-history) for the details. For functions:

0 commit comments

Comments
 (0)