feat: expose Ollama models in Hermes picker
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
import base64
|
||||
import binascii
|
||||
import io
|
||||
import importlib.util
|
||||
import ipaddress
|
||||
import json
|
||||
import mimetypes
|
||||
@@ -311,6 +312,22 @@ def _write_connections(value: dict[str, str]) -> None:
|
||||
pass
|
||||
|
||||
|
||||
def _sync_native_ollama_providers(connections: dict[str, str] | None = None) -> None:
|
||||
"""Keep Hermes' native model picker aligned with this plugin's endpoints."""
|
||||
try:
|
||||
helper_path = Path(__file__).resolve().parent.parent / "ollama_provider.py"
|
||||
spec = importlib.util.spec_from_file_location("_ollama_manager_provider_sync", helper_path)
|
||||
if spec is None or spec.loader is None:
|
||||
return
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
module.sync_hermes_ollama_providers(connections)
|
||||
except Exception:
|
||||
# Provider synchronization must never make the Ollama dashboard route fail.
|
||||
return
|
||||
|
||||
|
||||
|
||||
def _apply_saved_connection() -> None:
|
||||
global LOCAL_OLLAMA
|
||||
saved = _read_connections().get("active_url")
|
||||
@@ -1511,6 +1528,7 @@ def connections_configure(body: ConnectionRequest) -> dict[str, Any]:
|
||||
if role == "local":
|
||||
saved["active_url"] = url
|
||||
_write_connections(saved)
|
||||
_sync_native_ollama_providers(saved)
|
||||
if role == "local":
|
||||
global LOCAL_OLLAMA
|
||||
LOCAL_OLLAMA = url
|
||||
@@ -1533,6 +1551,7 @@ def connections_delete(role: str) -> dict[str, Any]:
|
||||
if role == "local":
|
||||
saved["active_url"] = ""
|
||||
_write_connections(saved)
|
||||
_sync_native_ollama_providers(saved)
|
||||
if role == "local":
|
||||
_apply_saved_connection()
|
||||
return {"ok": True, "role": role, "removed_url": removed, "message": f"Removed saved {role} Ollama endpoint"}
|
||||
@@ -1687,4 +1706,5 @@ def delete_model(body: ModelRequest) -> dict[str, Any]:
|
||||
|
||||
|
||||
def create_ollama_routes(app) -> None:
|
||||
_sync_native_ollama_providers()
|
||||
app.include_router(router, prefix="/api/plugins/ollama-manager")
|
||||
|
||||
Reference in New Issue
Block a user