From 18c745e67aa7ae7a27f3baf5172487a18b4a94cb Mon Sep 17 00:00:00 2001 From: Jeffrey Huber Date: Tue, 28 Mar 2023 17:27:18 -0700 Subject: [PATCH 1/2] get current version --- chromadb/api/fastapi.py | 6 ++++++ chromadb/api/local.py | 4 ++++ chromadb/server/fastapi/__init__.py | 4 ++++ chromadb/test/test_api.py | 14 ++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/chromadb/api/fastapi.py b/chromadb/api/fastapi.py index d760700de4c..843cfde89d1 100644 --- a/chromadb/api/fastapi.py +++ b/chromadb/api/fastapi.py @@ -283,3 +283,9 @@ def create_index(self, collection_name: str): except requests.HTTPError as e: raise (Exception(resp.text)) return resp.json() + + def get_version(self): + """Returns the version of the server""" + resp = requests.get(self._api_url + "/version") + resp.raise_for_status() + return resp.json() diff --git a/chromadb/api/local.py b/chromadb/api/local.py index 72782e89b1b..5a46812eb12 100644 --- a/chromadb/api/local.py +++ b/chromadb/api/local.py @@ -2,6 +2,7 @@ import uuid import time from typing import Dict, List, Optional, Sequence, Callable, Type, cast +from chromadb import __version__ from chromadb.api import API from chromadb.db import DB from chromadb.api.types import ( @@ -316,3 +317,6 @@ def _peek(self, collection_name, n=10): def persist(self): self._db.persist() return True + + def get_version(self): + return __version__ diff --git a/chromadb/server/fastapi/__init__.py b/chromadb/server/fastapi/__init__.py index d373a1d7332..4a36c47acf8 100644 --- a/chromadb/server/fastapi/__init__.py +++ b/chromadb/server/fastapi/__init__.py @@ -72,6 +72,7 @@ def __init__(self, settings): self.router.add_api_route("/api/v1", self.root, methods=["GET"]) self.router.add_api_route("/api/v1/reset", self.reset, methods=["POST"]) + self.router.add_api_route("/api/v1/version", self.version, methods=["GET"]) self.router.add_api_route("/api/v1/persist", self.persist, methods=["POST"]) self.router.add_api_route("/api/v1/raw_sql", self.raw_sql, methods=["POST"]) @@ -129,6 +130,9 @@ def root(self): def persist(self): self._api.persist() + def version(self): + return self._api.get_version() + def list_collections(self): return self._api.list_collections() diff --git a/chromadb/test/test_api.py b/chromadb/test/test_api.py index e81c0321966..6dc914d2116 100644 --- a/chromadb/test/test_api.py +++ b/chromadb/test/test_api.py @@ -1306,3 +1306,17 @@ def test_persist_index_loading_params(api_fixture, request): ) for key in nn.keys(): assert len(nn[key]) == 1 + + +# test get_version +@pytest.mark.parametrize("api_fixture", test_apis) +def test_get_version(api_fixture, request): + api = request.getfixturevalue(api_fixture.__name__) + api.reset() + version = api.get_version() + # assert version["version"] == "0.1.0" + + # assert version matches the pattern x.y.z + import re + + assert re.match(r"\d+\.\d+\.\d+", version) From 20e39e2a9a27dd5bce2fb17325e96f857a6d57d2 Mon Sep 17 00:00:00 2001 From: Jeffrey Huber Date: Tue, 28 Mar 2023 22:22:11 -0700 Subject: [PATCH 2/2] remove comment --- chromadb/test/test_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/chromadb/test/test_api.py b/chromadb/test/test_api.py index 6dc914d2116..435bf4e803d 100644 --- a/chromadb/test/test_api.py +++ b/chromadb/test/test_api.py @@ -1314,7 +1314,6 @@ def test_get_version(api_fixture, request): api = request.getfixturevalue(api_fixture.__name__) api.reset() version = api.get_version() - # assert version["version"] == "0.1.0" # assert version matches the pattern x.y.z import re