Git Product home page Git Product logo

salesforce-einstein-platform-apex's Introduction

Build Status

salesforce-einstein-platform-apex

This repository showcases how to use the Salesforce Einstein Platform API using an Apex based wrapper.

Please check the product documentation for general information about what the Salesforce Einstein Platform API is, how to use it and when it'll be available for you.

The wrapper supersedes the old wrapper for the Salesforce Einstein Vision API. Besided breaking changes compared to the old wrapper this repo contains the v2 of the API (including image-multi-label, language intent and language sentiment).

See the included Playground in action.

Playground

Version history

The current version is 2.2.0 (git tag). Check out the full changelog.

Prerequisites

For using the wrapper you'll need to fulfill the following requirements:

  • Access to a Salesforce org that as minimum API version 41, i. e. a Developer Edition or a scratch org (you can signup here for free if you don't have one).
  • An API account for Salesforce Einstein Platform.

Please find the detailed instructions for how to setup access to the Einstein Platform API here.

Installation

Salesforce DX - new scratch org

Clone the repo to your local file system.

git clone https://github.com/muenzpraeger/salesforce-einstein-platform-apex

Change into the git repo directory and create a new scratch org

sfdx force:org:create -s -f config/project-scratch-def.json

Push the source to the newly created org.

sfdx force:source:push

Salesforce DX - existing scratch org

If you want to add the wrapper to an existing org you can either copy the contents manually from this repo.

Alternatively you can use Wade's OSS plugin for Salesforce DX.

Salesforce DX - deploy online into a scratch org

Again thanks to Wade for creating this neat feature.

Deploy

Configuration

After you've added the wrapper files two steps are required:

  • Set the value for Einstein EMail in Custom Settings => Einstein Settings (via the Manage button) for that org to the email address that you've used to sign up for Einstein Platform.
  • Store the Einstein Platform file as File in the org. The name must be einstein_platform.

If you went through my Trailhead project you likely went through that excercise already.

The installation adds a new Lightning App to your Salesforce org for the included Playground. playground

Usage examples

Creating a PredictionService

The foundation for everything is the PredictionService. As the communication with the API is based on a valid OAuth2 token (see MetaMind documentation) you can initiate a new PredictionService in the following way.

Einstein_PredictionService predictionService = new Einstein_PredictionService(Einstein_PredictionService.Types.IMAGE);

This creates a new prediction service for working with images. You can switch the type so that you can reuse it for other predictions.

service.setType(Einstein_PredictionService.Types.SENTIMENT);

Fetch all trained image datasets

Einstein_PredictionService service = new Einstein_PredictionService(Einstein_PredictionService.Types.IMAGE);
List<Einstein_Dataset> datasets = service.getDatasets();

Train an intent dataset

Einstein_PredictionService service = new Einstein_PredictionService(Einstein_PredictionService.Types.INTENT);
Einstein_Model model = service.trainDataset(datasetId, 'the dataset name', 0, 0, '';

Prediction

You can predict images either by sending Base64, uploading a Blob or a remote (publicly available!) URL. See this example how to validate a remote URL.

Einstein_PredictionResult result = service.predictImageUrl('GeneralImageClassifier', 'yourUrl', 5, '');

The prediction for intent or sentiment is similar. Like this example for intent.

Einstein_PredictionResult result = service.predictIntent('yourModelId', 'theText', 0, '');

Contribution

Feel free to contribute to this project via pull requests. Please read the contribution before you start working on something.

License

For licensing see the included license file.

salesforce-einstein-platform-apex's People

Contributors

christiantravelling avatar fishofprey avatar muenzpraeger avatar wadewegner avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.