Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get current version #247

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)