Skip to content

Commit

Permalink
Merge pull request #247 from chroma-core/currentVersion
Browse files Browse the repository at this point in the history
get current version
  • Loading branch information
jeffchuber authored Mar 29, 2023
2 parents 5cef7f9 + 20e39e2 commit 19982c4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chromadb/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 4 additions & 0 deletions chromadb/api/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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__
4 changes: 4 additions & 0 deletions chromadb/server/fastapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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()

Expand Down
13 changes: 13 additions & 0 deletions chromadb/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,3 +1306,16 @@ 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 matches the pattern x.y.z
import re

assert re.match(r"\d+\.\d+\.\d+", version)

0 comments on commit 19982c4

Please sign in to comment.