Namespace
EinsteinLLM Methods
generateMessagesForPromptTemplate(promptTemplateDevName, promptTemplateGenerationsInput)
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.
Return Value
Type: ConnectApi.EinsteinPromptTemplateGenerationsRepresentation
Example
In this example, call generateMessagesForPromptTemplate(promptTemplateDevName, promptTemplateGenerationsInput) to resolve a Sales Email prompt template. For more examples, see Resolve a Prompt Template.
// Create input
ConnectApi.EinsteinPromptTemplateGenerationsInput promptGenerationsInput = new ConnectApi.EinsteinPromptTemplateGenerationsInput();
promptGenerationsInput.isPreview = false;
// Build input map
Map<String,ConnectApi.WrappedValue> valueMap = new Map<String,ConnectApi.WrappedValue>();
Map<String, String> recipientEntityRecordIdMap = new Map<String, String>();
recipientEntityRecordIdMap.put('id', '00Qxx000002ToPvEAK');
Map<String, String> senderEntityRecordIdMap = new Map<String, String>();
senderEntityRecordIdMap.put('id', '005xx000001XiWLAA0');
ConnectApi.WrappedValue recipientEntityWrappedValue = new ConnectApi.WrappedValue();
recipientEntityWrappedValue.value = recipientEntityRecordIdMap;
ConnectApi.WrappedValue senderEntityWrappedValue = new ConnectApi.WrappedValue();
senderEntityWrappedValue.value = senderEntityRecordIdMap;
valueMap.put('Input:Account', recipientEntityWrappedValue);
valueMap.put('Input:Recipient', recipientEntityWrappedValue);
valueMap.put('Input:Sender', senderEntityWrappedValue);
promptGenerationsInput.inputParams = valueMap;
// Set additional configuration values
promptGenerationsInput.additionalConfig = new ConnectApi.EinsteinLlmAdditionalConfigInput();
promptGenerationsInput.additionalConfig.applicationName = 'PromptTemplateGenerationsInvocable';
// Call the service
ConnectApi.EinsteinPromptTemplateGenerationsRepresentation generationsOutput =
ConnectApi.EinsteinLLM.generateMessagesForPromptTemplate('0hfxx0000000KTNAA2', promptGenerationsInput);
// Consume response
System.debug('Prompt Testing: ' + generationsOutput.prompt);
getPromptTemplates(query, sortBy, offset, pageLimit, fields, type, relatedEntity, isActive)
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.
Return Value
Type: ConnectApi.EinsteinPromptRecordCollectionOutputRepresentation
Usage
To get a list of prompt templates, you must have Einstein Generative AI enabled and the Execute Prompt Templates user permission.
Example
ConnectApi.EinsteinPromptRecordCollectionOutputRepresentation promptTemplateList = ConnectApi.EinsteinLLM.getPromptTemplates('Summarize', 'CreatedDate', 0, 5, null, 'einstein_gpt__flex', null, true);
// Get information from the prompt templates in the list
if (promptTemplateList != null && promptTemplateList.promptRecords != null) {
for (ConnectApi.EinsteinPromptRecordRepresentation promptTemplate : promptTemplateList.promptRecords) {
System.debug('Prompt Template ID: ' + promptTemplate.id);
for (String fieldName : promptTemplate.fields.keySet()) {
System.debug('Field Name: ' + fieldName + ', Value: ' + promptTemplate.fields.get(fieldName).value);
}
}
} else {
System.debug('No prompt templates found.');
}