ibm_aigov_facts_client.factsheet.assets module

class Assets(facts_client: FactsClientAdapter)

Bases: object

create_custom_facts_definitions(csvFilePath, type_name: str = None, section_name: str = None, overwrite=True)

Utility to add custom facts attribute properties of model or model usecase.

Parameters:
  • csvFilePath (str) – File path of csv having the asset properties.

  • type_name (str) – Asset type user needs to add/update. Current options are modelfacts_user,`model_entry_user`. Default is set to modelfacts_user.

  • section_name (str) – Custom name to show for custom attribute section. Applies only to model_entry_user type.

  • overwrite (bool) – (Optional) Merge or replace current properties. Default is True.

A way you might use me is:

>>> client.assets.create_custom_facts_definitions("Asset_type_definition.csv") # uses default type `modelfacts_user` type
>>> client.assets.create_custom_facts_definitions("Asset_type_definition.csv",type_name="model_entry_user", localized_name=<custom name for attributes section>,overwrite=False)
reset_custom_facts_definitions(type_name: str = None)

Utility to remove custom facts attribute properties of model or model usecase.

Parameters:

type_name (str) – Asset type user needs to add/update. Current options are modelfacts_user,`model_entry_user`. Default is set to modelfacts_user.

A way you might use me is,:

client.assets.reset_custom_facts_definitions(type_name="model_entry_user")
get_facts_definitions(type_name: str, container_type: str = None, container_id: str = None) Dict

Get all facts definitions

Parameters:
  • type_name (str) – Asset fact type. Current options are modelfacts_user and model_entry_user.

  • container_type (str) – (Optional) Asset container type. Options are project, space or catalog. Default to container type used when initiating client.

  • container_id (str) – (Optional) Asset container id. Default to container id when initiating client

Return type:

dict

A way you might use me is:

>>> client.assets.get_facts_definitions(type_name=<fact type>) # uses container type and id used initializing facts client
>>> client.assets.get_facts_definitions(type_name=<fact type>,container_type=<container type>,container_id=<container id>)
get_model(model_id: str = None, container_type: str = None, container_id: str = None, wml_stored_model_details: dict = None)

Get model asset.

Parameters:
  • model_id (str) – (Optional) Id of the traditional machine learning model asset.

  • container_type (str) – (Optional) Name of the container where model is saved. Currently supported container_type are space or project. For external models it is not needed and defaulted to catalog.

  • container_id (str) – (Optional) Id of the container where model asset is saved. For external models, it refers to catalog id where model stub is saved. if not provided for external models,if available and user have access, default platform asset catalog is used

  • wml_stored_model_details (dict) – (Optional) Watson machine learning model details. Applied to Watson Machine Learning models only.

Return type:

ModelAssetUtilities

The way to use me is:

>>> client.assets.get_model(model_id=<model_id>) # uses container type and id used to initiate client
>>> client.assets.get_model(model_id=<model id>,container_type=<space or project>,container_id=<space or project id>)
>>> client.assets.get_model(wml_stored_model_details=<wml model details>) # uses model id, container type and id part of model details

for external models,

>>> client.assets.get_model(model_id=<model_id>) # uses available platform asset catalog id as container_id
>>> client.assets.get_model(model_id=<model_id>,container_id=<catalog id>)
get_ai_usecase(ai_usecase_id: str, catalog_id: str = None) AIUsecaseUtilities

Get AI usecase asset.

Parameters:
  • ai_usecase_id (str) – Id of the ai usecase.

  • catalog_id (str) – Id of the catalog where ai usecase is saved.

Return type:

AIUsecaseUtilities

The way to use me is:

>>> client.assets.get_ai_usecase(ai_usecase_id=<ai usecase id>, catalog_id=<catalog id>)
get_model_usecase(model_usecase_id: str, catalog_id: str = None) ModelUsecaseUtilities

Warning

ibm_aigov_facts_client.factsheet.assets.Assets.get_model_usecase is deprecated. This method will be removed in a future release.It is due to new generalized method available to cover models and prompts. Use client.assets.get_ai_usecase() instead.

Get model usecase asset.

Parameters:
  • model_usecase_id (str) – Id of the model usecase.

  • catalog_id (str) – Id of the catalog where model usecase is saved.

Return type:

ModelUsecaseUtilities

The way to use me is:

>>> client.assets.get_model_usecase(model_usecase_id=<model usecase id>, catalog_id=<catalog id>)
create_inventory(name: str, description: str, container_type: str = None, cloud_object_storage_name: str = None, s3_storage: str = None) AIGovInventoryUtilities

Create a new inventory item.

This method creates an inventory item with the specified name and description.

Note:
  • If using IBM Cloud, provide the cloud_object_storage_name to properly associate the inventory with a Cloud Object Storage (COS) instance.

Parameters:
  • name (str): The name of the inventory item to be created.

  • description (str): A brief description of the inventory item.

  • cloud_object_storage_name (str, optional): The name of the cloud object storage instance to associate with the inventory. Required if using IBM Cloud.To retrieve the available COS instances, see the documentation for the get_cloud_object_storage_instances function.

  • s3_storage (str): The bucket storage preference, shared or dedicated is mandatory for AWS region

  • container_type (str): The container type is mandatory for AWS region

Returns:

InventoryUtilities`: An instance of AIGovInventoryUtilities representing the created inventory item.

Example:

  1. Creating an inventory in the Watsonx.Governance platform:

    >>> inventory = client.assets.create_inventory(name="My Inventory", description="This is a test inventory.")
    
  2. Creating an inventory with a COS name in IBM Cloud:

    >>> inventory = client.assets.create_inventory(name="Data Inventory", description="Inventory for data storage", cloud_object_storage_name="my-cos-instance")
    
  3. Creating an inventory with AWS:
    >>> inventory = client.assets.create_inventory(name="My Inventory", container_type"<container_type>", s3_storage="shared" or "dedicated",description="<description>")
    
list_inventories(name: str = None, exact_match: bool = False) list[AIGovInventoryUtilities]

List All Inventories

This method retrieves and returns a list of all inventories associated with the account. Each inventory item is represented as an instance of AIGovInventoryUtilities.

Args:
  • name (str, optional): The name of the inventory to filter the results. If provided, the method will search for inventories matching this name.

  • exact_match (bool, optional): If set to True, the method will perform an exact match on the inventory name. Default is False, which allows for partial matches.

Returns:

list[AIGovInventoryUtilities]: A list of AIGovInventoryUtilities instances, each representing an inventory item.

Examples:
>>> inventories = client.assets.list_inventories()  # Retrieve all inventories
>>> inventories = client.assets.list_inventories(name="sample")  # Retrieve inventories matching "sample"
>>> inventories = client.assets.list_inventories(name="sample", exact_match=True)  # Retrieve inventories with an exact match for "sample"
get_inventory(inventory_id: str) AIGovInventoryUtilities

Retrieve a specific inventory by its inventory_id.

This method fetches the details of a specific inventory item using its inventory_id. The returned inventory is represented as an instance of AIGovInventoryUtilities.

Parameters:

inventory_id (str): The unique identifier of the inventory item to retrieve.

Returns:

AIGovInventoryUtilities: An instance of AIGovInventoryUtilities representing the requested inventory item.

Example:
>>> inventory = client.assets.get_inventory(inventory_id="993738-383****")
get_default_inventory_details()

Retrieves details for the default inventory along with the username also.

Usage:
>>> client.assets.get_default_inventory_details()
remove_asset(asset_id: str, container_type: str = None, container_id: str = None)

Remove a model or model usecase asset.”

Parameters:
  • asset_id (str) – Id of the asset

  • container_type (str, optional) – container where asset is stored, defaults to container type use when initiating client

  • container_id (str, optional) – container id where asset is stored, defaults to container id used when initiating client. For external models, if not provided, uses available platform asset catalog.

Raises:

ClientError – Report exception details

The way you can use me is :

>>> client.assets.remove_asset(asset_id=<model or model usecase id>)
>>> client.assets.remove_asset(asset_id=<model or model usecase id>,container_type=<space,project or catalog>, container_id=<container id>)
delete_prompt_asset(asset_id: str, container_type: str = None, container_id: str = None)

Deletes a prompt asset after checking the tracking status of the prompt against an AI usecase In case a prompt is tracked to an ai usecase, then user is warned. User may untrack the prompt and re-execute the delete prompt command for deleting the same.

Parameters:
  • asset_id (str) – Id of the asset

  • container_type (str, optional) – container where asset is stored, defaults to container type use when initiating client

  • container_id (str, optional) – container id where asset is stored, defaults to container id used when initiating client. For external models, if not provided, uses available platform asset catalog.

The way you can use me is :

>>> client.assets.delete_prompt_asset(asset_id=<model or model usecase id>)
>>> client.assets.delete_prompt_asset(asset_id=<model or model usecase id>,container_type=<space,project or catalog>, container_id=<container id>)
list_model_usecases(catalog_id: str = None) list

Warning

ibm_aigov_facts_client.factsheet.assets.Assets.list_model_usecases is deprecated. This method will be removed in a future release.Use client.assets.get_model_usecases() instead.

Returns WKC Model usecase assets

Parameters:

catalog_id (str) – Catalog ID where registered model usecase. if not provided, dafault shows all model usecases in all catalogs across all accounts to which the user has access.

Returns:

All WKC Model usecase assets for a catalog

Return type:

list

Example:

>>> client.assets.list_model_usecases(catalog_id=<catalog_id>)
>>> client.assets.list_model_usecases()
create_model_usecase(catalog_id: str = None, name: str = None, description: str = None) ModelUsecaseUtilities

Warning

ibm_aigov_facts_client.factsheet.assets.Assets.create_model_usecase is deprecated. This method will be removed in a future release.It is due to new generalized method available to cover models and prompts. Use client.assets.create_ai_usecase() instead.

Returns WKC Model usecase

Parameters:
  • catalog_id (str) – Catalog ID where this model usecase needs to create.

  • name (str) – Name of model usecase

  • description (str) – (Optional) Model usecase description

Return type:

ModelUsecaseUtilities

Returns:

WKC Model usecase asset

Example:

>>> client.assets.create_model_usecase(catalog_id=<catalog_id>,name=<model usecase name>,description=<model usecase description>)
get_ai_usecases(catalog_id: str = None, limit_to_apikey_account: bool = True) list

Returns AI usecase assets.

Parameters:
  • catalog_id (str) – (Optional) Catalog ID where AI usecases are registered. If not provided, defaults to showing all AI usecases in all catalogs across all accounts to which the user has access.

  • limit_to_apikey_account (bool) – (Optional) Value is set to True by default, limiting the returned results to the current BSS account ID linked to the API key used. Can be modified and set to False when required. This flag works only when no catalog ID is passed and in a cloud environment.

Return type:

list of AIUsecaseUtilities

Returns:

All AI usecase assets for a catalog.

Example:

>>> client.assets.get_ai_usecases(catalog_id=<catalog_id>)
>>> client.assets.get_ai_usecases()
get_ai_usecases_by_name(name: str, inventory_id: str = None, exact_match: bool = None) List[AIUsecaseUtilities]

Retrieve AI use cases by name.

Search for AI use cases based on the provided name. If exact_match is True, only exact matches are returned; otherwise, partial matches are included. An optional inventory_id can limit the search to a specific inventory.

Parameters:
  • name (str): The name or partial name of the AI use case.

  • inventory_id (str, optional): The ID to filter by inventory. Defaults to None.

  • exact_match (bool, optional): If True, returns only exact matches. Defaults to False.

Returns:

List[AIUsecaseUtilities]: A list of matching AI use cases.

Examples:
# Search for AI use cases with names that contain 'sample'
usecases = client.assets.get_ai_usecases_by_name(name='sample')

# Search for AI use cases with an exact name match
usecases = client.assets.get_ai_usecases_by_name(name='sample', exact_match=True)
get_model_usecases(catalog_id: str = None) list

Warning

ibm_aigov_facts_client.factsheet.assets.Assets.get_model_usecases is deprecated. This method will be removed in a future release.It is due to new generalized method available to cover models and prompts. Use client.assets.get_ai_usecases() instead.

Returns WKC Model usecase assets

Parameters:

catalog_id (str) – (Optional) Catalog ID where model usecase are registered. if not provided, dafault shows all model usecases in all catalogs across all accounts to which the user has access.

Return type:

list(ModelUsecaseUtilities)

Returns:

All WKC Model usecase assets for a catalog

Example:

>>> client.assets.get_model_usecases(catalog_id=<catalog_id>)
>>> client.assets.get_model_usecases()
get_PAC_id() str

Get Platform Asset Catalog ( PAC ) ID.

Return type:

PAC ID

The way to use me is:

>>> client.assets.get_PAC_id()
get_attachment_definitions(type_name: str = None) None

Displays all attachment fact definitions for model or model_usecase. Supported for CPD version >=4.6.5 :return: None :rtype: list()

The way to use me is:

>>> client.assets.get_attachment_definitions(type_name=<model or model_usecase>)
create_ai_usecase(catalog_id: str = None, name: str = None, description: str = None, status: str = None, risk: str = None, tags: list = None) AIUsecaseUtilities

Returns AI usecase

Parameters:
  • catalog_id (str) – Catalog ID where this model usecase needs to create.

  • name (str) – Name of model usecase

  • description (str) – (Optional) Model usecase description

  • status (str) – (Optional) AI Usecase status.Available options are in Status

  • risk (str) – (Optional) AI Usecase risk.Available options are in Risk

  • tags (list) – (Optional) AI usecase tags. Provide list of tags, for example [“usecase for prod”,”model for prod”]

Return type:

AIUsecaseUtilities

Returns:

AI usecase asset

Example:

>>> client.assets.create_ai_usecase(catalog_id=<catalog_id>,name=<AI usecase name>,description=<AI usecase description>)
create_detached_prompt(name: str, model_id: str, task_id: str, detached_information: DetachedPromptTemplate, description: str = None, prompt_details: PromptTemplate = None, container_type: str = None, container_id: str = None) AIGovAssetUtilities

Create a Detached/External Prompt Template Asset.

Parameters:
  • name (str) – The name of the detached prompt being created.

  • model_id (str) – The identifier of the model associated with the extrnal prompt

  • task_id (str) – Describes possible Task for the prompt template creation

  • detached_information (DetachedPromptTemplate) – Holds information about an external prompt, including its ID, associated model ID, provider, model name and URL, prompt URL, and additional information

  • description (str) – (Optional) description of the external prompt to be created

  • prompt_details (PromptTemplate) – (Optional) Holds information about task IDs, model version details, prompt variables, instructions, input/output prefixes, and example data

  • container_id (str) – (Optional) used to save the detached prompt

Returns:

AIGovAssetUtilities

Example-1 (Creating a Detached prompt with minimal information),:

detached_info = DetachedPromptTemplate(prompt_id="n/a",
                                       model_id="arn:aws:bedrock:us-east1:123456789012:provisioned-model/anthropic.claude-v2",
                                       model_provider="AWS Bedrock",
                                       model_name="Anthropic Claude 2.0",
                                       model_url="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html",
                                       prompt_url="n/a",
                                       prompt_additional_info={"AWS Region": "us-east1"}
                                       )

external_prompt = facts.client.asests.create_detached_prompt(name="External prompt sample (model AWS Bedrock Anthropic)",
                                                         task_id="summarization",
                                                         model_id="anthropic.claude-v2", 
                                                         description="My First External Prompt",
                                                         detached_information=ivar_detached_info)

Example-2 (Creating a Detached prompt with additional details),:

detached_info = DetachedPromptTemplate(prompt_id="n/a",
                                model_id="arn:aws:bedrock:us-east1:123456789012:provisioned-model/anthropic.claude-v2",
                                model_provider="AWS Bedrock",
                                model_name="Anthropic Claude 2.0",
                                model_url="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-claude.html",
                                prompt_url="n/a",
                                prompt_additional_info={"AWS Region": "us-east1"}
                                )

prompt_template = PromptTemplate(
                                 prompt_variables= {"text": "value" }
                                 input="Input text to be given",

                                 model_parameters={"decoding_method":"greedy"
                                                  "max_new_tokens":2034,
                                                  "min_new_tokens":0,
                                                  "random_seed":0,
                                                  "top_k":0,
                                                  "top_p":0
                                                  }


external_prompt = facts.client.asests.create_detached_prompt(name="External prompt sample (model AWS Bedrock Anthropic)", 
                                     model_id="anthropic.claude-v2", 
                                     task_id="summarization",
                                     detached_information=ivar_detached_info, 
                                     description="My First External Prompt", 
                                     prompt_details=prompt_template, 
                                    )
create_prompt(input_mode: str, name: str, task_id: str, prompt_details: PromptTemplate, model_id: str = None, model_type: str = None, deployment_id: str = None, description: str = None, container_type: str = None, container_id: str = None) AIGovAssetUtilities

Create a Regular Prompt Template Asset.

Parameters:
  • input_mode (str) – The mode in which the prompt is being created. Currently supports “structured” and “freeflow” modes.

  • name (str) – The name of prompt being created.

  • model_id (str) – The identifier of the model associated with the prompt

  • task_id (str) – Describes possible Task for the prompt template creation

  • prompt_details (PromptTemplate) – Holds information about model version details, prompt variables, instructions, input/output prefixes, and example data

  • description (str) – (Optional) description of the extrnal prompt to be created

  • container_id (str) – (Optional) used to save the detached prompt

Return Type:

AIGovAssetUtilities

Example-1 (Creating a Structured prompt template assest),:

prompt_template = PromptTemplate(model_version={"number": "2.0.0-rc.7", "tag": "tag", "description": "Description of the model version"},
                             input="Input text to be given",
                             prompt_variables= {"text": "value"}
                             prompt_instruction="Your prompt instruction",
                             input_prefix="Your input prefix,
                             output_prefix="Your output prefix",
                             examples={"What is the capidddtal of France{text}?": "The capital of France is Paris{text}.",
                                        "Who wrote '1984{text}'?": "George Orwell wrote '1984'{text}."},

                            model_parameters={"decoding_method":"greedy"
                                              "max_new_tokens":2034,
                                              "min_new_tokens":0,
                                              "random_seed":0,
                                              "top_k":0,
                                              "top_p":0
                                              }

structured_prompt = facts.client.asests.create_prompt(input_mode="structured",
                                                      name=" structured prompt sample",
                                                      task_id="summarization",
                                                      model_id="ibm/granite-13b-chat-v2", 
                                                      description="My First structured prompt",
                                                      prompt_details=prompt_template,
                                                      )

Example-2 (Creating a Freeflow prompt template assest),:

prompt_template = PromptTemplate(
                             input="Input text to be given",
                             prompt_variables= {"text": "value"}

                            model_parameters={"decoding_method":"greedy"
                                              "max_new_tokens":2034,
                                              "min_new_tokens":0,
                                              "random_seed":0,
                                              "top_k":0,
                                              "top_p":0
                                              }
                            )

freeflow_prompt = facts.client.asests.create_prompt(input_mode="freeflow",
                                                    name="Freeflow prompt sample",
                                                    task_id="summarization",
                                                    model_id="ibm/granite-13b-chat-v2", 
                                                    description="My First Freeflow prompt",
                                                    prompt_details=prompt_template,
                                                    )
get_prompt(asset_id: str, container_type: str = None, container_id: str = None) AIGovAssetUtilities

Retrieve a prompt asset from the AI government asset utilities.

This method allows retrieval of a prompt asset from the AI government asset utilities, either by providing the ID of the prompt, or by specifying the container type and container ID where the prompt is stored.

Parameters:
  • prompt_id (str): The ID of the prompt asset to retrieve.

  • container_type (str optional): The type of container where the prompt is stored.

  • container_id (str optional): The ID of the container where the prompt is stored.

Returns:

AIGovAssetUtilities: An instance of AIGovAssetUtilities for managing the retrieved prompt asset.

Note:
  • To retrieve a prompt asset, either the ‘prompt_id’ or both ‘container_type’ and ‘container_id’ must be provided.

  • If ‘prompt_id’ is provided, the method will directly fetch the prompt with that ID.

  • If ‘container_type’ and ‘container_id’ are provided, the method will search for the prompt within the specified container.

Example usage,:

#Retrieve a prompt asset using prompt ID
retrieved_prompt= facts_client.asests.get_prompt(asset_id="********")
retrieved_prompt= facts_client.asests.get_prompt(asset_id="********")
# Retrieve a prompt asset using container type and container ID
retrieved_prompt= facts_client.asests.get_prompt(asset_id="********",container_type="project", container_id"*****")
retrieved_prompt= facts_client.asests.get_prompt(asset_id="********",container_type="project", container_id"*****")
get_workspace_association_info(workspace_info: List[dict[str, str]]) None

This method can be used to get and display usecase and phase details for a single workspace or a list of workspaces. The workspace can be either project or space.

Parameters:

worspace_details (workspace_info is a dictionary with) – project id or space id and workspace_type: type of workspace , values can be either “project” or “space”

egworkspace_info = [

{“id”: project_id1, “type”: “project”}, {“id”: project_id2, “type”: “project”}, {“id”: space_id, “type”: “space”},

]

Returns:

None