Newer Version Available

This content describes an older version of this product. View Latest

EinsteinLLM Class

Get a list of prompt templates and generate LLM responses for prompt templates.

Namespace

ConnectApi

EinsteinLLM Methods

These methods are for EinsteinLLM. All methods are static.

generate​MessagesFor​PromptTemplate​(promptTemplate​DevName, prompt​Template​GenerationsInput)

Generates a response using the specified prompt template and input parameters.

API Version

60.0

Requires Chatter

No

Signature

public static ConnectApi.EinsteinPromptTemplateGenerationsRepresentation generateMessagesForPromptTemplate(String promptTemplateDevName, ConnectApi.EinsteinPromptTemplateGenerationsInput promptTemplateGenerationsInput)

Parameters

promptTemplateDevName
Type: String
Developer name or ID of a prompt template record.
promptTemplateGenerationsInput
Type: ConnectApi.EinsteinPromptTemplateGenerationsInput
Input for generating a response using the specified prompt template.

Example

In this example, call generateMessagesForPromptTemplate(promptTemplateDevName, promptTemplateGenerationsInput) to resolve a Sales Email prompt template. For more examples, see Resolve a Prompt Template.

1// Create input
2ConnectApi.EinsteinPromptTemplateGenerationsInput promptGenerationsInput = new ConnectApi.EinsteinPromptTemplateGenerationsInput();
3promptGenerationsInput.isPreview = false;
4
5// Build input map
6Map<String,ConnectApi.WrappedValue> valueMap = new Map<String,ConnectApi.WrappedValue>();
7
8Map<String, String> recipientEntityRecordIdMap = new Map<String, String>();
9recipientEntityRecordIdMap.put('id', '00Qxx000002ToPvEAK');
10
11Map<String, String> senderEntityRecordIdMap = new Map<String, String>();
12senderEntityRecordIdMap.put('id', '005xx000001XiWLAA0');
13
14ConnectApi.WrappedValue recipientEntityWrappedValue = new ConnectApi.WrappedValue();
15recipientEntityWrappedValue.value = recipientEntityRecordIdMap;
16
17ConnectApi.WrappedValue senderEntityWrappedValue = new ConnectApi.WrappedValue();
18senderEntityWrappedValue.value = senderEntityRecordIdMap;
19
20valueMap.put('Input:Account', recipientEntityWrappedValue);
21valueMap.put('Input:Recipient', recipientEntityWrappedValue);
22valueMap.put('Input:Sender', senderEntityWrappedValue);
23
24promptGenerationsInput.inputParams = valueMap;
25
26// Set additional configuration values
27promptGenerationsInput.additionalConfig = new ConnectApi.EinsteinLlmAdditionalConfigInput();
28promptGenerationsInput.additionalConfig.applicationName = 'PromptTemplateGenerationsInvocable';
29
30// Call the service
31ConnectApi.EinsteinPromptTemplateGenerationsRepresentation generationsOutput = 
32ConnectApi.EinsteinLLM.generateMessagesForPromptTemplate('0hfxx0000000KTNAA2', promptGenerationsInput);
33
34// Consume response
35System.debug('Prompt Testing: ' + generationsOutput.prompt);

getPromptTemplates(query, sortBy, offset, pageLimit, fields, type, relatedEntity, isActive)

Get a list of prompt templates using the specified filters.

API Version

62.0

Requires Chatter

No

Signature

public static ConnectApi.EinsteinPromptRecordCollectionOutputRepresentation getPromptTemplates(String query, String sortBy, Integer offset, Integer pageLimit, List<String> fields, String type, String relatedEntity, Boolean isActive)

Parameters

query
Type: String
User-entered search string. If null, all prompt template records are returned.
sortBy
Type: String
Field to sort the returned prompt template records by, such as createdDate. If null, records are returned in the order they’re retrieved.
offset
Type: Integer
Used for pagination. Number of rows to skip between returned prompt template records. The default value is 0.
pageLimit
Type: Integer
Used for pagination. Maximum number of prompt template records returned per page. The default value is 50.
fields
Type: List<String>
Comma-separated list of prompt template record fields to return, such as createdDate. If null, all fields are returned.
type
Type: String
Prompt template type to filter records by, such as einstein_gpt__salesEmail. If null, records of all types are returned.
relatedEntity
Type: String
Related entity to filter records by, such as Contact. If null, all records with all related entities are returned.
isActive
Type: Boolean
Specifies whether to return active prompt templates only. The default is false.

Usage

To get a list of prompt templates, you must have Einstein Generative AI enabled and the Execute Prompt Templates user permission.

Example

1ConnectApi.EinsteinPromptRecordCollectionOutputRepresentation promptTemplateList = ConnectApi.EinsteinLLM.getPromptTemplates('Summarize', 'CreatedDate', 0, 5, null, 'einstein_gpt__flex', null, true);
2
3// Get information from the prompt templates in the list
4    if (promptTemplateList != null && promptTemplateList.promptRecords != null) {
5    for (ConnectApi.EinsteinPromptRecordRepresentation promptTemplate : promptTemplateList.promptRecords) {
6        System.debug('Prompt Template ID: ' + promptTemplate.id);
7        for (String fieldName : promptTemplate.fields.keySet()) {
8            System.debug('Field Name: ' + fieldName + ', Value: ' + promptTemplate.fields.get(fieldName).value);
9        }
10    }
11} else {
12    System.debug('No prompt templates found.');
13}