mirror of
https://github.com/open-webui/docs
synced 2025-06-16 11:28:36 +00:00
WIP Functions Docs
This commit is contained in:
parent
031b062a89
commit
504ce9686f
@ -3,12 +3,131 @@ sidebar_position: 2
|
|||||||
title: "Functions"
|
title: "Functions"
|
||||||
---
|
---
|
||||||
|
|
||||||
# Functions
|
## What are Functions?
|
||||||
|
Tools are scripts, written in python, that are provided to an LLM at the time of the request. Tools allow LLMs to perform actions and receive additional context as a result. Generally speaking, your LLM of choice will need to support function calling for tools to be reliably utilized.
|
||||||
|
|
||||||
## WIP 🚧
|
## How can I use Functions?
|
||||||
|
Functions can be used, [once installed](#how-to-install-functions), by assigning them to an LLM or enabling them globally. Some function types will always be enabled globally, such as manifolds. To assign a function to a model, you simply need to navigate to Workspace => Models. Here you can select the model for which you’d like to enable any Functinos.
|
||||||
|
|
||||||
<p align="center">
|
Once you click the pencil icon to edit the model settings, scroll down to the Functions section and check any Functions you wish to enable. Once done you must click save.
|
||||||
<a href="#">
|
|
||||||
<img src="/img/oi/cat.png" alt="Under Construction" />
|
You also have the ability to enable Functions globally for ALL models. In order to do this, navigate to Workspace => Functions and click the "..." menu. Once the menu opens, simply enable the "Global" switch and your function will be enabled for every model in your OpenWebUI instance.
|
||||||
</a>
|
## How to install Functions
|
||||||
</p>
|
The Functions import process is quite simple. You will have two options:
|
||||||
|
|
||||||
|
### Download and import manually
|
||||||
|
Navigate to the community site: https://openwebui.com/functions/
|
||||||
|
1) Click on the Function you wish to import
|
||||||
|
2) Click the blue “Get” button in the top right-hand corner of the page
|
||||||
|
3) Click “Download as JSON export”
|
||||||
|
4) You can now upload the Funtion into OpenWebUI by navigating to Workspace => Functions and clicking “Import Functions
|
||||||
|
|
||||||
|
### Import via your OpenWebUI URL
|
||||||
|
1) Navigate to the community site: https://openwebui.com/functions/
|
||||||
|
2) Click on the Function you wish to import
|
||||||
|
3) Click the blue “Get” button in the top right-hand corner of the page
|
||||||
|
4) Enter the IP address of your OpenWebUI instance and click “Import to WebUI” which will automatically open your instance and allow you to import the Function.
|
||||||
|
|
||||||
|
Note: You can install your own Function and other Functions not tracked on the community site using the manual import method. Please do not import Functions you do not understand or are not from a trustworthy source. Running unknown code is ALWAYS a risk.
|
||||||
|
|
||||||
|
## What are the support types of functions
|
||||||
|
### Filter
|
||||||
|
Filters are used to manipulate the user input and/or the LLM output to add, remove, format, or otherwise adjust the content of the body object.
|
||||||
|
|
||||||
|
Filters have a few main components:
|
||||||
|
|
||||||
|
#### Inlet
|
||||||
|
The inlet is user to pre-process a user input before it is send to the LLM for processing.
|
||||||
|
|
||||||
|
#### Outlet
|
||||||
|
The outlet is used to post-process the output from the LLM. It is important to note that when you perform actions such as stripping/replacing content, this will happen after the output is rendered to the UI.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Example</summary>
|
||||||
|
|
||||||
|
```
|
||||||
|
class Filter:
|
||||||
|
# Define and Valves
|
||||||
|
class Valves(BaseModel):
|
||||||
|
priority: int = Field(
|
||||||
|
default=0, description="Priority level for the filter operations."
|
||||||
|
)
|
||||||
|
test_valve: int = Field(
|
||||||
|
default=4, description="A valve controlling a numberical value"
|
||||||
|
)
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Define any UserValves
|
||||||
|
class UserValves(BaseModel):
|
||||||
|
test_user_valve: bool = Field(
|
||||||
|
default=False, description="A user valve controlling a True/False (on/off) switch"
|
||||||
|
)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.valves = self.Valves()
|
||||||
|
pass
|
||||||
|
|
||||||
|
def inlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
|
||||||
|
print(f"inlet:{__name__}")
|
||||||
|
print(f"inlet:body:{body}")
|
||||||
|
print(f"inlet:user:{__user__}")
|
||||||
|
|
||||||
|
# Pre-processing logic here
|
||||||
|
|
||||||
|
return body
|
||||||
|
|
||||||
|
def outlet(self, body: dict, __user__: Optional[dict] = None) -> dict:
|
||||||
|
print(f"outlet:{__name__}")
|
||||||
|
print(f"outlet:body:{body}")
|
||||||
|
print(f"outlet:user:{__user__}")
|
||||||
|
|
||||||
|
# Post-processing logic here
|
||||||
|
|
||||||
|
return body
|
||||||
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### Action
|
||||||
|
Actions are used to create a button in the Message UI (the small buttons found directly underneath individual chat messages).
|
||||||
|
|
||||||
|
Actions have a single main component called an action. This component takes an object defining the type of action and the data being processed.
|
||||||
|
|
||||||
|
```
|
||||||
|
async def action(
|
||||||
|
self,
|
||||||
|
body: dict,
|
||||||
|
__user__=None,
|
||||||
|
__event_emitter__=None,
|
||||||
|
__event_call__=None,
|
||||||
|
) -> Optional[dict]:
|
||||||
|
print(f"action:{__name__}")
|
||||||
|
|
||||||
|
response = await __event_call__(
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"data": {
|
||||||
|
"title": "write a message",
|
||||||
|
"message": "here write a message to append",
|
||||||
|
"placeholder": "enter your message",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
print(response)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pipe
|
||||||
|
|
||||||
|
### Manifold
|
||||||
|
|
||||||
|
## Shared Function Components
|
||||||
|
|
||||||
|
### Valves and UserValves - (optional, but HIGHLY encouraged)
|
||||||
|
|
||||||
|
Valves and UserValves are used to allow users to provide dyanmic details such as an API key or a configuration option. These will create a fillable field or a bool switch in the GUI menu for the given function.
|
||||||
|
|
||||||
|
Valves are configurable by admins alone and UserValves are configurable by any users.
|
||||||
|
|
||||||
|
### Event Emitters
|
||||||
|
|
||||||
|
## What sorts of things can Functions do?
|
Loading…
Reference in New Issue
Block a user