Skip to content

Calling GPT Methods from Apex

All iDialogue Flow Action classes marked Global are accessible via Apex.

Open the developer console to view any of the GPT / AI Apex controller classes.

This will appear if the image fails to load

Available Apex GPT Action Classes

  • AICompletionAction
  • AIDialogueAction
  • AIPromptSObjectUtils
  • AITranscriptAction

Example

Copy and paste the code example below into the Developer Console->Execute Anonymous window.

// Create a GPT Completion Request
rooms.AICompletionAction.Request apiRequest = new rooms.AICompletionAction.Request();
apiRequest.systemMessage = 'Act as a language translator. Convert the following to Latin';
apiRequest.userMessage = 'Hello world';
System.debug('Request: ' + apiRequest.userMessage );
// Invoke the GPT Completion
List<rooms.AICompletionAction.Response> responses = rooms.AICompletionAction.invoke( new List<rooms.AICompletionAction.Request> { apiRequest } );
// Handle the GPT Response
rooms.AICompletionAction.Response apiResponse = responses.get(0);
System.debug('Response: ' + apiResponse.completion );

This will appear if the image fails to load

View the results in the “Logs” tab. Filter by Debug Only.

This will appear if the image fails to load

Notes

Most Apex classes make a callout to the iDialogue API; which is a proxy to OpenAI for managing conversation memory, intent, caching and security.

Any DML executed before the callout may result in a commit error.