refac: valves

This commit is contained in:
Timothy J. Baek 2024-06-01 11:36:31 -07:00
parent 74e5c067e5
commit 5b8b9d8f6d
13 changed files with 153 additions and 140 deletions

View File

@ -19,15 +19,17 @@ import requests
class Pipeline: class Pipeline:
class Valves(BaseModel):
ANTHROPIC_API_KEY: str = ""
def __init__(self): def __init__(self):
self.type = "manifold" self.type = "manifold"
self.id = "anthropic" self.id = "anthropic"
self.name = "anthropic/" self.name = "anthropic/"
class Valves(BaseModel): self.valves = self.Valves(
ANTHROPIC_API_KEY: str **{"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY")}
)
self.valves = Valves(**{"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY")})
self.client = Anthropic(api_key=self.valves.ANTHROPIC_API_KEY) self.client = Anthropic(api_key=self.valves.ANTHROPIC_API_KEY)
def get_anthropic_models(self): def get_anthropic_models(self):

View File

@ -18,16 +18,16 @@ import requests
class Pipeline: class Pipeline:
class Valves(BaseModel):
COHERE_API_BASE_URL: str = "https://api.cohere.com/v1"
COHERE_API_KEY: str = ""
def __init__(self): def __init__(self):
self.type = "manifold" self.type = "manifold"
self.id = "cohere" self.id = "cohere"
self.name = "cohere/" self.name = "cohere/"
class Valves(BaseModel): self.valves = self.Valves(**{"COHERE_API_KEY": os.getenv("COHERE_API_KEY")})
COHERE_API_BASE_URL: str = "https://api.cohere.com/v1"
COHERE_API_KEY: str
self.valves = Valves(**{"COHERE_API_KEY": os.getenv("COHERE_API_KEY")})
self.pipelines = self.get_cohere_models() self.pipelines = self.get_cohere_models()

View File

