Setup

Note

  • Either API_KEY from IBM Cloud or Cloud Pak for Data details can be used when initiating client

  • If using IBM Cloud API_KEY or Cloud pak for Data details and it is not for external models, specify a container type and ID of either project or space

Important

If watsonx.governance is hosted in certain regions, for example, Frankfurt (eu-de), Sydney (au-syd), or N. Virginia (us-east-1), apart from the default Dallas (us-south), a new region parameter is introduced during initialization.

Available region values: dallas, sydney, frankfurt, toronto, london, tokyo, aws_mumbai, aws_nv (N. Virginia), aws_govcloud.

class FactsClientAdapter(service_instance_id: str = None, experiment_name: str = None, container_type: str | None = None, container_id: str | None = None, authenticator: BearerTokenAuthenticator | CloudPakForDataAuthenticator | IAMAuthenticator | MCSPV2Authenticator | None = None, api_key: str | None = None, bearer_token: str | None = None, set_as_current_experiment: bool | None = False, enable_autolog: bool | None = True, external_model: bool | None = False, centralized_model: bool | None = False, cloud_pak_for_data_configs: CloudPakforDataConfig = None, disable_tracing: bool | None = False, enable_push_framework: bool | None = False, region: str | None = None, account_id: str | None = None)

Bases: FactsAuthClient

AI GOVERNANCE FACTS CLIENT

Variables:

version (str) – Returns version of the python library.

Parameters:
  • experiment_name (str) – Name of the Experiment.

  • service_instance_id (str) – (Optional) The GUID of the watsonx.governance service instance to use. If not provided, the default instance for the account is used automatically.

  • container_type (str) – (Optional) Name of the container where model would be saved. Currently supported options are SPACE or PROJECT. It is (Required) when using Watson Machine Learning.

  • container_id (str) – (Optional) container id specific to container type.It is (Required) when using Watson Machine Learning.

  • set_as_current_experiment (bool) – (Optional) if True new experiment will not be created if experiment already exists with same experiment name.By default set to False.

  • enable_autolog (bool) – (Optional) if False, manual log option will be available. By default set to True.

  • external_model (bool) – (Optional) if True, external models tracing would be enabled. By default set to False.

  • cloud_pak_for_data_configs (CloudPakforDataConfig) – (Optional) Cloud pak for data cluster details.

  • disable_tracing (bool) – (Optional) if True, tracing and logging utilities will be disabled. Default to False.

  • enable_push_framework (bool) – (Optional) if True, enable_push_framework support will be enabled. Default to False.

  • region (str) – (Optional) Specifies the region where the watsonx.governance is hosted. The default region is Dallas(us-south). For available options, refer to Region.

  • account_id (str) – (Optional) Specifies the account_id of AWS region. It is required when using AWS regions.

The way to use is:

watsonx.governance Factsheet(Cloud)

>>> from ibm_aigov_facts_client import AIGovFactsClient
>>> client = AIGovFactsClient(api_key=<API_KEY>, experiment_name="test",container_type="space or project",container_id=<space_id or project_id>)

If cloud region is one of: Sydney, Frankfurt, Toronto, London, Tokyo:

To set up the client for these regions, use the following code:

>>> client = AIGovFactsClient(api_key=<API_KEY>, experiment_name="test",container_type="space or project",container_id=<space_id or project_id>,region="sydney" or "frankfurt" or "toronto" or "london" or "tokyo")

If using existing experiment as current:

>>> client = AIGovFactsClient(api_key=<API_KEY>, experiment_name="test",container_type="space",container_id=<space_id>,set_as_current_experiment=True)

If using external models with manual log:

>>> client= AIGovFactsClient(api_key=API_KEY,experiment_name="external",enable_autolog=False,external_model=True)

If using external models with Autolog:

>>> client= AIGovFactsClient(api_key=API_KEY,experiment_name="external",external_model=True)

If using push framework:

client = AIGovFactsClient(api_key=<API_KEY>, experiment_name="test",container_type="space or project",container_id=<space_id or project_id>,enable_push_framework=True)

If using Trusted Profile (bearer token):

>>> client = AIGovFactsClient(bearer_token="<BEARER_TOKEN>", experiment_name="test", container_type="space or project", container_id="<space_id or project_id>")

If specifying a particular service instance (multi-instance):

>>> client = AIGovFactsClient(api_key=<API_KEY>, experiment_name="test", container_type="space", container_id=<space_id>, service_instance_id="<service_instance_guid>")

watsonx.governance Factsheet(On Prem)

