File size: 1,129 Bytes
aa73ff9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Persist a validation-selected threshold without granting execution permission."""
import json


def load_allow_threshold(model, override=None):
    if override is not None:return override
    path=model/'operating-policy.json'
    if not path.exists():return .90
    policy=json.loads(path.read_text());threshold=float(policy['allow_threshold'])
    if not 0<=threshold<=1.0001:raise ValueError('Invalid saved operating threshold')
    if (threshold>1)!=bool(policy.get('disable_automatic_allow',False)):
        raise ValueError('Inconsistent automatic ALLOW disabling policy')
    return threshold


def save_experimental_policy(model,validation):
    policy=dict(allow_threshold=validation['operating_threshold'],disable_automatic_allow=validation['operating_threshold']>1,
                selected_on='validation_only',validation_sha256=validation['dataset_sha256'],validation_passed=validation['readiness']['passed'],
                criteria_passed=False,status='experimental_until_test_and_audit_pass',production_execution_enabled=False)
    (model/'operating-policy.json').write_text(json.dumps(policy,indent=2)+'\n')