Skip to content

Commit 157ea54

Browse files
committed
first pass
1 parent 588406e commit 157ea54

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/groundlight/experimental_api.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
)
4141
from urllib3.response import HTTPResponse
4242

43+
from groundlight.edge.config import EdgeEndpointConfig
4344
from groundlight.images import parse_supported_image_types
4445
from groundlight.internalapi import _generate_request_id
4546
from groundlight.optional_imports import Image, np
@@ -817,3 +818,19 @@ def make_generic_api_request( # noqa: PLR0913 # pylint: disable=too-many-argume
817818
auth_settings=["ApiToken"],
818819
_preload_content=False, # This returns the urllib3 response rather than trying any type of processing
819820
)
821+
822+
def get_edge_config(self) -> EdgeEndpointConfig:
823+
"""Retrieve the active edge endpoint configuration.
824+
825+
Only works when the client is pointed at an edge endpoint
826+
(via GROUNDLIGHT_ENDPOINT or the endpoint constructor arg).
827+
"""
828+
from urllib.parse import urlparse, urlunparse
829+
830+
parsed = urlparse(self.configuration.host)
831+
base_url = urlunparse((parsed.scheme, parsed.netloc, "", "", "", ""))
832+
url = f"{base_url}/edge-config"
833+
headers = self.get_raw_headers()
834+
response = requests.get(url, headers=headers, verify=self.configuration.verify_ssl)
835+
response.raise_for_status()
836+
return EdgeEndpointConfig.from_payload(response.json())

test/unit/test_edge_config.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,30 @@ def test_inference_config_validation_errors():
307307
always_return_edge_prediction=True,
308308
min_time_between_escalations=-1.0,
309309
)
310+
311+
312+
def test_get_edge_config_parses_response():
313+
"""ExperimentalApi.get_edge_config() parses the HTTP response into an EdgeEndpointConfig."""
314+
from unittest.mock import Mock, patch
315+
316+
from groundlight import ExperimentalApi
317+
318+
payload = {
319+
"global_config": {"refresh_rate": REFRESH_RATE_SECONDS},
320+
"edge_inference_configs": {"default": {"enabled": True}},
321+
"detectors": [{"detector_id": "det_1", "edge_inference_config": "default"}],
322+
}
323+
324+
mock_response = Mock()
325+
mock_response.json.return_value = payload
326+
mock_response.raise_for_status = Mock()
327+
328+
gl = ExperimentalApi()
329+
with patch("requests.get", return_value=mock_response) as mock_get:
330+
config = gl.get_edge_config()
331+
332+
mock_get.assert_called_once()
333+
assert isinstance(config, EdgeEndpointConfig)
334+
assert config.global_config.refresh_rate == REFRESH_RATE_SECONDS
335+
assert config.edge_inference_configs["default"].name == "default"
336+
assert [d.detector_id for d in config.detectors] == ["det_1"]

0 commit comments

Comments
 (0)