mirror of
https://github.com/open-webui/pipelines
synced 2025-05-11 08:01:08 +00:00
feat: valves on_startup & on_shutdown
This commit is contained in:
parent
a8348a3197
commit
88f3d59fcb
2
main.py
2
main.py
@ -255,6 +255,7 @@ async def update_valves(pipeline_id: str, form_data: dict):
|
||||
|
||||
pipeline_module = PIPELINE_MODULES[pipeline_id]
|
||||
|
||||
await pipeline_module.on_shutdown()
|
||||
try:
|
||||
ValvesModel = pipeline_module.valves.__class__
|
||||
valves = ValvesModel(**form_data)
|
||||
@ -265,6 +266,7 @@ async def update_valves(pipeline_id: str, form_data: dict):
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"{str(e)}",
|
||||
)
|
||||
await pipeline_module.on_startup()
|
||||
|
||||
return pipeline_module.valves
|
||||
|
||||
|
@ -18,13 +18,13 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -14,12 +14,12 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -34,12 +34,12 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -75,7 +75,7 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
pass
|
||||
|
||||
def pipe(
|
||||
|
@ -43,12 +43,12 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
self.langfuse.flush()
|
||||
pass
|
||||
|
@ -24,32 +24,38 @@ class Pipeline:
|
||||
LITELLM_BASE_URL: str
|
||||
|
||||
# Initialize rate limits
|
||||
self.valves = Valves(**{"LITELLM_BASE_URL": "http://localhost:4000"})
|
||||
|
||||
self.pipelines = self.get_litellm_models()
|
||||
self.valves = Valves(**{"LITELLM_BASE_URL": "http://localhost:4001"})
|
||||
self.pipelines = []
|
||||
pass
|
||||
|
||||
def get_litellm_models(self):
|
||||
if self.valves.LITELLM_BASE_URL:
|
||||
r = requests.get(f"{self.valves.LITELLM_BASE_URL}/v1/models")
|
||||
models = r.json()
|
||||
return [
|
||||
{
|
||||
"id": model["id"],
|
||||
"name": model["name"] if "name" in model else model["id"],
|
||||
}
|
||||
for model in models["data"]
|
||||
]
|
||||
try:
|
||||
r = requests.get(f"{self.valves.LITELLM_BASE_URL}/v1/models")
|
||||
models = r.json()
|
||||
return [
|
||||
{
|
||||
"id": model["id"],
|
||||
"name": model["name"] if "name" in model else model["id"],
|
||||
}
|
||||
for model in models["data"]
|
||||
]
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
return [
|
||||
{"id": "litellm", "name": "LiteLLM: Please configure LiteLLM URL"},
|
||||
]
|
||||
else:
|
||||
return []
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
self.pipelines = self.get_litellm_models()
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -15,7 +15,7 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
from llama_cpp import Llama
|
||||
|
||||
@ -29,7 +29,7 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -66,7 +66,7 @@ class Pipeline:
|
||||
print(self.index)
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
pass
|
||||
|
||||
def pipe(
|
||||
|
@ -18,7 +18,7 @@ class Pipeline:
|
||||
)
|
||||
Settings.llm = Ollama(model="llama3")
|
||||
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
global documents, index
|
||||
|
||||
self.documents = SimpleDirectoryReader("./data").load_data()
|
||||
@ -26,7 +26,7 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
pass
|
||||
|
||||
def pipe(
|
||||
|
@ -17,11 +17,11 @@ class Pipeline:
|
||||
|
||||
self.documents = SimpleDirectoryReader("./data").load_data()
|
||||
self.index = VectorStoreIndex.from_documents(self.documents)
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
pass
|
||||
|
||||
def pipe(
|
||||
|
@ -30,12 +30,12 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -32,12 +32,12 @@ class Pipeline:
|
||||
]
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -14,12 +14,12 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -14,12 +14,12 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -14,12 +14,12 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -11,12 +11,12 @@ class Pipeline:
|
||||
pass
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -47,12 +47,12 @@ class Pipeline:
|
||||
self.user_requests = {}
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -31,12 +31,12 @@ class Pipeline:
|
||||
]
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
@ -47,12 +47,12 @@ class Pipeline:
|
||||
self.user_requests = {}
|
||||
|
||||
async def on_startup(self):
|
||||
# This function is called when the server is started.
|
||||
# This function is called when the server is started or after valves are updated.
|
||||
print(f"on_startup:{__name__}")
|
||||
pass
|
||||
|
||||
async def on_shutdown(self):
|
||||
# This function is called when the server is stopped.
|
||||
# This function is called when the server is stopped or before valves are updated.
|
||||
print(f"on_shutdown:{__name__}")
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user