Code Monkey home page Code Monkey logo

nlp-gauntlet's Introduction

CI

Nlp Gauntlet

The Nlp Gauntlet was designed to hold any number of external Natural Language Processing services, better known as NLP services. When used in combination, their already impressive powers make the wearer able to do anything they want.

The goal of this project is to make integration and testing of external NLP services in Apex as easy as snapping your fingers. We achieve this by providing a common interface to invoke and consume results for different NLP service implementations. Having a common output across providers allows swapping NLP services without having to re-write any of the applications that consume the prediction results.

Installation instructions

Method 1 : Un-managed package installation

To install using a pre-built package, use the installation links provided here

Method 2 : Non-Scratch Org quick deploy

Deploy to Salesforce

Method 3 : Scratch Org quick deploy

Deploy

Method 4 : Scratch Org sfdx CLI deploy

  1. Install Salesforce DX. Enable the Dev Hub in your org or sign up for a Dev Hub trial org and install the Salesforce DX CLI. Follow the instructions in the Salesforce DX Setup Guide or in the App Development with Salesforce DX Trailhead module.

  2. Clone the nlp-gauntlet repository:

    git clone https://github.com/forcedotcom/nlp-gauntlet
    cd nlp-gauntlet
  3. Create a scratch org and provide it with an alias (nlp-gauntlet):

    sfdx force:org:create -s -f config/project-scratch-def.json -a nlp-gauntlet
  4. Push the app to your scratch org:

    sfdx force:source:push
  5. Assign the External Nlp Admin permission set to the default user:

    sfdx force:user:permset:assign -n External_Nlp_Admin
  6. Open the scratch org:

    sfdx force:org:open

Setup instructions

Once you have deployed the source code to your org, you can begin the authorization setup for your corresponding NLP service provider.

The provided service implementations rely on Named Credentials to generate the authorization tokens.

This project will create some Sample Named Credentials in your org but you will need to edit/clone these with the right credentials/certificates.

  1. Go to Setup > Security > Named Credentials and edit the corresponding Named Credential.

    Below you'll find instructions on how to setup and test each specific Nlp Service:

  2. Next, go to /apex/ExternalNlpWorkbench in your browser to verify connectivity and run some tests.

    The Nlp Gauntlet Workbench tool allows you to test out different model configurations. You can also load saved configurations from Custom Metadata Types in your org.

    Nlp Gauntlet Workbench

  3. Once you've verified the connection and confirmed your models are working correctly. You can consume these predictions from your apex code :

        // Instantiate external nlp service
        // Replace with your provider type (e.g. WitAi, Watson, DialogFlow, Luis)
        ExternalNlpService extNlpService = ExternalNlpServiceFactory.makeNlpService(EinsteinAiService.class);
    
        // Un-comment line below if instantiating from a Custom Metadata Definition
        //ExternalNlpService extNlpService = ExternalNlpServiceFactory.makeNlpService('Einstein_ai');
    
        // Set model parameters
        List<ExternalNlpModelParameters> modelParams = new List<ExternalNlpModelParameters>{
            new ExternalNlpModelParameters.Builder()
                .setModelId('Your Model/App/Skill/etc Id')
                .setNamedCredentialKey('Your Named Credential Key') // Case-sensitive name
                .build()
        };
    
        // Set thresholds and additional parameters (if needed)
        ExternalNlpServiceParameters serviceParams = new ExternalNlpServiceParameters.Builder()
            .setModelParams(modelParams)
            .setIntentThreshold((Double)0.7)
            .setNerThreshold((Double)0.7)
            .setSentimentThreshold((Double)0.7)
            .setAdditionalParams(new Map<String, String>())
            .build();
    
        // Get predictions
        ExternalNlpPredictionResult results = extNlpService.predict(serviceParams, 'Your text to be analyzed', 'en_US');
    
        // Consume predictions
        System.debug(results.getIntentResults().getPredictedIntents());
        System.debug(results.getIntentResults().getHighestConfidenceIntentName());
        System.debug(results.getEntityResults().getPredictedEntities());
        System.debug(results.getSentimentResults().getDocumentSentiment());
  4. Profit!

    You can now retire on a quiet farm and stare at the universe you just created.

Adding a new service

To add a new service to the nlp gauntlet follow the steps provided in this guide

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.