You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4434450
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/features/extensibility/plugin/functions/filter.mdx
+5-9Lines changed: 5 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,8 @@ Let's start with the simplest representation of a Filter Function. Don't worry i
43
43
44
44
### Basic Skeleton of a Filter
45
45
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
+
46
48
```python
47
49
from pydantic import BaseModel
48
50
from typing import Optional
@@ -315,16 +317,13 @@ Filters can exist in one of four states, controlled by two boolean flags in the
315
317
316
318
| State |`is_active`|`is_global`| Effect |
317
319
|-------|------------|------------|--------|
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 |
319
321
|**Globally Disabled**|`False`|`True`| Not applied anywhere; even though the filter is globally enabled, the filter itself is disabled |
320
322
|**Model-Specific**|`True`|`False`| Only applied to models where the admin explicitly enables it |
321
323
|**Inactive**|`False`|`False`| Not applied anywhere, even if filter is enabled for a model by the admin; the filter itself is turned off |
322
324
323
325
:::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.
328
327
:::
329
328
330
329
#### Admin Panel: Making a Filter Global
@@ -339,10 +338,7 @@ To make a filter global:
339
338
5. Flip the **Global** switch in that menu
340
339
6. Ensure the filter is also **Active** (green toggle switch)
341
340
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.
346
342
347
343
**Visual Indicators:**
348
344
- Green toggle = `is_active=True` (filter is active)
Copy file name to clipboardExpand all lines: docs/features/extensibility/plugin/functions/index.mdx
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -177,6 +177,18 @@ Functions are managed from **Admin Panel > Functions**. The page is hidden when
177
177
|**Valves** (gear icon) | Opens the admin-configurable settings for this function. |
178
178
|**Export / Delete**| Export the function as a file or remove it. |
179
179
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
+
180
192
### Version history
181
193
182
194
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