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_count
is no longer a parameter of the list_workspaces() methodinclude_count
is no longer a parameter of the list_intents() methodinclude_count
is no longer a parameter of the list_examples() methodinclude_count
is no longer a parameter of the list_counterexamples() methodinclude_count
is no longer a parameter of the list_entities() methodinclude_count
is no longer a parameter of the list_values() methodinclude_count
is no longer a parameter of the list_synonyms() methodinclude_count
is no longer a parameter of the list_dialog_nodes() methodvalue_type
was renamed totype
in the create_value() methodnew_value_type
was renamed tonew_type
in the update_value() methodnode_type
was renamed totype
in the create_dialog_node() methodnew_node_type
was renamed tonew_type
in the update_dialog_node() methodvalue_type
was renamed totype
in the CreateValue modelnode_type
was renamed totype
in the DialogNode modelaction_type
was renamed totype
in the DialogNodeAction modelquery_type
property was added to the DialogNodeOutputGeneric modelquery
property was added to the DialogNodeOutputGeneric modelfilter
property was added to the DialogNodeOutputGeneric modeldiscovery_version
property was added to the DialogNodeOutputGeneric model- LogMessage model no longer has
_additionalProperties
DialogRuntimeResponseGeneric
was renamed toRuntimeResponseGeneric
- RuntimeEntity model no longer has
_additionalProperties
- RuntimeIntent model no longer has
_additionalProperties
value_type
was renamed totype
in the Value model
action_type
was renamed totype
in the DialogNodeAction model- DialogRuntimeResponseGeneric was renamed to RuntimeResponseGeneric
convert_to_html()
method does not require a filename parameter
return_fields
was renamed toreturn_
in the query() methodlogging_opt_out
was renamed tox_watson_logging_opt_out
in the query() methodspelling_suggestions
was added to the query() methodcollection_ids
is no longer a parameter of the query() methodreturn_fields
was renamed toreturn_
in the QueryNotices() methodlogging_opt_out
was renamed tox_watson_logging_opt_out
in the federated_query() methodcollection_ids
is now required in the federated_query() methodcollection_ids
changed position in the federated_query() methodreturn_fields
was renamed toreturn_
in the federated_query() methodreturn_fields
was renamed toreturn_
in the federated_query_notices() methodenrichment_name
was renamed toenrichment
in the Enrichment modelfield_type
was renamed totype
in the Field modelfield_name
was renamed tofield
in the Field model- test_configuration_in_environment() method was removed
- query_entities() method was removed
- query_relations() method was removed
default_models
was renamed todefault
in the list_models() methodtranslation_output
was renamed totranslation
in the Translation model
metadata
was renamed totraining_metadata
in thecreate_classifier()
method
final_results
was renamed tofinal
in the SpeakerLabelsResult modelfinal_results
was renamed tofinal
in the SpeechRecognitionResult model
detect_faces()
method was removedclass_name
was renamed toclass_
in the ClassResult modelclass_name
was renamed toclass_
in the ModelClass model
- New Service!