@ -6,17 +6,6 @@ import time
class Pipeline: class Pipeline:
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"
# 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 = "conversation_turn_limit_filter_pipeline"
self.name = "Conversation Turn Limit Filter"
class Valves(BaseModel): class Valves(BaseModel):
# List target pipeline ids (models) that this filter will be connected to. # 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 ["*"] # If you want to connect this filter to all pipelines, you can set pipelines to ["*"]
@ -31,7 +20,18 @@ class Pipeline:
target_user_roles: List[str] = ["user"] target_user_roles: List[str] = ["user"]
max_turns: Optional[int] = None max_turns: Optional[int] = None
self.valves = Valves( 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"
# 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 = "conversation_turn_limit_filter_pipeline"
self.name = "Conversation Turn Limit Filter"
self.valves = self.Valves(
**{ **{
"pipelines": os.getenv("CONVERSATION_TURN_PIPELINES", "*").split(","), "pipelines": os.getenv("CONVERSATION_TURN_PIPELINES", "*").split(","),
"max_turns": 10, "max_turns": 10,

View File

@ -16,6 +16,17 @@ import os
class Pipeline: 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 ["*"]
# e.g. ["llama3:latest", "gpt-3.5-turbo"]
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
def __init__(self): def __init__(self):
# Pipeline filters are only compatible with Open WebUI # 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. # 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.
@ -28,19 +39,8 @@ class Pipeline:
self.id = "detoxify_filter_pipeline" self.id = "detoxify_filter_pipeline"
self.name = "Detoxify Filter" self.name = "Detoxify Filter"
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 ["*"]
# e.g. ["llama3:latest", "gpt-3.5-turbo"]
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
# Initialize # Initialize
self.valves = Valves( self.valves = self.Valves(
**{ **{
"pipelines": ["*"], # Connect to all pipelines "pipelines": ["*"], # Connect to all pipelines
} }

View File

@ -1,8 +1,12 @@
from typing import List, Union, Generator, Iterator from typing import List, Union, Generator, Iterator
from schemas import OpenAIChatMessage from schemas import OpenAIChatMessage
from pydantic import BaseModel
class Pipeline: class Pipeline:
class Valves(BaseModel):
pass
def __init__(self): def __init__(self):
# Optionally, you can set the id and name of the pipeline. # Optionally, you can set the id and name of the pipeline.
# Assign a unique identifier to the pipeline. # Assign a unique identifier to the pipeline.

View File

@ -14,18 +14,6 @@ from schemas import OpenAIChatMessage
class Pipeline: class Pipeline:
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"
class Valves(BaseModel): class Valves(BaseModel):
# List target pipeline ids (models) that this filter will be connected to. # 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 ["*"] # If you want to connect this filter to all pipelines, you can set pipelines to ["*"]
@ -39,7 +27,19 @@ class Pipeline:
# Add your custom parameters here # Add your custom parameters here
pass pass
self.valves = Valves(**{"pipelines": ["llama3:latest"]}) 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 pass

View File

@ -18,17 +18,6 @@ from langfuse import Langfuse
class Pipeline: class Pipeline:
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 = "langfuse_filter_pipeline"
self.name = "Langfuse Filter"
class Valves(BaseModel): class Valves(BaseModel):
# List target pipeline ids (models) that this filter will be connected to. # List target pipeline ids (models) that this filter will be connected to.
@ -46,8 +35,20 @@ class Pipeline:
public_key: str public_key: str
host: str host: str
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 = "langfuse_filter_pipeline"
self.name = "Langfuse Filter"
# Initialize # Initialize
self.valves = Valves( self.valves = self.Valves(
**{ **{
"pipelines": ["*"], # Connect to all pipelines "pipelines": ["*"], # Connect to all pipelines
"secret_key": os.getenv("LANGFUSE_SECRET_KEY"), "secret_key": os.getenv("LANGFUSE_SECRET_KEY"),
@ -94,7 +95,7 @@ class Pipeline:
input=body, input=body,
user_id=user["id"], user_id=user["id"],
metadata={"name": user["name"]}, metadata={"name": user["name"]},
session_id=body["chat_id"] session_id=body["chat_id"],
) )
print(trace.get_trace_url()) print(trace.get_trace_url())

View File

@ -8,17 +8,6 @@ from utils.main import get_last_user_message, get_last_assistant_message
class Pipeline: class Pipeline:
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 = "libretranslate_filter_pipeline"
self.name = "LibreTranslate Filter"
class Valves(BaseModel): class Valves(BaseModel):
# List target pipeline ids (models) that this filter will be connected to. # List target pipeline ids (models) that this filter will be connected to.
@ -44,8 +33,20 @@ class Pipeline:
source_assistant: Optional[str] = "en" source_assistant: Optional[str] = "en"
target_assistant: Optional[str] = "es" target_assistant: Optional[str] = "es"
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 = "libretranslate_filter_pipeline"
self.name = "LibreTranslate Filter"
# Initialize # Initialize
self.valves = Valves( self.valves = self.Valves(
**{ **{
"pipelines": ["*"], # Connect to all pipelines "pipelines": ["*"], # Connect to all pipelines
"libretranslate_url": os.getenv( "libretranslate_url": os.getenv(

View File

@ -14,6 +14,10 @@ import requests
class Pipeline: class Pipeline:
class Valves(BaseModel):
LITELLM_BASE_URL: str
def __init__(self): def __init__(self):
# You can also set the pipelines that are available in this pipeline. # 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. # Set manifold to True if you want to use this pipeline as a manifold.
@ -29,11 +33,8 @@ class Pipeline:
# Optionally, you can set the name of the manifold pipeline. # Optionally, you can set the name of the manifold pipeline.
self.name = "LiteLLM: " self.name = "LiteLLM: "
class Valves(BaseModel):
LITELLM_BASE_URL: str
# Initialize rate limits # Initialize rate limits
self.valves = Valves(**{"LITELLM_BASE_URL": "http://localhost:4001"}) self.valves = self.Valves(**{"LITELLM_BASE_URL": "http://localhost:4001"})
self.pipelines = [] self.pipelines = []
pass pass

View File

@ -21,6 +21,12 @@ import yaml
class Pipeline: class Pipeline:
class Valves(BaseModel):
LITELLM_CONFIG_DIR: str = "./litellm/config.yaml"
LITELLM_PROXY_PORT: int = 4001
LITELLM_PROXY_HOST: str = "127.0.0.1"
litellm_config: dict = {}
def __init__(self): def __init__(self):
# You can also set the pipelines that are available in this pipeline. # 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. # Set manifold to True if you want to use this pipeline as a manifold.
@ -36,14 +42,8 @@ class Pipeline:
# Optionally, you can set the name of the manifold pipeline. # Optionally, you can set the name of the manifold pipeline.
self.name = "LiteLLM: " self.name = "LiteLLM: "
class Valves(BaseModel):
LITELLM_CONFIG_DIR: str = "./litellm/config.yaml"
LITELLM_PROXY_PORT: int = 4001
LITELLM_PROXY_HOST: str = "127.0.0.1"
litellm_config: dict = {}
# Initialize Valves # Initialize Valves
self.valves = Valves(**{"LITELLM_CONFIG_DIR": f"./litellm/config.yaml"}) self.valves = self.Valves(**{"LITELLM_CONFIG_DIR": f"./litellm/config.yaml"})
self.background_process = None self.background_process = None
pass pass

View File

@ -5,6 +5,10 @@ import requests
class Pipeline: class Pipeline:
class Valves(BaseModel):
OLLAMA_BASE_URL: str
def __init__(self): def __init__(self):
# You can also set the pipelines that are available in this pipeline. # 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. # Set manifold to True if you want to use this pipeline as a manifold.
@ -20,10 +24,7 @@ class Pipeline:
# Optionally, you can set the name of the manifold pipeline. # Optionally, you can set the name of the manifold pipeline.
self.name = "Ollama: " self.name = "Ollama: "
class Valves(BaseModel): self.valves = self.Valves(**{"OLLAMA_BASE_URL": "http://localhost:11435"})
OLLAMA_BASE_URL: str
self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11435"})
self.pipelines = [] self.pipelines = []
pass pass

View File

@ -4,18 +4,8 @@ from pydantic import BaseModel
from schemas import OpenAIChatMessage from schemas import OpenAIChatMessage
import time import time
class Pipeline: class Pipeline:
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"
# 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 = "rate_limit_filter_pipeline"
self.name = "Rate Limit Filter"
class Valves(BaseModel): class Valves(BaseModel):
# List target pipeline ids (models) that this filter will be connected to. # 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 ["*"] # If you want to connect this filter to all pipelines, you can set pipelines to ["*"]
@ -32,20 +22,33 @@ class Pipeline:
sliding_window_limit: Optional[int] = None sliding_window_limit: Optional[int] = None
sliding_window_minutes: Optional[int] = None sliding_window_minutes: Optional[int] = None
# Initialize rate limits def __init__(self):
pipelines = os.getenv("RATE_LIMIT_PIPELINES", "*").split(",") # Pipeline filters are only compatible with Open WebUI
requests_per_minute = int(os.getenv("RATE_LIMIT_REQUESTS_PER_MINUTE", 10)) # 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.
requests_per_hour = int(os.getenv("RATE_LIMIT_REQUESTS_PER_HOUR", 1000)) self.type = "filter"
sliding_window_limit = int(os.getenv("RATE_LIMIT_SLIDING_WINDOW_LIMIT", 100))
sliding_window_minutes = int(os.getenv("RATE_LIMIT_SLIDING_WINDOW_MINUTES", 15))
self.valves = Valves( # 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 = "rate_limit_filter_pipeline"
self.name = "Rate Limit Filter"
# Initialize rate limits
self.valves = self.Valves(
**{ **{
"pipelines": pipelines, "pipelines": os.getenv("RATE_LIMIT_PIPELINES", "*").split(","),
"requests_per_minute": requests_per_minute, "requests_per_minute": int(
"requests_per_hour": requests_per_hour, os.getenv("RATE_LIMIT_REQUESTS_PER_MINUTE", 10)
"sliding_window_limit": sliding_window_limit, ),
"sliding_window_minutes": sliding_window_minutes, "requests_per_hour": int(
os.getenv("RATE_LIMIT_REQUESTS_PER_HOUR", 1000)
),
"sliding_window_limit": int(
os.getenv("RATE_LIMIT_SLIDING_WINDOW_LIMIT", 100)
),
"sliding_window_minutes": int(
os.getenv("RATE_LIMIT_SLIDING_WINDOW_MINUTES", 15)
),
} }
) )

View File

@ -6,6 +6,9 @@ import os
class Pipeline: class Pipeline:
class Valves(BaseModel):
pass
def __init__(self): def __init__(self):
# Assign a unique identifier to the pipeline. # Assign a unique identifier to the pipeline.
# The identifier must be unique across all pipelines. # The identifier must be unique across all pipelines.
@ -13,11 +16,8 @@ class Pipeline:
self.id = "wiki_pipeline" self.id = "wiki_pipeline"
self.name = "Wikipedia Pipeline" self.name = "Wikipedia Pipeline"
class Valves(BaseModel):
pass
# Initialize rate limits # Initialize rate limits
self.valves = Valves(**{"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY", "")}) self.valves = self.Valves(**{"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY", "")})
async def on_startup(self): async def on_startup(self):
# This function is called when the server is started. # This function is called when the server is started.