connect.governance.governance.Governance
- class connect.governance.governance.Governance(config_path=None, credo_api_client=None)
Bases:
objectClass to store governance data.
Governance is used to interact with the CredoAI Governance(Report) App. It has two main jobs. 1. Get evidence_requirements of use_case and policy pack. 2. Upload evidences gathered with evidence_requirements
- Parameters
credo_api_client (CredoApiClient, optional) – Credo API client. Uses default Credo API client if it is None Default Credo API client uses ~/.credo_config to read API server configuration. Please prepare ~/.credo_config file by downloading it from CredoAI Governance App.(My Settings > Tokens)
Examples
If you want to use your own configuration:
from connect.governance.credo_api_client import CredoApiClient, CredoApiConfig from connect.governance.goverance import Governance
- config = CredoApiConfig(
api_key=”API_KEY”, tenant=”credo”, api_server=”https://api.credo.ai”
) # or using credo_config file config = CredoApiConfig() config.load_config(“CREDO_CONFIG_FILE_PATH”)
client = CredoApiClient(config=config) governace = Governance(credo_api_client=client)
Governance object to connect Lens with Credo AI Platform
- Parameters
config_path (str, optional) – path to .credoconfig file. If None, points to ~/.credoconfig, by default None
credo_api_client (CredoApiClient, optional) – If provided, overrides the API configuration defined by the config path, by default None
- __init__(config_path=None, credo_api_client=None)
Governance object to connect Lens with Credo AI Platform
- Parameters
config_path (str, optional) – path to .credoconfig file. If None, points to ~/.credoconfig, by default None
credo_api_client (CredoApiClient, optional) – If provided, overrides the API configuration defined by the config path, by default None
Methods
__init__([config_path, credo_api_client])Governance object to connect Lens with Credo AI Platform
add_evidence(evidences)Add evidences
Update Platform model's tags to CredoAI Governance if changed
clear_evidence()export([filename])Upload evidences to CredoAI Governance(Report) App
get_evidence([verbose])Returns evidence that has been send to the governance object
get_evidence_requirements([tags, verbose])Returns evidence requirements.
Get the tags and version for the associated model
Return the unique tags used for all evidence requirements
register([assessment_plan_url, ...])- type assessment_plan_url
Optional[str]
set_artifacts(model, model_tags[, ...])Sets up internal knowledge of model and datasets to send to Credo AI Platform
set_evidence(evidences)Update evidences
tag_model(model)Interactive utility to tag a model tags from assessment plan
Attributes
modelregisteredrequirements_satisified- add_evidence(evidences)
Add evidences
- apply_model_changes()
Update Platform model’s tags to CredoAI Governance if changed
This function will update the platform model associated with the assessment plan with the tags associated with the local model associated with Governance. If no model has been registered on the platform, nothing will be updated.
- export(filename=None)
Upload evidences to CredoAI Governance(Report) App
- Returns
True – When uploading is successful with all evidence
False – When it is not registered yet, or evidence is insufficient
- get_evidence(verbose=False)
Returns evidence that has been send to the governance object
- Parameters
verbose (bool, False) – if True, print out human-readable evidence requirements
- get_evidence_requirements(tags=None, verbose=False)
Returns evidence requirements. Each evidence requirement can have optional tags (a dictionary). Returns requirements whose tags are a subset of the model’s tags.
For example, imagine a model has two tags: {‘risk’: ‘high’, ‘model_type’: ‘binary’} and three requirements with the following tags:
req1 = {} req2 = {‘risk’: ‘high’} req3 = {‘risk’: ‘high’, ‘model_type’: ‘binary’}
In this case all requirements will apply. If the model risk was was ‘low’ only req_1 would apply. If the ‘model_type’ was not ‘binary’ then only req1 and req2 would apply.
- Parameters
tags (dict, optional) – Tags to subset evidence requirements. If a model has been set, will default to the model’s tags. Evidence requirements will be returned that have no tags or have the same tag as provided.
verbose (bool, False) – if True, print out human-readable evidence requirements
- Returns
- Return type
List[EvidenceRequirement]
- get_model_info()
Get the tags and version for the associated model
- get_requirement_tags()
Return the unique tags used for all evidence requirements
- register(assessment_plan_url=None, use_case_name=None, policy_pack_key=None, assessment_plan=None, assessment_plan_file=None)
- Parameters
assessment_plan_url (str) – assessment plan URL
use_case_name (str) – use case name
policy_pack_key (str) – policy pack key
assessment_plan (str) – assessment plan JSON string
assessment_plan_file (str) – assessment plan file name that holds assessment plan JSON string
Examples
Get assessment plan and register it. There are three ways to do it:
With assessment_plan_url.
gov.register(assessment_plan_url=”https://api.credo.ai/api/v2/tenant/use_cases/{id}/assessment_plans/{pp_id}”)
With use case name and policy pack key.
gov.register(use_case_name=”Fraud Detection”, policy_pack_key=”FAIR”)
With assessment_plan json string or filename. It is used in the air-gap condition.
gov.register(assessment_plan=”JSON_STRING”) gov.register(assessment_plan_file=”FILENAME”)
After successful registration, gov.registered returns True and able to get evidence_requirements:
gov.registered # returns True gov.get_evidence_requirements()
- set_artifacts(model, model_tags, model_version=None, training_dataset=None, assessment_dataset=None)
Sets up internal knowledge of model and datasets to send to Credo AI Platform
- Parameters
model (str) – model name
model_tags (dict) – List of key:value pairs specifying model tags. These are typically used to pair the model with tagged governance requirements, which are defined in a Governance instance’s assessment_plan
training_dataset (str, optional) – training dataset name, by default None
assessment_dataset (str, optional) – assessment dataset name, by default None
- set_evidence(evidences)
Update evidences
- tag_model(model)
Interactive utility to tag a model tags from assessment plan