def test_list_model_auth_bad_key(self, resource_group, location,
                                  form_recognizer_account,
                                  form_recognizer_account_key):
     client = FormTrainingClient(form_recognizer_account,
                                 AzureKeyCredential("xxxx"))
     with self.assertRaises(ClientAuthenticationError):
         result = client.list_model_infos()
         for res in result:
             test = res
Esempio n. 2
0
    def manage_custom_models(self):
        # [START get_account_properties]
        from azure.core.credentials import AzureKeyCredential
        from azure.core.exceptions import ResourceNotFoundError
        from azure.ai.formrecognizer import FormTrainingClient

        form_training_client = FormTrainingClient(
            endpoint=self.endpoint, credential=AzureKeyCredential(self.key))
        # First, we see how many custom models we have, and what our limit is
        account_properties = form_training_client.get_account_properties()
        print(
            "Our account has {} custom models, and we can have at most {} custom models"
            .format(account_properties.custom_model_count,
                    account_properties.custom_model_limit))
        # [END get_account_properties]

        # Next, we get a paged list of all of our custom models
        # [START list_model_infos]
        custom_models = form_training_client.list_model_infos()

        print("We have models with the following ids:")

        # Let's pull out the first model
        first_model = next(custom_models)
        print(first_model.model_id)
        for model in custom_models:
            print(model.model_id)
        # [END list_model_infos]

        # Now we'll get the first custom model in the paged list
        # [START get_custom_model]
        custom_model = form_training_client.get_custom_model(
            model_id=first_model.model_id)
        print("Model ID: {}".format(custom_model.model_id))
        print("Status: {}".format(custom_model.status))
        print("Created on: {}".format(custom_model.created_on))
        print("Last modified: {}".format(custom_model.last_modified))
        # [END get_custom_model]

        # Finally, we will delete this model by ID
        # [START delete_model]
        form_training_client.delete_model(model_id=custom_model.model_id)

        try:
            form_training_client.get_custom_model(
                model_id=custom_model.model_id)
        except ResourceNotFoundError:
            print("Successfully deleted model with id {}".format(
                custom_model.model_id))