File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change 11import io
2+ import json
23from contextlib import nullcontext
3- from typing import Type , TYPE_CHECKING , Optional
4+ from typing import Type , TYPE_CHECKING
5+ from functools import lru_cache
6+ from urllib .request import Request , urlopen
47
58from ....helper import get_request_header
69
710if TYPE_CHECKING :
811 from ....types import T
912
1013
14+ @lru_cache ()
15+ def _get_cloud_api () -> str :
16+ """Get Cloud Api for transmiting data to the cloud.
17+
18+ :raises RuntimeError: Encounter error when fetching the cloud Api Url.
19+ :return: Cloud Api Url
20+ """
21+ try :
22+ req = Request (
23+ 'https://api.jina.ai/hub/hubble.json' ,
24+ headers = {'User-Agent' : 'Mozilla/5.0' },
25+ )
26+ with urlopen (req ) as resp :
27+ u = json .load (resp )['url' ]
28+ except Exception as ex :
29+ raise RuntimeError (
30+ f'Can not fetch Cloud API address from { req .full_url } '
31+ ) from ex
32+
33+ return u
34+
35+
1136class PushPullMixin :
1237 """Transmitting :class:`DocumentArray` via Jina Cloud Service"""
1338
14- _service_url = 'https://apihubble.jina.ai /v2/rpc/da.'
39+ _service_url = _get_cloud_api () + ' /v2/rpc/da.'
1540 _max_bytes = 4 * 1024 * 1024 * 1024
1641
1742 def push (self , token : str , show_progress : bool = False ) -> None :
You can’t perform that action at this time.
0 commit comments