DEV Community

Tech Community for Software AG Tech Community

Posted on • Originally published at tech.forums.softwareag.com on

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”
}

Enter fullscreen mode Exit fullscreen mode

image

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

image

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

image

image

Then select the Create Moderation action:

image

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

image

Press Next, and then test the action.

You see the results/scores returned from the moderation:

image

5.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

6.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:

image

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.

image

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

image

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

image

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

image

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

image

11.Your workflow should now look something like this:

image

12.Now we need to configure the Completion to generate the AI survey response.
13.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.

image

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:

image

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

image

15.Press Done.

16.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.

image

image

17.Press Next and Test this response.

18.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.

image

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

image

You can then test the whole integration:

image

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)

image

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

image

You can register for an OpenAI account from here: OpenAI API. 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.

Read full topic

Top comments (0)