V1 Migration Guide¶
New ibm_watsonx_ai
Python SDK 1.0 is backward compatible in most common scenarios,
but few minor adjustments in code may be needed.
What’s new?¶
Refactor and Cleanup¶
This major release marks a thorough refactoring and cleanup of the codebase. We’ve diligently worked to improve code readability, and enhance overall performance. As a result, users can expect a more efficient and maintainable package.
Easier project and space setup¶
Starting from ibm_watsonx_ai
1.0 release users can set the default space
or project while initializing APIClient object.
✅ New approach
client_project = APIClient(credentials, project_id = project_id)
client_space = APIClient(credentials, space_id = space_id)
❌ Old approach
client_project = APIClient(credentials)
client_project.set.default_project(project_id)
client_space = APIClient(credentials)
client_space.set.default_space(space_id)
Foundation models functions moved under APIClient¶
Starting from ibm_watsonx_ai
1.0 foundation models functions (get_model_specs
, get_custom_model_specs
,
get_model_lifecycle
, get_model_specs_with_prompt_tuning_support
, get_embedding_model_specs
) are moved into client.foundation_models
object.
Old versions of the functions are not removed, however, as they lack authentication, they will no longer work.
✅ New approach - Using functions from client.foundation_models.
client.foundation_models.get_model_specs()
client.foundation_models.get_custom_model_specs()
client.foundation_models.get_custom_model_specs(
model_id='mistralai/Mistral-7B-Instruct-v0.2'
)
client.foundation_models.get_custom_model_specs(limit=20)
client.foundation_models.get_custom_model_specs(limit=20, get_all=True)
client.foundation_models.get_model_lifecycle(
model_id="ibm/granite-13b-instruct-v2"
)
client.foundation_models.get_model_specs_with_prompt_tuning_support()
client.foundation_models.get_embeddings_model_specs()
❌ Old approach - Using functions from ibm_watsonx_ai.foundation_models module.
from ibm_watsonx_ai.foundation_models import (
get_model_specs,
get_custom_models_spec,
get_model_lifecycle,
get_model_specs_with_prompt_tuning_support,
get_embedding_model_specs
)
get_model_specs(
url="https://us-south.ml.cloud.ibm.com"
)
get_custom_models_spec(api_client=client)
get_custom_models_spec(credentials=credentials)
get_custom_models_spec(api_client=client, model_id='mistralai/Mistral-7B-Instruct-v0.2')
get_custom_models_spec(api_client=client, limit=20)
get_custom_models_spec(api_client=client, limit=20, get_all=True)
get_model_lifecycle(
url="https://us-south.ml.cloud.ibm.com",
model_id="ibm/granite-13b-instruct-v2"
)
get_model_specs_with_prompt_tuning_support(
url="https://us-south.ml.cloud.ibm.com"
)
get_embedding_model_specs(
url="https://us-south.ml.cloud.ibm.com"
)
Breaking changes¶
client.<resource>.list()
methods don’t print the table with listed assets. They return the table aspandas.DataFrame
. The optional parameter for the methodsreturn_as_df
was removed.
✅ New approach - Access to credentials fields as class attributes.
conn_list = client.connections.list() ## table not printed
❌ Old approach - Table with listed resources printed.
conn_list = client.connections.list()
### Table returned as pandas.DataFrame `conn_list` object and printed output:
--------------------------- ------------------------------------ -------------------- ------------------------------------
NAME ID CREATED DATASOURCE_TYPE_ID
Connection to COS 71738a79-6585-4f33-bf4a-18907abcf06a 2024-04-25T10:42:23Z 193a97c1-4475-4a19-b90c-295c4fdc6517
--------------------------- ------------------------------------ -------------------- ------------------------------------
Methods and parameters that were marked as deprecated in
ibm_watsonx_ai v0
were removed. For example:
✅ New approach - Use method that replaced deprecated one, for get_uid
it’s get_id
asset_id = client.data_assets.get_id(asset_details)
❌ Old approach - Deprecated get_uid
method called
client.data_assets.get_uid(asset_details)
client.credentials
andclient.wml_credentials
returnsCredentials
object instead of dictionary.
✅ New approach - Access to credentials fields as class attributes.
from ibm_watsonx_ai import APIClient
from ibm_watsonx_ai import Credentials
credentials = Credentials(
url = "https://us-south.ml.cloud.ibm.com",
token = "***********",
)
client = APIClient(credentials)
url = client.credentials.url
# OR
url = credentials.url
❌ Old approach - Access to credentials fields as keys in dictionary.
from ibm_watsonx_ai import APIClient
credentials = {
"url": "https://us-south.ml.cloud.ibm.com",
"token":"***********",
}
client = APIClient(credentials)
url = client.wml_credentials.get('url')
Parameter changes in
service.score(...)
for online deployment
service.score(...)
has additional forecast_window
parameter added before transaction_id
parameter.
Additionally, service.score(...)
function will require from 1.0.0 to pass all named parameters except payload
parameter.
✅ New approach - named parameters and new parameter.
predictions = service.score({
"observations": AbstractTestTSAsync.observations,
"supporting_features": AbstractTestTSAsync.supporting_features,
},
forecast_window=1,
transaction_id=transaction_id,
)
❌ Old approach - all parameters not named, forecast_window
parameter absent
predictions = service.score({
"observations": AbstractTestTSAsync.observations,
"supporting_features": AbstractTestTSAsync.supporting_features,
},
transaction_id,
)
Deprecations¶
Initializing
APIClient
withcredentials
as dictionary is deprecated.- All parameters with
wml
in name are deprecated. They were renamed to: wml_credentials
->credentials
wml_client
->api_client
.
- All parameters with
id
naming was aligned in parameters and methods, now alluid
should be replaced byid
. Methods that were usinguid
were either removed or mark as deprecated.