Self-hosted AI workspace.
Python
Ignore non-object embedding endpoint config (#1260)
red person7bb710338c6a
diff --git a/routes/embedding_routes.py b/routes/embedding_routes.pyindex 7ae80057d..dbe075ac1 100644--- a/routes/embedding_routes.py+++ b/routes/embedding_routes.py@@ -86,7 +86,8 @@ def _load_custom_endpoint() -> dict:"""Load the saved custom embedding endpoint, if any."""try:if os.path.exists(_ENDPOINT_FILE):- return json.loads(Path(_ENDPOINT_FILE).read_text(encoding="utf-8"))+ data = json.loads(Path(_ENDPOINT_FILE).read_text(encoding="utf-8"))+ return data if isinstance(data, dict) else {}except Exception:passreturn {}diff --git a/tests/test_embedding_endpoint_config.py b/tests/test_embedding_endpoint_config.pynew file mode 100644index 000000000..e800e23a5--- /dev/null+++ b/tests/test_embedding_endpoint_config.py@@ -0,0 +1,25 @@+import json++import routes.embedding_routes as embedding_routes+++def test_load_custom_endpoint_ignores_non_object_json(tmp_path, monkeypatch):+ endpoint_file = tmp_path / "embedding_endpoint.json"+ endpoint_file.write_text(json.dumps(["not", "an", "endpoint", "object"]), encoding="utf-8")+ monkeypatch.setattr(embedding_routes, "_ENDPOINT_FILE", str(endpoint_file))++ assert embedding_routes._load_custom_endpoint() == {}+++def test_load_custom_endpoint_keeps_object_json(tmp_path, monkeypatch):+ endpoint_file = tmp_path / "embedding_endpoint.json"+ endpoint_file.write_text(+ json.dumps({"url": "http://127.0.0.1:11434", "model": "nomic-embed-text"}),+ encoding="utf-8",+ )+ monkeypatch.setattr(embedding_routes, "_ENDPOINT_FILE", str(endpoint_file))++ assert embedding_routes._load_custom_endpoint() == {+ "url": "http://127.0.0.1:11434",+ "model": "nomic-embed-text",+ }