forked from marqo-ai/marqo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
36 lines (32 loc) · 1.2 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from typing import Optional, Union
from marqo.tensor_search import enums
class Config:
def __init__(
self,
url: str,
timeout: Optional[int] = None,
indexing_device: Optional[Union[enums.Device, str]] = None,
search_device: Optional[Union[enums.Device, str]] = None
) -> None:
"""
Parameters
----------
url:
The url to the S2Search API (ex: http://localhost:9200)
"""
self.cluster_is_remote = False
self.url = self.set_url(url)
self.timeout = timeout
default_device = enums.Device.cpu
self.indexing_device = indexing_device if indexing_device is not None else default_device
self.search_device = search_device if search_device is not None else default_device
def set_url(self, url):
"""Set the URL, and infers whether that url is remote"""
lowered_url = url.lower()
local_host_markers = ["localhost", "0.0.0.0", "127.0.0.1"]
if any([marker in lowered_url for marker in local_host_markers]):
self.cluster_is_remote = False
else:
self.cluster_is_remote = True
self.url = url
return self.url