From e7e0ab120f4b59591da4444808a67828b484e3f7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 28 May 2024 16:09:47 -0700 Subject: [PATCH] enh: examples --- .../examples/litellm_manifold_pipeline.py | 5 +++- .../examples/ollama_manifold_pipeline.py | 26 ++++++++++++++----- pipelines/ollama_manifold_pipeline.py | 26 ++++++++++++++----- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/pipelines/examples/litellm_manifold_pipeline.py b/pipelines/examples/litellm_manifold_pipeline.py index 9e9c2ed..8d6d668 100644 --- a/pipelines/examples/litellm_manifold_pipeline.py +++ b/pipelines/examples/litellm_manifold_pipeline.py @@ -54,7 +54,10 @@ class Pipeline: except Exception as e: print(f"Error: {e}") return [ - {"id": "litellm", "name": "Please configure LiteLLM URL"}, + { + "id": self.id, + "name": "Could not fetch models from LiteLLM, please update the URL in the valves.", + }, ] else: return [] diff --git a/pipelines/examples/ollama_manifold_pipeline.py b/pipelines/examples/ollama_manifold_pipeline.py index a90b82f..88d8e15 100644 --- a/pipelines/examples/ollama_manifold_pipeline.py +++ b/pipelines/examples/ollama_manifold_pipeline.py @@ -23,7 +23,7 @@ class Pipeline: class Valves(BaseModel): OLLAMA_BASE_URL: str - self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11434"}) + self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11435"}) self.pipelines = [] pass @@ -39,12 +39,24 @@ class Pipeline: 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"] - ] + if self.valves.OLLAMA_BASE_URL: + try: + 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"] + ] + except Exception as e: + print(f"Error: {e}") + return [ + { + "id": self.id, + "name": "Could not fetch models from Ollama, please update the URL in the valves.", + }, + ] + else: + return [] def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict diff --git a/pipelines/ollama_manifold_pipeline.py b/pipelines/ollama_manifold_pipeline.py index a90b82f..88d8e15 100644 --- a/pipelines/ollama_manifold_pipeline.py +++ b/pipelines/ollama_manifold_pipeline.py @@ -23,7 +23,7 @@ class Pipeline: class Valves(BaseModel): OLLAMA_BASE_URL: str - self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11434"}) + self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11435"}) self.pipelines = [] pass @@ -39,12 +39,24 @@ class Pipeline: 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"] - ] + if self.valves.OLLAMA_BASE_URL: + try: + 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"] + ] + except Exception as e: + print(f"Error: {e}") + return [ + { + "id": self.id, + "name": "Could not fetch models from Ollama, please update the URL in the valves.", + }, + ] + else: + return [] def pipe( self, user_message: str, model_id: str, messages: List[dict], body: dict