diff --git a/chromadb/__init__.py b/chromadb/__init__.py index 18a9c9f671f..209a3e791c9 100644 --- a/chromadb/__init__.py +++ b/chromadb/__init__.py @@ -112,6 +112,10 @@ def EphemeralClient( settings = Settings() settings.is_persistent = False + # Make sure paramaters are the correct types -- users can pass anything. + tenant = str(tenant) + database = str(database) + return ClientCreator(settings=settings, tenant=tenant, database=database) @@ -135,12 +139,16 @@ def PersistentClient( settings.persist_directory = path settings.is_persistent = True + # Make sure paramaters are the correct types -- users can pass anything. + tenant = str(tenant) + database = str(database) + return ClientCreator(tenant=tenant, database=database, settings=settings) def HttpClient( host: str = "localhost", - port: str = "8000", + port: int = 8000, ssl: bool = False, headers: Optional[Dict[str, str]] = None, settings: Optional[Settings] = None, @@ -165,6 +173,13 @@ def HttpClient( if settings is None: settings = Settings() + # Make sure paramaters are the correct types -- users can pass anything. + host = str(host) + port = int(port) + ssl = bool(ssl) + tenant = str(tenant) + database = str(database) + settings.chroma_api_impl = "chromadb.api.fastapi.FastAPI" if settings.chroma_server_host and settings.chroma_server_host != host: raise ValueError( @@ -189,7 +204,7 @@ def CloudClient( settings: Optional[Settings] = None, *, # Following arguments are keyword-only, intended for testing only. cloud_host: str = "api.trychroma.com", - cloud_port: str = "8000", + cloud_port: int = 8000, enable_ssl: bool = True, ) -> ClientAPI: """ @@ -217,6 +232,14 @@ def CloudClient( if settings is None: settings = Settings() + # Make sure paramaters are the correct types -- users can pass anything. + tenant = str(tenant) + database = str(database) + api_key = str(api_key) + cloud_host = str(cloud_host) + cloud_port = int(cloud_port) + enable_ssl = bool(enable_ssl) + settings.chroma_api_impl = "chromadb.api.fastapi.FastAPI" settings.chroma_server_host = cloud_host settings.chroma_server_http_port = cloud_port @@ -242,9 +265,12 @@ def Client( tenant: The tenant to use for this client. Defaults to the default tenant. database: The database to use for this client. Defaults to the default database. - """ + # Make sure paramaters are the correct types -- users can pass anything. + tenant = str(tenant) + database = str(database) + return ClientCreator(tenant=tenant, database=database, settings=settings) diff --git a/chromadb/api/fastapi.py b/chromadb/api/fastapi.py index d3d1a8a4e7e..27728880b33 100644 --- a/chromadb/api/fastapi.py +++ b/chromadb/api/fastapi.py @@ -109,7 +109,7 @@ def __init__(self, system: System): self._api_url = FastAPI.resolve_url( chroma_server_host=str(system.settings.chroma_server_host), - chroma_server_http_port=int(str(system.settings.chroma_server_http_port)), + chroma_server_http_port=system.settings.chroma_server_http_port, chroma_server_ssl_enabled=system.settings.chroma_server_ssl_enabled, default_api_path=system.settings.chroma_server_api_default_path, ) diff --git a/chromadb/config.py b/chromadb/config.py index 59bea5ee0e4..da58c711259 100644 --- a/chromadb/config.py +++ b/chromadb/config.py @@ -118,10 +118,10 @@ class Settings(BaseSettings): # type: ignore chroma_server_host: Optional[str] = None chroma_server_headers: Optional[Dict[str, str]] = None - chroma_server_http_port: Optional[str] = None + chroma_server_http_port: Optional[int] = None chroma_server_ssl_enabled: Optional[bool] = False chroma_server_api_default_path: Optional[str] = "/api/v1" - chroma_server_grpc_port: Optional[str] = None + chroma_server_grpc_port: Optional[int] = None # eg ["http://localhost:3000"] chroma_server_cors_allow_origins: List[str] = [] @@ -134,8 +134,8 @@ def empty_str_to_none(cls, v: str) -> Optional[str]: chroma_server_nofile: Optional[int] = None pulsar_broker_url: Optional[str] = None - pulsar_admin_port: Optional[str] = "8080" - pulsar_broker_port: Optional[str] = "6650" + pulsar_admin_port: Optional[int] = 8080 + pulsar_broker_port: Optional[int] = 6650 chroma_server_auth_provider: Optional[str] = None diff --git a/chromadb/test/client/test_cloud_client.py b/chromadb/test/client/test_cloud_client.py index aee869ca1c5..48b0252789b 100644 --- a/chromadb/test/client/test_cloud_client.py +++ b/chromadb/test/client/test_cloud_client.py @@ -61,7 +61,7 @@ def mock_cloud_server(valid_token: str) -> Generator[System, None, None]: settings = Settings( chroma_api_impl="chromadb.api.fastapi.FastAPI", chroma_server_host=TEST_CLOUD_HOST, - chroma_server_http_port=str(port), + chroma_server_http_port=port, chroma_client_auth_provider="chromadb.auth.token.TokenAuthClientProvider", chroma_client_auth_credentials=valid_token, chroma_client_auth_token_transport_header=TOKEN_TRANSPORT_HEADER, @@ -82,7 +82,7 @@ def test_valid_key(mock_cloud_server: System, valid_token: str) -> None: database=DEFAULT_DATABASE, api_key=valid_token, cloud_host=TEST_CLOUD_HOST, - cloud_port=mock_cloud_server.settings.chroma_server_http_port, # type: ignore + cloud_port=mock_cloud_server.settings.chroma_server_http_port or 8000, enable_ssl=False, ) @@ -98,7 +98,7 @@ def test_invalid_key(mock_cloud_server: System, valid_token: str) -> None: database=DEFAULT_DATABASE, api_key=invalid_token, cloud_host=TEST_CLOUD_HOST, - cloud_port=mock_cloud_server.settings.chroma_server_http_port, # type: ignore + cloud_port=mock_cloud_server.settings.chroma_server_http_port or 8000, enable_ssl=False, ) client.heartbeat() diff --git a/chromadb/test/conftest.py b/chromadb/test/conftest.py index 087cb2271bd..1ff975b2d23 100644 --- a/chromadb/test/conftest.py +++ b/chromadb/test/conftest.py @@ -205,7 +205,7 @@ def _fastapi_fixture( settings = Settings( chroma_api_impl="chromadb.api.fastapi.FastAPI", chroma_server_host="localhost", - chroma_server_http_port=str(port), + chroma_server_http_port=port, allow_reset=True, chroma_client_auth_provider=chroma_client_auth_provider, chroma_client_auth_credentials=chroma_client_auth_credentials, @@ -234,7 +234,7 @@ def fastapi_persistent() -> Generator[System, None, None]: def basic_http_client() -> Generator[System, None, None]: settings = Settings( chroma_api_impl="chromadb.api.fastapi.FastAPI", - chroma_server_http_port="8000", + chroma_server_http_port=8000, allow_reset=True, ) system = System(settings) diff --git a/chromadb/test/test_chroma.py b/chromadb/test/test_chroma.py index 9d88ea8cc49..89b4ae924eb 100644 --- a/chromadb/test/test_chroma.py +++ b/chromadb/test/test_chroma.py @@ -66,7 +66,7 @@ def test_fastapi(self, mock: Mock) -> None: chroma_api_impl="chromadb.api.fastapi.FastAPI", persist_directory="./foo", chroma_server_host="foo", - chroma_server_http_port="80", + chroma_server_http_port=80, ) ) assert mock.called @@ -78,7 +78,7 @@ def test_settings_pass_to_fastapi(self, mock: Mock) -> None: settings = chromadb.config.Settings( chroma_api_impl="chromadb.api.fastapi.FastAPI", chroma_server_host="foo", - chroma_server_http_port="80", + chroma_server_http_port=80, chroma_server_headers={"foo": "bar"}, ) client = chromadb.Client(settings) @@ -106,7 +106,7 @@ def test_legacy_values() -> None: chroma_api_impl="chromadb.api.local.LocalAPI", persist_directory="./foo", chroma_server_host="foo", - chroma_server_http_port="80", + chroma_server_http_port=80, ) ) client.clear_system_cache() diff --git a/chromadb/test/test_client.py b/chromadb/test/test_client.py index f67293d8586..34dd2df1412 100644 --- a/chromadb/test/test_client.py +++ b/chromadb/test/test_client.py @@ -60,9 +60,9 @@ def test_http_client_with_inconsistent_host_settings() -> None: def test_http_client_with_inconsistent_port_settings() -> None: try: chromadb.HttpClient( - port="8002", + port=8002, settings=Settings( - chroma_server_http_port="8001", + chroma_server_http_port=8001, ), ) except ValueError as e: