IBM watsonx.ai software¶
Requirements¶
For information on how to start working with IBM watsonx.ai software, refer to Getting started with IBM Cloud Pak® for Data 4.8.
Supported machine learning frameworks¶
- For a list of supported machine learning frameworks (models) of IBM watsonx.ai software, refer to watsonx.ai documentation:
Authentication¶
If you are a user of IBM watsonx.ai software with IBM Cloud Pak® for Data 4.8, you can create a IBM watsonx.ai Python client by providing your credentials or using a token:
Note
To determine your <APIKEY>, refer to Generating API keys.
The base URL for ibm_watsonx_ai comes from the cluster and add-on service instance. The URL follows this pattern:
https://{cpd_cluster}
{cpd_cluster}
represents the name or IP address of your deployed cluster. For the Cloud Pak for Data system, use a hostname that resolves to an IP address in the cluster.
To find the base URL, view the details for the service instance from the Cloud Pak for Data web client. Use that URL in your requests to watsonx.ai software.
Example of creating the client using username and password credentials:
from ibm_watsonx_ai import APIClient
from ibm_watsonx_ai import Credentials
credentials = Credentials(
url = "<URL>",
username = "<USERNAME>",
password = "<PASSWORD>",
instance_id = "openshift",
version = "4.8"
)
client = APIClient(credentials)
Example of creating the client using username and apikey credentials:
from ibm_watsonx_ai import APIClient
from ibm_watsonx_ai import Credentials
credentials = Credentials(
url = "<URL>",
username = "<USERNAME>",
api_key = "<API_KEY>",
instance_id = "openshift",
version = "4.8"
)
client = APIClient(credentials)
Example of creating the client using a token:
Note: In IBM watsonx.ai software with IBM Cloud Pak® for Data 4.8, you can authenticate with a token set in the notebook environment.
access_token = os.environ['USER_ACCESS_TOKEN']
from ibm_watsonx_ai import APIClient
from ibm_watsonx_ai import Credentials
credentials = Credentials(
url = "<URL>",
token = access_token,
instance_id = "openshift"
version = "4.8"
)
client = APIClient(credentials)
- Note:
The version value should be set to the version and release format (for example: 4.8) for the IBM watsonx.ai software you are using.
Setting a default space ID or project ID is mandatory, except for a lightweight engine. For examples, refer to the
client.set.default_space()
andclient.set.default_project()
APIs in this document.
- Note for IBM watsonx.ai software with IBM Cloud Pak® for Data 4.8 and later:
If the following error appears during authentication:
Attempt of generating `bedrock_url` automatically failed. If iamintegration=True, please provide `bedrock_url` in wml_credentials. If iamintegration=False, please validate your credentials.
There are two possible causes:
If you chose iamintegration=False (default configuration) during installation, the credentials might be invalid or the service is temporary unavailable.
If you chose iamintegration=True during installation, the autogeneration of bedrock_url wasn’t successful. Provide the IBM Cloud Pak foundational services URL as the bedrock_url param in the wml_credentials.
To get the IBM Cloud Pak foundational services URL, refer to Authenticating for programmatic access.
watsonx.ai lightweight engines¶
For a watsonx.ai lightweight engine, you do not need to authenticate with a WML service and do not need to provide a project_id or space_id.
Example of creating the client with only lightweight engine support:
from ibm_watsonx_ai import APIClient
from ibm_watsonx_ai import Credentials
credentials = Credentials(
username="username",
password="***********",
url="<URL>",
instance_id="openshift",
version="5.0"
)
client = APIClient(credentials=credentials)
Note: Do not use methods such as client.set.default_space()
and client.set.default_project()
when you are using a watsonx.ai lightweight engine.