mirror of
https://github.com/open-webui/pipelines
synced 2025-05-12 16:40:45 +00:00
refac
This commit is contained in:
parent
ee1a4baed9
commit
9e58c71509
@ -28,6 +28,17 @@ class Pipeline:
|
|||||||
self.pipelines = []
|
self.pipelines = []
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def on_startup(self):
|
||||||
|
# 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 or before valves are updated.
|
||||||
|
print(f"on_shutdown:{__name__}")
|
||||||
|
pass
|
||||||
|
|
||||||
def get_litellm_models(self):
|
def get_litellm_models(self):
|
||||||
if self.valves.LITELLM_BASE_URL:
|
if self.valves.LITELLM_BASE_URL:
|
||||||
try:
|
try:
|
||||||
@ -43,22 +54,11 @@ class Pipeline:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
return [
|
return [
|
||||||
{"id": "litellm", "name": "LiteLLM: Please configure LiteLLM URL"},
|
{"id": "litellm", "name": "Please configure LiteLLM URL"},
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
async def on_startup(self):
|
|
||||||
# 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 or before valves are updated.
|
|
||||||
print(f"on_shutdown:{__name__}")
|
|
||||||
pass
|
|
||||||
|
|
||||||
def pipe(
|
def pipe(
|
||||||
self, user_message: str, model_id: str, messages: List[dict], body: dict
|
self, user_message: str, model_id: str, messages: List[dict], body: dict
|
||||||
) -> Union[str, Generator, Iterator]:
|
) -> Union[str, Generator, Iterator]:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
@ -19,21 +20,17 @@ 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: "
|
||||||
|
|
||||||
self.OLLAMA_BASE_URL = "http://localhost:11434"
|
class Valves(BaseModel):
|
||||||
self.pipelines = self.get_ollama_models()
|
OLLAMA_BASE_URL: str
|
||||||
|
|
||||||
|
self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11434"})
|
||||||
|
self.pipelines = []
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_ollama_models(self):
|
|
||||||
r = requests.get(f"{self.OLLAMA_BASE_URL}/api/tags")
|
|
||||||
models = r.json()
|
|
||||||
|
|
||||||
return [
|
|
||||||
{"id": model["model"], "name": model["name"]} for model in models["models"]
|
|
||||||
]
|
|
||||||
|
|
||||||
async def on_startup(self):
|
async def on_startup(self):
|
||||||
# This function is called when the server is started or after valves are updated.
|
# This function is called when the server is started or after valves are updated.
|
||||||
print(f"on_startup:{__name__}")
|
print(f"on_startup:{__name__}")
|
||||||
|
self.pipelines = self.get_ollama_models()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def on_shutdown(self):
|
async def on_shutdown(self):
|
||||||
@ -41,6 +38,14 @@ class Pipeline:
|
|||||||
print(f"on_shutdown:{__name__}")
|
print(f"on_shutdown:{__name__}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_ollama_models(self):
|
||||||
|
r = requests.get(f"{self.valves.OLLAMA_BASE_URL}/api/tags")
|
||||||
|
models = r.json()
|
||||||
|
|
||||||
|
return [
|
||||||
|
{"id": model["model"], "name": model["name"]} for model in models["models"]
|
||||||
|
]
|
||||||
|
|
||||||
def pipe(
|
def pipe(
|
||||||
self, user_message: str, model_id: str, messages: List[dict], body: dict
|
self, user_message: str, model_id: str, messages: List[dict], body: dict
|
||||||
) -> Union[str, Generator, Iterator]:
|
) -> Union[str, Generator, Iterator]:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
@ -10,29 +11,26 @@ class Pipeline:
|
|||||||
# Manifold pipelines can have multiple pipelines.
|
# Manifold pipelines can have multiple pipelines.
|
||||||
self.type = "manifold"
|
self.type = "manifold"
|
||||||
|
|
||||||
|
# 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.
|
||||||
# The identifier must be unique across all pipelines.
|
# 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.
|
# The identifier must be an alphanumeric string that can include underscores or hyphens. It cannot contain spaces, special characters, slashes, or backslashes.
|
||||||
self.id = "ollama_manifold"
|
self.id = "ollama_manifold"
|
||||||
|
|
||||||
# Optionally, you can set the name of the manifold pipeline.
|
# Optionally, you can set the name of the manifold pipeline.
|
||||||
self.name = "Manifold: "
|
self.name = "Ollama: "
|
||||||
|
|
||||||
self.OLLAMA_BASE_URL = "http://localhost:11434"
|
class Valves(BaseModel):
|
||||||
self.pipelines = self.get_ollama_models()
|
OLLAMA_BASE_URL: str
|
||||||
|
|
||||||
|
self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11434"})
|
||||||
|
self.pipelines = []
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_ollama_models(self):
|
|
||||||
r = requests.get(f"{self.OLLAMA_BASE_URL}/api/tags")
|
|
||||||
models = r.json()
|
|
||||||
|
|
||||||
return [
|
|
||||||
{"id": model["model"], "name": model["name"]} for model in models["models"]
|
|
||||||
]
|
|
||||||
|
|
||||||
async def on_startup(self):
|
async def on_startup(self):
|
||||||
# This function is called when the server is started or after valves are updated.
|
# This function is called when the server is started or after valves are updated.
|
||||||
print(f"on_startup:{__name__}")
|
print(f"on_startup:{__name__}")
|
||||||
|
self.pipelines = self.get_ollama_models()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def on_shutdown(self):
|
async def on_shutdown(self):
|
||||||
@ -40,6 +38,14 @@ class Pipeline:
|
|||||||
print(f"on_shutdown:{__name__}")
|
print(f"on_shutdown:{__name__}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_ollama_models(self):
|
||||||
|
r = requests.get(f"{self.valves.OLLAMA_BASE_URL}/api/tags")
|
||||||
|
models = r.json()
|
||||||
|
|
||||||
|
return [
|
||||||
|
{"id": model["model"], "name": model["name"]} for model in models["models"]
|
||||||
|
]
|
||||||
|
|
||||||
def pipe(
|
def pipe(
|
||||||
self, user_message: str, model_id: str, messages: List[dict], body: dict
|
self, user_message: str, model_id: str, messages: List[dict], body: dict
|
||||||
) -> Union[str, Generator, Iterator]:
|
) -> Union[str, Generator, Iterator]:
|
||||||
|
Loading…
Reference in New Issue
Block a user