mirror of
https://github.com/open-webui/pipelines
synced 2025-06-26 18:15:58 +00:00
chore
This commit is contained in:
62
examples/scaffolds/example_pipeline_scaffold.py
Normal file
62
examples/scaffolds/example_pipeline_scaffold.py
Normal file
@@ -0,0 +1,62 @@
|
||||
from typing import List, Union, Generator, Iterator
|
||||
from schemas import OpenAIChatMessage
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Pipeline:
|
||||
class Valves(BaseModel):
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
# Optionally, you can set the id and name of the pipeline.
|
||||
# Assign a unique identifier to the pipeline.
|
||||
# The identifier must be unique across all pipelines.
|
||||
# The identifier must be an alphanumeric string that can include underscores or hyphens. It cannot contain spaces, special characters, slashes, or backslashes.
|
||||
self.id = "pipeline_example"
|
||||
self.name = "Pipeline Example"
|
||||
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_valves_updated(self):
|
||||
# This function is called when the valves are updated.
|
||||
pass
|
||||
|
||||
async def inlet(self, body: dict, user: dict) -> dict:
|
||||
# This function is called before the OpenAI API request is made. You can modify the form data before it is sent to the OpenAI API.
|
||||
print(f"inlet:{__name__}")
|
||||
|
||||
print(body)
|
||||
print(user)
|
||||
|
||||
return body
|
||||
|
||||
async def outlet(self, body: dict, user: dict) -> dict:
|
||||
# This function is called after the OpenAI API response is completed. You can modify the messages after they are received from the OpenAI API.
|
||||
print(f"outlet:{__name__}")
|
||||
|
||||
print(body)
|
||||
print(user)
|
||||
|
||||
return body
|
||||
|
||||
def pipe(
|
||||
self, user_message: str, model_id: str, messages: List[dict], body: dict
|
||||
) -> Union[str, Generator, Iterator]:
|
||||
# This is where you can add your custom pipelines like RAG.
|
||||
print(f"pipe:{__name__}")
|
||||
|
||||
print(messages)
|
||||
print(user_message)
|
||||
print(body)
|
||||
|
||||
return f"{__name__} response to: {user_message}"
|
||||
63
examples/scaffolds/filter_pipeline_scaffold.py
Normal file
63
examples/scaffolds/filter_pipeline_scaffold.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
title: Filter Pipeline
|
||||
author: open-webui
|
||||
date: 2024-05-30
|
||||
version: 1.1
|
||||
license: MIT
|
||||
description: Example of a filter pipeline that can be used to edit the form data before it is sent to the OpenAI API.
|
||||
requirements: requests
|
||||
"""
|
||||
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel
|
||||
from schemas import OpenAIChatMessage
|
||||
|
||||
|
||||
class Pipeline:
|
||||
class Valves(BaseModel):
|
||||
# List target pipeline ids (models) that this filter will be connected to.
|
||||
# If you want to connect this filter to all pipelines, you can set pipelines to ["*"]
|
||||
pipelines: List[str] = []
|
||||
|
||||
# Assign a priority level to the filter pipeline.
|
||||
# The priority level determines the order in which the filter pipelines are executed.
|
||||
# The lower the number, the higher the priority.
|
||||
priority: int = 0
|
||||
|
||||
# Add your custom parameters here
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
# Pipeline filters are only compatible with Open WebUI
|
||||
# You can think of filter pipeline as a middleware that can be used to edit the form data before it is sent to the OpenAI API.
|
||||
self.type = "filter"
|
||||
|
||||
# Optionally, you can set the id and name of the pipeline.
|
||||
# Assign a unique identifier to the pipeline.
|
||||
# The identifier must be unique across all pipelines.
|
||||
# The identifier must be an alphanumeric string that can include underscores or hyphens. It cannot contain spaces, special characters, slashes, or backslashes.
|
||||
self.id = "filter_pipeline"
|
||||
self.name = "Filter"
|
||||
|
||||
self.valves = self.Valves(**{"pipelines": ["llama3:latest"]})
|
||||
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
|
||||
# This filter is applied to the form data before it is sent to the OpenAI API.
|
||||
print(f"inlet:{__name__}")
|
||||
|
||||
print(body)
|
||||
print(user)
|
||||
|
||||
return body
|
||||
27
examples/scaffolds/function_calling_scaffold.py
Normal file
27
examples/scaffolds/function_calling_scaffold.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from blueprints.function_calling_blueprint import Pipeline as FunctionCallingBlueprint
|
||||
|
||||
|
||||
class Pipeline(FunctionCallingBlueprint):
|
||||
class Valves(FunctionCallingBlueprint.Valves):
|
||||
# Add your custom parameters here
|
||||
pass
|
||||
|
||||
class Tools:
|
||||
def __init__(self, pipeline) -> None:
|
||||
self.pipeline = pipeline
|
||||
|
||||
# Add your custom tools using pure Python code here, make sure to add type hints
|
||||
# Please refer to function_calling_filter_pipeline.py for an example
|
||||
pass
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.id = "my_tools_pipeline"
|
||||
self.name = "My Tools Pipeline"
|
||||
self.valves = self.Valves(
|
||||
**{
|
||||
**self.valves.model_dump(),
|
||||
"pipelines": ["*"], # Connect to all pipelines
|
||||
},
|
||||
)
|
||||
self.tools = self.Tools(self)
|
||||
52
examples/scaffolds/manifold_pipeline_scaffold.py
Normal file
52
examples/scaffolds/manifold_pipeline_scaffold.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from typing import List, Union, Generator, Iterator
|
||||
from schemas import OpenAIChatMessage
|
||||
|
||||
|
||||
class Pipeline:
|
||||
def __init__(self):
|
||||
# You can also set the pipelines that are available in this pipeline.
|
||||
# Set manifold to True if you want to use this pipeline as a manifold.
|
||||
# Manifold pipelines can have multiple pipelines.
|
||||
self.type = "manifold"
|
||||
|
||||
# Optionally, you can set the id and name of the pipeline.
|
||||
# Assign a unique identifier to the pipeline.
|
||||
# The identifier must be unique across all pipelines.
|
||||
# The identifier must be an alphanumeric string that can include underscores or hyphens. It cannot contain spaces, special characters, slashes, or backslashes.
|
||||
self.id = "manifold_pipeline"
|
||||
|
||||
# Optionally, you can set the name of the manifold pipeline.
|
||||
self.name = "Manifold: "
|
||||
self.pipelines = [
|
||||
{
|
||||
"id": "pipeline-1", # This will turn into `manifold_pipeline.pipeline-1`
|
||||
"name": "Pipeline 1", # This will turn into `Manifold: Pipeline 1`
|
||||
},
|
||||
{
|
||||
"id": "pipeline-2",
|
||||
"name": "Pipeline 2",
|
||||
},
|
||||
]
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
def pipe(
|
||||
self, user_message: str, model_id: str, messages: List[dict], body: dict
|
||||
) -> Union[str, Generator, Iterator]:
|
||||
# This is where you can add your custom pipelines like RAG.
|
||||
print(f"pipe:{__name__}")
|
||||
|
||||
print(messages)
|
||||
print(user_message)
|
||||
print(body)
|
||||
|
||||
return f"{model_id} response to: {user_message}"
|
||||
Reference in New Issue
Block a user