Skip to content

Commit

Permalink
refac: valves
Browse files Browse the repository at this point in the history
  • Loading branch information
tjbck committed Jun 1, 2024
1 parent 74e5c06 commit 5b8b9d8
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 140 deletions.
10 changes: 6 additions & 4 deletions examples/anthropic_manifold_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@


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):
Expand Down
10 changes: 5 additions & 5 deletions examples/cohere_manifold_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@


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()

Expand Down
30 changes: 15 additions & 15 deletions examples/conversation_turn_limit_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@


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.
Expand All @@ -17,21 +31,7 @@ def __init__(self):
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,
Expand Down
24 changes: 12 additions & 12 deletions examples/detoxify_filter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@


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.
Expand All @@ -28,19 +39,8 @@ def __init__(self):
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
}
Expand Down
4 changes: 4 additions & 0 deletions examples/example_pipeline.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
28 changes: 14 additions & 14 deletions examples/filter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@


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.
Expand All @@ -26,20 +39,7 @@ def __init__(self):
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

Expand Down
37 changes: 19 additions & 18 deletions examples/langfuse_filter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@


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.
Expand All @@ -30,24 +47,8 @@ def __init__(self):
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"),
Expand Down Expand Up @@ -94,7 +95,7 @@ async def inlet(self, body: dict, user: Optional[dict] = None) -> dict:
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())
Expand Down
51 changes: 26 additions & 25 deletions examples/libretranslate_filter_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@


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.
Expand All @@ -20,32 +45,8 @@ def __init__(self):
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(
Expand Down
9 changes: 5 additions & 4 deletions examples/litellm_manifold_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@


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.
Expand All @@ -29,11 +33,8 @@ def __init__(self):
# 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

Expand Down
14 changes: 7 additions & 7 deletions examples/litellm_subprocess_manifold_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@


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.
Expand All @@ -36,14 +42,8 @@ def __init__(self):
# 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

Expand Down
9 changes: 5 additions & 4 deletions examples/ollama_manifold_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@


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.
Expand All @@ -20,10 +24,7 @@ def __init__(self):
# 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

Expand Down
Loading

0 comments on commit 5b8b9d8

Please sign in to comment.