>>> from ibm_aigov_facts_client import AIGovFactsClient,CloudPakforDataConfig
>>> cpd_creds=CloudPakforDataConfig(service_url="<hosturl>",username="<username>",password="<password>")
>>> client = AIGovFactsClient(experiment_name="<name of experiment>",container_type="<space or project>",container_id="<space_id or project_id>",cloud_pak_for_data_configs=cpd_creds)

If API_KEY is available

>>> from ibm_aigov_facts_client import AIGovFactsClient,CloudPakforDataConfig
>>> cpd_creds=CloudPakforDataConfig(service_url="<hosturl>",username="<username>",api_key="<api_key>")
>>> client = AIGovFactsClient(experiment_name="<name of experiment>",container_type="<space or project>",container_id="<space_id or project_id>",cloud_pak_for_data_configs=cpd_creds)

If Watsonx Governance platform has IAM enabled:

>>> from ibm_aigov_facts_client import AIGovFactsClient,CloudPakforDataConfig
>>> cpd_creds=CloudPakforDataConfig(service_url="<hosturl>",username="<username>",password="<password>",bedrock_url="<cluster bedrock url>")
>>> client = AIGovFactsClient(experiment_name="<name of experiment>",container_type="<space or project>",container_id="<space_id or project_id>",cloud_pak_for_data_configs=cpd_creds )

if disable tracing as a whole and use other features like custom facts and facts definitions

>>> client = AIGovFactsClient(container_type=<project or space>,container_id=<space or project id>,cloud_pak_for_data_configs=creds,disable_tracing=True)
>>> client = AIGovFactsClient(external_model=True,cloud_pak_for_data_configs=creds,disable_tracing=True)

For Standalone use in localhost without factsheet functionality:

>>> from ibm_aigov_facts_client import AIGovFactsClient
>>> client = AIGovFactsClient(experiment_name="test")

watsonx.governance Factsheet (AWS)

For AWS Mumbai region, api_key and account_id are mandatory to set up the Facts client

To set up the client for the region, use the following code:

>>> from ibm_aigov_facts_client import AIGovFactsClient
>>> client = AIGovFactsClient(api_key=<api_key>,experiment_name=experiment_name,account_id=<account_id>,region="aws_mumbai",container_type="space or project",container_id=<space_id or project_id>)
>>> client = AIGovFactsClient(api_key=<api_key>,experiment_name=experiment_name,account_id=<account_id>,region="aws_mumbai",external_model=True)

For AWS N. Virginia region, api_key and account_id are mandatory to set up the Facts client

>>> client = AIGovFactsClient(api_key=<api_key>,experiment_name=experiment_name,account_id=<account_id>,region="aws_nv",container_type="space or project",container_id=<space_id or project_id>)
>>> client = AIGovFactsClient(api_key=<api_key>,experiment_name=experiment_name,account_id=<account_id>,region="aws_nv",external_model=True)
get_service_instance_id()

Get the service instance ID.

Returns:

str: The service instance ID.

set_service_instance_id(value)

Set the service instance ID.

Args:

value (str): The service instance ID to set.

get_access_token(apikey: str = None, account_id: str = None)

Method to get IAM access token / aws access token

The way to use me is:

>>> client.get_access_token()

for aws >>> client.get_access_token(apikey,aws_account_id)

Trusted Profiles

The Factsheet client supports trusted profiles in watsonx.governance (cloud). Trusted profile authentication is implemented with bearer tokens, similar to how authentication is implemented using API keys.

For example:

from ibm_aigov_facts_client import AIGovFactsClient

client = AIGovFactsClient(bearer_token="<BEARER_TOKEN>", experiment_name="test", container_type="space or project", container_id="<space_id or project_id>")

Multi-Instance Support

When multiple watsonx.governance service instances are available, you can specify a particular instance by passing the service_instance_id parameter during client initialization. If omitted, the default instance is used automatically.

For example:

from ibm_aigov_facts_client import AIGovFactsClient

# Use a specific service instance
client = AIGovFactsClient(api_key="<API_KEY>", experiment_name="test",
                          container_type="space", container_id="<space_id>",
                          service_instance_id="<service_instance_guid>")

# Retrieve or change the service instance ID at runtime
instance_id = client.get_service_instance_id()
client.set_service_instance_id("<new_service_instance_guid>")

Retrieve Installed Version

get_cpd_version(self) str

Get Cloud Pak for Data version. If it’s cloud then it’ll return as SaaS

Return type:

CP4D version or SaaS if it’s cloud.

The way to use me is:

>>> client.get_cpd_version()