ChatGPT Integration Example: NPS Survey Response with Moderation

Overview

This webMethods.io Integration workflow example sends automated NPS survey responses generated by the webMethods.io ChatGPT API Connector.

Steps

  1. As this will be an API, create a webhook trigger. image

The body of the post will contain the NPS data as follows:

{
 "email": "example@softwareag.com",
  "score": "10",
  "comments": "very good software. I like it a lot”
}

  1. Just to help with debugging I insert a logger after the webhook and log the payload to help during testing.

image

  1. Next to moderate the input add the ChatGPT connector and provide the API Key:

image

Then select the Create Moderation action:

  1. Map the provided comments to the input of the create moderation action:

Press Next, and then test the action.

You see the results/scores returned from the moderation:

  1. If all the moderation categories are false, then we’ll generate the AI completion, otherwise we’ll return a standard response. For this, I use the switch control, which I drop into the canvas

image

  1. The default condition takes this to a return data on sync webhook action which just returns a pre-created thank you response, which then links to the end action:

Note: the Access-Control-Allow-Origin with a null value was added so I could test this from an HTML page or a local application.

  1. For the other action of the switch, add a ChatGPT connector and link this to the switch action.

  1. Position your mouse over the arrow between the 2 nodes and select the settings icon:

  1. Now configure the conditions for this transition by adding filters for all of the categories and match for false

  1. Ensure the other switch condition is set to the default case by clicking on the settings icon on that arrow and selecting ‘default’

  1. Your workflow should now look something like this:

  1. Now we need to configure the Completion to generate the AI survey response.
  2. Select the Create Completions action and configure it as follows:

a. Set Model to text-davinci-003
b. Set Prompt to: “Create me a response for an NPS survey with a score of “ leaving the cursor in the prompt box and clicking on the score data item from the webhook action.

c. Complete the rest of the prompt as follows: , and where the following comments were provided:
d. Then add the comments to the prompt, so the prompt in total should look something like the following:
Create me a response for an NPS survey with a score of {{$request.body.score}}, and where the following comments were provided: {{$request.body.comments}}
e. Set the temperature to 0.7 (or higher for a more random answer, or lower for a more consistent and deterministic answer).
f. Set max_tokens to 4000
g. Your mapping should then look like this:

  1. Press next, then “Test” the action with the test button and you should see a response from the ChatGPT davinci engine:

  1. Press Done.

  2. Now we’ll moderate the response from ChatGPT for safety by adding another moderation action from ChatGPT and passing the text response from ChatGPT to the moderation API.

  1. Press Next and Test this response.

  2. Lastly, like the previous moderation, we’ll add a switch with the same checks. If all are false we link to a new return data on sync, otherwise we link to the pre-created response.

  1. Lastly, we just need to configure the API response on the return data sync on webhook mapping in the response from ChatGPT:

You can then test the whole integration:

You can also download the workflow archive below and simply import it under your webMethods.io Integration project:

NPS Survey Response (with moderation).zip (91.0 KB)

Note that you will be asked to connect to your OpenAI account and to provide an API key:

You can register for an OpenAI account from here: https://platform.openai.com/overview. After you login, you will need to upgrade your account and create an API key from your account menu.

To learn more about how you can integrate the webMethods.io ChatGPT API Connector with any application, you can watch our demos (we show the steps on how to register for an OpenAI account and create several workflows from scratch):

All connectors available in webMethods.io Integration are listed here Categories - webMethods.io Integration.

If you are new to webMethods.io Integration and want to try it, please refer to this Getting Started with webMethods.io beginner’s guide and sign up here Sign up - Software AG Cloud for a free forever account.


This article is part of the TECHniques newsletter blog - technical tips and tricks for the Software AG community. Subscribe to receive our quarterly updates or read the latest issue.

3 Likes