Skip to main content

Python SDK to register ML model with AI Builder

Project description

Project description

AI Builder SDK

AI Builder is a Microsoft Power Platform capability that provides AI models that are designed to optimize your business processes. AI Builder enables your business to use AI to automate processes and glean insights from your data in Power Apps and Power Automate.

This SDK allows registration of model endpoints as AI Models with power platform to be leveraged in flows and power apps.

Installing

  1. Install Python 3.6+ from the link here. Click the 'Download' link on any version of Python greater than Python 3.6. For Linux and Mac OS please follow the appropriate link on the page. You can also install using an OS specific package manager of your choice.

  2. Run the installer to begin installation and be sure to check the box 'Add Python X.X to PATH'.

  3. Make sure the installation path is in the PATH variable by running:

    python --version
    
  4. After python is installed, install aibuilder by running:

    pip install -f https://test.pypi.org/simple/ aibuilder
    
    

Capabilities

Get an Environment

An environment is a space to store, manage, and share your organization's business data, apps, and flows. It also serves as a container to separate apps that might have different roles, security requirements, or target audiences. How you choose to use environments depends on your organization and the apps you're trying to build. Each environment is created under an Azure Active Directory (Azure AD) tenant, and its resources can only be accessed by users within that tenant. When you create an app in an environment, that app is only permitted to connect to the data sources that are also deployed in that same environment, including connections, gateways, flows, and Dataverse databases. The AI Builder SDK allows you to programmatically retrieve an existing environment where you want to register your machine learning model. Click here to know more about environments in Power Platform.

Registering a model

Once you have your machine learning model hosted on an endpoint, you can then create a scoring script to run the hosted machine learning model. This script which now represents the machine learning model is required to be registered with AI Builder in order to use prediction.

Usage and Examples

Let’s say you have a machine learning model deployed on an endpoint and you are able to deploy the model successfully on an Azure Container Instance. Here is an example use case in AI Builder

      from azureml.core.webservice import AciWebservice, Webservice, Workspace
      from azureml.exceptions import WebserviceException

      from aibuilder.core.environment import Environment
      from aibuilder.models.constants import ModelClientResponseStatus

      # The name of the Power Platform environment where you are registering the model
      environment_name = 'environment_name'
      # The name of the model endpoint to be created in AzureML
      aci_service_name = 'service_name'
      # The name of the model as it will appear in AI Builder
      model_name = "name_of_model_to_be_registered"

      ws = Workspace.get(name='your_workspace_name', subscription_id='your_subscription_id', resource_group='your_resource_group')
      # Get the ACI service based on what you deployed (otherwise, create one if service is not found)
      try:
         service = Webservice(ws, name=aci_service_name)
      except WebserviceException as e:
         print(f"Service not found: {aci_service_name}")
      print(service.state) # Should be displayed as healthy

      # Get the Environment
      env = Environment.get(environment_name= environment_name)
      # Register your machine learning model to AI Builder
      response = env.register_model(model_name= model_name, connection=service)

      if response != ModelClientResponseStatus.success:
         raise Exception('Model registration failed')
      print(f"Registered AI Builder model {model_name}")

License

AI Builder SDK

Copyright (c) Microsoft Corporation
All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the 
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit 
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 
Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

aibuilder-0.0.54-py3-none-any.whl (85.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page