Here are simple steps to move from v3.0.0 to v4.0.0. Note that v4.0,0 supports only python 3.5 and above
The constructor no longer accepts individual credentials like iam_apikey, etc. We initialize authenticators from the core. The core supports various authentication mechanisms, choose the one appropriate to your instance and use case.
For example, to pass a IAM apikey:
from ibm_watson import MyService
service = MyService(
iam_apikey='{apikey}',
url='{url}'
)from ibm_watson import MyService
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
service = MyService(
authenticator=authenticator
)
service.set_service_url('{url}')There are 5 authentication variants supplied in the SDK (shown below), and it's possible now to create your own authentication implementation if you need something specific by implementing the Authenticator implementation.
from ibm_cloud_sdk_core.authenticators import BasicAuthenticator
authenticator = BasicAuthenticator(<your_username>, <your_password>)
service = MyService(authenticator=authenticator)from ibm_cloud_sdk_core.authenticators import BearerTokenAuthenticator
authenticator = BearerTokenAuthenticator(<your_bearer_token>)
service = MyService(authenticator=authenticator)
# can set bearer token
service.get_authenticator().set_bearer_token('xxx');from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator
authenticator = CloudPakForDataAuthenticator(
'my_username',
'my_password',
'https://my-cp4d-url',
disable_ssl_verification=True)
service = MyService(authenticator=authenticator)from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('my_apikey')
service = MyService(authenticator=authenticator)from ibm_cloud_sdk_core.authenticators import NoAuthAuthenticator
authenticator = NoAuthAuthenticator()
service = MyService(authenticator=authenticator)from ibm_cloud_sdk_core import get_authenticator_from_environment
authenticator = get_authenticator_from_environment('Assistant')
service = MyService(authenticator=authenticator)We can set the service url using set_service_url() or from external configurations.
service = MyService(
iam_apikey='{apikey}',
url='{url}' # <= here
)service = MyService(
authenticator=authenticator,
)
service.set_service_url('{url}')OR, pass from external configurations like environment variable
export MY_SERVICE_URL="<your url>"The method params which are optional would need to be specified by name rather than position. For example
The list_workspaces with page_limit as 10 was:
assistant_service.list_workspaces(10)We need to specify the optional param name:
assistant_service.list_workspaces(page_limit=10)service.disable_ssl_verification(True)service.set_disable_ssl_verification(True)Constants for methods and models are shown in the form of Enums
The SDK no longer supports Pyhton versions 2.7 and <=3.4.
include_countis no longer a parameter of the list_workspaces() methodinclude_countis no longer a parameter of the list_intents() methodinclude_countis no longer a parameter of the list_examples() methodinclude_countis no longer a parameter of the list_counterexamples() methodinclude_countis no longer a parameter of the list_entities() methodinclude_countis no longer a parameter of the list_values() methodinclude_countis no longer a parameter of the list_synonyms() methodinclude_countis no longer a parameter of the list_dialog_nodes() methodvalue_typewas renamed totypein the create_value() methodnew_value_typewas renamed tonew_typein the update_value() methodnode_typewas renamed totypein the create_dialog_node() methodnew_node_typewas renamed tonew_typein the update_dialog_node() methodvalue_typewas renamed totypein the CreateValue modelnode_typewas renamed totypein the DialogNode modelaction_typewas renamed totypein the DialogNodeAction modelquery_typeproperty was added to the DialogNodeOutputGeneric modelqueryproperty was added to the DialogNodeOutputGeneric modelfilterproperty was added to the DialogNodeOutputGeneric modeldiscovery_versionproperty was added to the DialogNodeOutputGeneric model- LogMessage model no longer has
_additionalProperties DialogRuntimeResponseGenericwas renamed toRuntimeResponseGeneric- RuntimeEntity model no longer has
_additionalProperties - RuntimeIntent model no longer has
_additionalProperties value_typewas renamed totypein the Value model
action_typewas renamed totypein the DialogNodeAction model- DialogRuntimeResponseGeneric was renamed to RuntimeResponseGeneric
convert_to_html()method does not require a filename parameter
return_fieldswas renamed toreturn_in the query() methodlogging_opt_outwas renamed tox_watson_logging_opt_outin the query() methodspelling_suggestionswas added to the query() methodcollection_idsis no longer a parameter of the query() methodreturn_fieldswas renamed toreturn_in the QueryNotices() methodlogging_opt_outwas renamed tox_watson_logging_opt_outin the federated_query() methodcollection_idsis now required in the federated_query() methodcollection_idschanged position in the federated_query() methodreturn_fieldswas renamed toreturn_in the federated_query() methodreturn_fieldswas renamed toreturn_in the federated_query_notices() methodenrichment_namewas renamed toenrichmentin the Enrichment modelfield_typewas renamed totypein the Field modelfield_namewas renamed tofieldin the Field model- test_configuration_in_environment() method was removed
- query_entities() method was removed
- query_relations() method was removed
default_modelswas renamed todefaultin the list_models() methodtranslation_outputwas renamed totranslationin the Translation model
metadatawas renamed totraining_metadatain thecreate_classifier()method
final_resultswas renamed tofinalin the SpeakerLabelsResult modelfinal_resultswas renamed tofinalin the SpeechRecognitionResult model
detect_faces()method was removedclass_namewas renamed toclass_in the ClassResult modelclass_namewas renamed toclass_in the ModelClass model
- New Service!