ChatGPT Callbacks
ChatGPT offers the ability to access functions in the customer system and incorporate information into its responses whose sources are not normally accessible.
OpenAI describes this feature here.
Requirement
You have successfully configured ChatGPT in todo4teams as described here.
Example
You offer your customers a chat (implemented by integrating ChatGPT) that provides answers to typical service inquiries: Where can I find the user manual for X? How long is the warranty valid? etc.
However, ChatGPT cannot answer many typical questions because they would require queries to your CRM system, for example: What is my current bonus points balance? How long does my subscription last? Do I still have a "VIP" customer status?
Solution scheme
To solve this problem, ChatGPT must be able to retrieve data from your CRM system. However, ChatGPT does not have an interface for this and should not receive access keys for this sensitive data source.
Therefore, the following procedure was chosen:
- The "prompt" you send to ChatGPT is supplemented with a description of service functions.
- ChatGPT recognizes the purpose of these functions based on a textual description and the documentation of the parameters and understands what information it can obtain in the customer dialog.
- It describes in a defined format which functions it wants to execute to answer a prompt, but delegates execution back to the client side (in our case, todo4teams).
- The client side (todo4teams) executes the function and sends the result back to ChatGPT.
- ChatGPT repeats this process if necessary until the required information is complete.
- It inserts this data into the response and answers the prompt as usual.
The diagram here illustrates this process.
Procedure in todo4teams
Consider the following example: In emails to todo4teams, the customer can request various information about their customer account—for example, their VIP status.
You implement the function for determining the VIP status (for a given email address) in the email reception script in todo4teams.
The description of this function must be created manually for ChatGPT and could look something like this:
{
type: 'function',
function: {
name: 'getVIPStatus',
description: 'Get VIP status of a customer by his email address. Returns the VIP status as a string.',
strict: true,
parameters: {
additionalProperties: false,
type: 'object',
properties: {
emailaddress: {
description: 'email address of the customer',
type: 'string'
}
},
required: ['emailaddress']
}
}
}
]
The format is specified by ChatGPT and documented at the link above.
This description is now made known to the AIHelper object in todo4teams. This is done using the setFunctionDefinitions() method:
var defs = new org.json.JSONArray(
"[{type: 'function',function: {name: 'getVIPStatus',description: 'Get VIP status of a customer by his email address. Returns the VIP status as a string.', strict:true, parameters: {additionalProperties:false, type: 'object', properties: { emailaddress: { description: 'email address of the customer', type: 'string' }}, required:['emailaddress']}}}]");
ai.setFunctionDefinitions(defs)
The getVIPStatus() function specified here must now be deployed in todo4teams.
The easiest way to do this is to write a corresponding function directly in the receiving script and pass it to the AI interface:
'getVIPStatus': function(args){
// args is a JSONObject, as defined in parameters!
println("getVIPStatus called! "+args);
println("VIP? "+args.getString("emailaddress"));
return 'VIP, Gold level';
}
});
Here, an anonymous JavaScript object is created that implements a getVIPStatus() method. Our example function always returns the result 'VIP, Gold Level'. However, it could also access your CRM system.
You could trigger the use of this callback with the following call to ChatGPT:
In our test, the following response is returned to this prompt:
Alternative provision of the callback handler
Instead of processing the callbacks in JavaScript, you can also delegate them to a Java implementation.
To do this, provide a JAR file (e.g., with the implementation of com.myorg.todo.ai.MyCallbackHandler) and register it in todo4teams, as described here.
Then create the object in the script and pass it to the AI helper:
Your class MyCallbackHandler must implement the above-mentioned method getVIPStatus() in this form:
import org.json.JSONObject;
public class MyCallbackHandler
{
public String getVIPStatus(Object args)
{
JSONObject jargs = (JSONObject) args;
String emailaddress = jargs.getString("emailaddress");
// calculate the VIP level for this email address
return vipStatus;
}
}
}