-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[BUG] Make sure Client parameters are strings #1577
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should the int conversions have a try/catch in case of failure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we're fine erroring if someone passes in a port that's not an int (same applies to other types). All we would do is throw another error. |
||
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) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what will happen if the user currently is passing a string? just a type error, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users can pass whatever they want -- these are just type hints which users can choose to statically check or not. If a user is currently passing a string we'll turn it into an int with the
port = int(port)
line below. This will not break anyone.