enh: examples

This commit is contained in:
Timothy J. Baek 2024-05-28 16:09:47 -07:00
parent 9e58c71509
commit e7e0ab120f
3 changed files with 42 additions and 15 deletions

View File

@ -54,7 +54,10 @@ class Pipeline:
except Exception as e: except Exception as e:
print(f"Error: {e}") print(f"Error: {e}")
return [ 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: else:
return [] return []

View File

@ -23,7 +23,7 @@ class Pipeline:
class Valves(BaseModel): class Valves(BaseModel):
OLLAMA_BASE_URL: str OLLAMA_BASE_URL: str
self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11434"}) self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11435"})
self.pipelines = [] self.pipelines = []
pass pass
@ -39,12 +39,24 @@ class Pipeline:
pass pass
def get_ollama_models(self): def get_ollama_models(self):
if self.valves.OLLAMA_BASE_URL:
try:
r = requests.get(f"{self.valves.OLLAMA_BASE_URL}/api/tags") r = requests.get(f"{self.valves.OLLAMA_BASE_URL}/api/tags")
models = r.json() models = r.json()
return [ return [
{"id": model["model"], "name": model["name"]} for model in models["models"] {"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( 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

View File

@ -23,7 +23,7 @@ class Pipeline:
class Valves(BaseModel): class Valves(BaseModel):
OLLAMA_BASE_URL: str OLLAMA_BASE_URL: str
self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11434"}) self.valves = Valves(**{"OLLAMA_BASE_URL": "http://localhost:11435"})
self.pipelines = [] self.pipelines = []
pass pass
@ -39,12 +39,24 @@ class Pipeline:
pass pass
def get_ollama_models(self): def get_ollama_models(self):
if self.valves.OLLAMA_BASE_URL:
try:
r = requests.get(f"{self.valves.OLLAMA_BASE_URL}/api/tags") r = requests.get(f"{self.valves.OLLAMA_BASE_URL}/api/tags")
models = r.json() models = r.json()
return [ return [
{"id": model["model"], "name": model["name"]} for model in models["models"] {"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( 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