diff --git a/examples/anthropic_manifold_pipeline.py b/examples/anthropic_manifold_pipeline.py index 9236db4..1cfcb14 100644 --- a/examples/anthropic_manifold_pipeline.py +++ b/examples/anthropic_manifold_pipeline.py @@ -19,15 +19,17 @@ import requests class Pipeline: + class Valves(BaseModel): + ANTHROPIC_API_KEY: str = "" + def __init__(self): self.type = "manifold" self.id = "anthropic" self.name = "anthropic/" - class Valves(BaseModel): - ANTHROPIC_API_KEY: str - - self.valves = Valves(**{"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY")}) + self.valves = self.Valves( + **{"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY")} + ) self.client = Anthropic(api_key=self.valves.ANTHROPIC_API_KEY) def get_anthropic_models(self): diff --git a/examples/cohere_manifold_pipeline.py b/examples/cohere_manifold_pipeline.py index 896f0f2..20bc5ec 100644 --- a/examples/cohere_manifold_pipeline.py +++ b/examples/cohere_manifold_pipeline.py @@ -18,16 +18,16 @@ import requests class Pipeline: + class Valves(BaseModel): + COHERE_API_BASE_URL: str = "https://api.cohere.com/v1" + COHERE_API_KEY: str = "" + def __init__(self): self.type = "manifold" self.id = "cohere" self.name = "cohere/" - class Valves(BaseModel): - 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.valves = self.Valves(**{"COHERE_API_KEY": os.getenv("COHERE_API_KEY")}) self.pipelines = self.get_cohere_models() diff --git a/examples/conversation_turn_limit_filter.py b/examples/conversation_turn_limit_filter.py index ca6c264..54e9483 100644 --- a/examples/conversation_turn_limit_filter.py +++ b/examples/conversation_turn_limit_filter.py @@ -6,6 +6,20 @@ import time 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 + + # Valves for conversation turn limiting + target_user_roles: List[str] = ["user"] + max_turns: Optional[int] = None + 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. @@ -17,21 +31,7 @@ class Pipeline: self.id = "conversation_turn_limit_filter_pipeline" self.name = "Conversation Turn Limit 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 ["*"] - 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 - - # Valves for conversation turn limiting - target_user_roles: List[str] = ["user"] - max_turns: Optional[int] = None - - self.valves = Valves( + self.valves = self.Valves( **{ "pipelines": os.getenv("CONVERSATION_TURN_PIPELINES", "*").split(","), "max_turns": 10, diff --git a/examples/detoxify_filter_pipeline.py b/examples/detoxify_filter_pipeline.py index 28f7138..7411b39 100644 --- a/examples/detoxify_filter_pipeline.py +++ b/examples/detoxify_filter_pipeline.py @@ -16,6 +16,17 @@ import os 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): # 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. @@ -28,19 +39,8 @@ class Pipeline: self.id = "detoxify_filter_pipeline" 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 - self.valves = Valves( + self.valves = self.Valves( **{ "pipelines": ["*"], # Connect to all pipelines } diff --git a/examples/example_pipeline.py b/examples/example_pipeline.py index 417974e..c321f4b 100644 --- a/examples/example_pipeline.py +++ b/examples/example_pipeline.py @@ -1,8 +1,12 @@ 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. diff --git a/examples/filter_pipeline.py b/examples/filter_pipeline.py index db69271..0e303c4 100644 --- a/examples/filter_pipeline.py +++ b/examples/filter_pipeline.py @@ -14,6 +14,19 @@ 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. @@ -26,20 +39,7 @@ class Pipeline: self.id = "filter_pipeline" self.name = "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 ["*"] - 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 - - self.valves = Valves(**{"pipelines": ["llama3:latest"]}) + self.valves = self.Valves(**{"pipelines": ["llama3:latest"]}) pass diff --git a/examples/langfuse_filter_pipeline.py b/examples/langfuse_filter_pipeline.py index f985419..6dd4894 100644 --- a/examples/langfuse_filter_pipeline.py +++ b/examples/langfuse_filter_pipeline.py @@ -18,6 +18,23 @@ from langfuse import Langfuse 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 + + # Valves + secret_key: str + public_key: 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. @@ -30,24 +47,8 @@ class Pipeline: self.id = "langfuse_filter_pipeline" self.name = "Langfuse 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 - - # Valves - secret_key: str - public_key: str - host: str - # Initialize - self.valves = Valves( + self.valves = self.Valves( **{ "pipelines": ["*"], # Connect to all pipelines "secret_key": os.getenv("LANGFUSE_SECRET_KEY"), @@ -94,7 +95,7 @@ class Pipeline: input=body, user_id=user["id"], metadata={"name": user["name"]}, - session_id=body["chat_id"] + session_id=body["chat_id"], ) print(trace.get_trace_url()) diff --git a/examples/libretranslate_filter_pipeline.py b/examples/libretranslate_filter_pipeline.py index 5a8745b..0c14ac8 100644 --- a/examples/libretranslate_filter_pipeline.py +++ b/examples/libretranslate_filter_pipeline.py @@ -8,6 +8,31 @@ from utils.main import get_last_user_message, get_last_assistant_message 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 + + # Valves + libretranslate_url: str + + # Source and target languages + # User message will be translated from source_user to target_user + source_user: Optional[str] = "auto" + target_user: Optional[str] = "en" + + # Assistant languages + # Assistant message will be translated from source_assistant to target_assistant + source_assistant: Optional[str] = "en" + 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. @@ -20,32 +45,8 @@ class Pipeline: self.id = "libretranslate_filter_pipeline" self.name = "LibreTranslate 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 - - # Valves - libretranslate_url: str - - # Source and target languages - # User message will be translated from source_user to target_user - source_user: Optional[str] = "auto" - target_user: Optional[str] = "en" - - # Assistant languages - # Assistant message will be translated from source_assistant to target_assistant - source_assistant: Optional[str] = "en" - target_assistant: Optional[str] = "es" - # Initialize - self.valves = Valves( + self.valves = self.Valves( **{ "pipelines": ["*"], # Connect to all pipelines "libretranslate_url": os.getenv( diff --git a/examples/litellm_manifold_pipeline.py b/examples/litellm_manifold_pipeline.py index a739730..f12e93a 100644 --- a/examples/litellm_manifold_pipeline.py +++ b/examples/litellm_manifold_pipeline.py @@ -14,6 +14,10 @@ import requests class Pipeline: + + class Valves(BaseModel): + LITELLM_BASE_URL: str + 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. @@ -29,11 +33,8 @@ class Pipeline: # Optionally, you can set the name of the manifold pipeline. self.name = "LiteLLM: " - class Valves(BaseModel): - LITELLM_BASE_URL: str - # Initialize rate limits - self.valves = Valves(**{"LITELLM_BASE_URL": "http://localhost:4001"}) + self.valves = self.Valves(**{"LITELLM_BASE_URL": "http://localhost:4001"}) self.pipelines = [] pass diff --git a/examples/litellm_subprocess_manifold_pipeline.py b/examples/litellm_subprocess_manifold_pipeline.py index e10ee87..f2bdeff 100644 --- a/examples/litellm_subprocess_manifold_pipeline.py +++ b/examples/litellm_subprocess_manifold_pipeline.py @@ -21,6 +21,12 @@ import yaml 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): # 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. @@ -36,14 +42,8 @@ class Pipeline: # Optionally, you can set the name of the manifold pipeline. 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 - 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 pass diff --git a/examples/ollama_manifold_pipeline.py b/examples/ollama_manifold_pipeline.py index 6fc18f8..a564113 100644 --- a/examples/ollama_manifold_pipeline.py +++ b/examples/ollama_manifold_pipeline.py @@ -5,6 +5,10 @@ import requests class Pipeline: + + class Valves(BaseModel): + OLLAMA_BASE_URL: str + 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. @@ -20,10 +24,7 @@ class Pipeline: # Optionally, you can set the name of the manifold pipeline. self.name = "Ollama: " - class Valves(BaseModel): - OLLAMA_BASE_URL: str - - self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11435"}) + self.valves = self.Valves(**{"OLLAMA_BASE_URL": "http://localhost:11435"}) self.pipelines = [] pass diff --git a/examples/rate_limit_filter_pipeline.py b/examples/rate_limit_filter_pipeline.py index 49ae733..f03e18b 100644 --- a/examples/rate_limit_filter_pipeline.py +++ b/examples/rate_limit_filter_pipeline.py @@ -4,7 +4,24 @@ from pydantic import BaseModel from schemas import OpenAIChatMessage import time + 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 + + # Valves for rate limiting + requests_per_minute: Optional[int] = None + requests_per_hour: Optional[int] = None + sliding_window_limit: Optional[int] = None + sliding_window_minutes: Optional[int] = None + 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. @@ -16,36 +33,22 @@ class Pipeline: self.id = "rate_limit_filter_pipeline" self.name = "Rate Limit 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 ["*"] - 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 - - # Valves for rate limiting - requests_per_minute: Optional[int] = None - requests_per_hour: Optional[int] = None - sliding_window_limit: Optional[int] = None - sliding_window_minutes: Optional[int] = None - # Initialize rate limits - pipelines = os.getenv("RATE_LIMIT_PIPELINES", "*").split(",") - requests_per_minute = int(os.getenv("RATE_LIMIT_REQUESTS_PER_MINUTE", 10)) - 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)) - - self.valves = Valves( + self.valves = self.Valves( **{ - "pipelines": pipelines, - "requests_per_minute": requests_per_minute, - "requests_per_hour": requests_per_hour, - "sliding_window_limit": sliding_window_limit, - "sliding_window_minutes": sliding_window_minutes, + "pipelines": os.getenv("RATE_LIMIT_PIPELINES", "*").split(","), + "requests_per_minute": int( + os.getenv("RATE_LIMIT_REQUESTS_PER_MINUTE", 10) + ), + "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) + ), } ) diff --git a/examples/wikipedia_pipeline.py b/examples/wikipedia_pipeline.py index 1a296ae..d430123 100644 --- a/examples/wikipedia_pipeline.py +++ b/examples/wikipedia_pipeline.py @@ -6,6 +6,9 @@ import os class Pipeline: + class Valves(BaseModel): + pass + def __init__(self): # Assign a unique identifier to the pipeline. # The identifier must be unique across all pipelines. @@ -13,11 +16,8 @@ class Pipeline: self.id = "wiki_pipeline" self.name = "Wikipedia Pipeline" - class Valves(BaseModel): - pass - # 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): # This function is called when the server is started.