proxyml 0.1.7__tar.gz → 0.1.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {proxyml-0.1.7 → proxyml-0.1.8}/PKG-INFO +1 -1
- {proxyml-0.1.7 → proxyml-0.1.8}/pyproject.toml +1 -1
- {proxyml-0.1.7 → proxyml-0.1.8}/src/proxyml/client.py +20 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/src/proxyml.egg-info/PKG-INFO +1 -1
- {proxyml-0.1.7 → proxyml-0.1.8}/tests/test_client.py +35 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/LICENSE +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/README.md +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/setup.cfg +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/src/proxyml/__init__.py +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/src/proxyml/schema.py +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/src/proxyml.egg-info/SOURCES.txt +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/src/proxyml.egg-info/dependency_links.txt +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/src/proxyml.egg-info/requires.txt +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/src/proxyml.egg-info/top_level.txt +0 -0
- {proxyml-0.1.7 → proxyml-0.1.8}/tests/test_schema.py +0 -0
|
@@ -270,6 +270,26 @@ def train_surrogate(
|
|
|
270
270
|
return None
|
|
271
271
|
|
|
272
272
|
|
|
273
|
+
def export_surrogate(version: str) -> Any:
|
|
274
|
+
"""
|
|
275
|
+
Exports a surrogate model to JSON e.g., classes, intercept, per_class_intercepts, features, scalers, etc.; everything required
|
|
276
|
+
to reconstruct the surrogate.
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
version (str): name of the surrogate to export
|
|
280
|
+
Returns:
|
|
281
|
+
JSON object representing the surrogate, or None if an error occurred.
|
|
282
|
+
"""
|
|
283
|
+
r = get(endpoint=f'/surrogate/models/{version}/export', params=dict())
|
|
284
|
+
if r.status_code == 200:
|
|
285
|
+
return r.json()
|
|
286
|
+
logger.error(
|
|
287
|
+
"Surrogate export failed (version=%s, status=%s): %s",
|
|
288
|
+
version, r.status_code, r.text,
|
|
289
|
+
)
|
|
290
|
+
return None
|
|
291
|
+
|
|
292
|
+
|
|
273
293
|
def predict(sample: list, version: str | None = None) -> Any:
|
|
274
294
|
"""
|
|
275
295
|
Calls a surrogate model to make a single prediction.
|
|
@@ -10,6 +10,7 @@ from proxyml.client import (
|
|
|
10
10
|
delete_model,
|
|
11
11
|
delete_schema,
|
|
12
12
|
diff_models,
|
|
13
|
+
export_surrogate,
|
|
13
14
|
fetch_schema,
|
|
14
15
|
find_counterfactuals,
|
|
15
16
|
get_model_summary,
|
|
@@ -552,3 +553,37 @@ def test_rotate_key_success(mock_post):
|
|
|
552
553
|
def test_rotate_key_failure_returns_none(mock_post):
|
|
553
554
|
mock_post.return_value = _mock_response(403, {"detail": "Key rotation is not available for test accounts"})
|
|
554
555
|
assert rotate_key() is None
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
# ---------------------------------------------------------------------------
|
|
559
|
+
# export_surrogate
|
|
560
|
+
# ---------------------------------------------------------------------------
|
|
561
|
+
|
|
562
|
+
_EXPORT_RESPONSE = {
|
|
563
|
+
"version": "abc-123",
|
|
564
|
+
"classes": [0, 1],
|
|
565
|
+
"intercept": [0.5],
|
|
566
|
+
"per_class_intercepts": None,
|
|
567
|
+
"features": [{"name": "age", "type": "continuous"}],
|
|
568
|
+
"scalers": {"age": {"mean": 35.0, "scale": 10.0}},
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
@patch("proxyml.client.get")
|
|
573
|
+
def test_export_surrogate_success(mock_get):
|
|
574
|
+
mock_get.return_value = _mock_response(200, _EXPORT_RESPONSE)
|
|
575
|
+
result = export_surrogate(version="abc-123")
|
|
576
|
+
assert result == _EXPORT_RESPONSE
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
@patch("proxyml.client.get")
|
|
580
|
+
def test_export_surrogate_calls_correct_endpoint(mock_get):
|
|
581
|
+
mock_get.return_value = _mock_response(200, _EXPORT_RESPONSE)
|
|
582
|
+
export_surrogate(version="abc-123")
|
|
583
|
+
mock_get.assert_called_once_with(endpoint="/surrogate/models/abc-123/export", params={})
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
@patch("proxyml.client.get")
|
|
587
|
+
def test_export_surrogate_failure_returns_none(mock_get):
|
|
588
|
+
mock_get.return_value = _mock_response(404, {"detail": "model not found"})
|
|
589
|
+
assert export_surrogate(version="no-such-version") is None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|