Create AI Model

Picture of Kalanithi Balasubramanian

Kalanithi Balasubramanian

Updated on April 10, 2024

To know more about how to configure the Prompt catalog, click here.

The AI Model record specifies the type of AI that GPTfy will invoke for generating responses. The creation of this AI Model record is a one-time activity.

Follow the steps below to create an AI Model. GPTfy allows us to create our own card for an AI model with the help of the ‘Create our own’ card.

Step 1

Access the Cockpit, navigate to the AI Model tile, and select it. Here, you will find a list of available AI Models and a ‘Create your own’ tile to choose from. Locate and select the ‘Create your own card’.

Step 2

  • Label: Name of the AI Model
  • Icon Source and Icon Details: This can be of two types,
    • When the icon source is selected as a Static resource, a static resource needs to be created. The logo should be uploaded in the static resource and under Icon details, the API name of the Static resource be added.
    • When the Icon source is selected the SLDS Icon, Any icon available in the dropdown under Icon Details has to be selected. These are basic salesforce icons.
  • Sequence: This number represents at which position the newly created Model should be seen in the AI Model window.
  • Description: A small description that can be seen on the card.

Step 3: Click Save

  • Once Save button is clicked, it will validate for all the required data.

  • Upon saving, a new tile in the AI Model will be created when the page is reloaded.
  • A new custom metadata record under GPTfy card configurations will be created but not enabled. Make sure the list view is selected as AI Model.

Step 4: Activate the Model

  • In Order to activate the model created, details should be added in the connection details tab.
  • Click on the model newly created and select the connection details tab.
  • Add the details for the required data.
    • Model: This gets automatically filled.
    • Platform: This picklist field helps in identifying on which platform the model has to work.
    • Named Credential: Named Credentials in Salesforce provide a secure and centralized approach to managing authentication information for external systems or services. For example, in order to use GPTfy technology, ‘GPTfy’ named credentials that come with the package can be used.
    • AI Technology: Select what type of AI technology, the connection will work on.
    • Top P: Top P signifies the cumulative probability threshold used in generating text with a language model like GPT-3. It determines which tokens are included in the output based on their probabilities. For example, setting Top P to 0.75 means that tokens with a cumulative probability above 0.75 are retained in the generated text.
    • Temperature: Controls the randomness of generated responses. Higher values (e.g., 0.8) result in more random outputs, while lower values (e.g., 0.2) yield more focused and deterministic responses.
    • Max Tokens: Specifies the maximum length of the generated output in terms of tokens, which includes words, punctuation, and other elements.

Step 5: Save and activate the Model

  • After completing the necessary information, click the Save button.

  • Once saved, open the tile again and click on activate, which enables the model by validating the details of the model.

  • Once activated, the model gets enabled in custom metadata under GPTfy card configurations.
  • A Green tick on the tile will be seen, visualizing that the model is activated.

By following these steps, you can successfully create an AI Model in GPTfy.

Sample Connector Class

Note: The sample code here is provided ‘as-is’ for reference and informational purposes only. You can refer to this to understand how the model can be authenticated using connector class.

				
					global class GPTfyopenAIConnector implements ccai.AIAuthenticationInterface{
global HttpRequest getAuthenticatedRequest(ccai__AI_Connection__c aiModel){
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:GPTfy/api/gptfyall');
return req;
}

				
			

Sample Processing Class

Note: The sample code here is provided ‘as-is’ for reference and informational purposes only. You can refer to this to understand how the model can be authenticated using the processing class.

				
					global class SampleAIProcessingClass implements ccai.AIProcessingInterface {
    
    global HttpResponse getProcessedResponse(ccai__AI_Connection__c aiModel, ccai__AI_Prompt__c aiPrompt, String promptCommand, String extractedData){
        
        String message = 'Human: '+promptCommand+' '+extractedData+' \nAssistant:';
        Map<String, Object> reqBodymap = new Map<String, Object>{
            'prompt' => message,
            'max_tokens_to_sample' => aiModel.ccai__Max_Tokens__c,
            'temperature' => aiModel.ccai__Temperature__c,
            'top_p' => aiModel.ccai__Top_P__c
        };
        String strBody = JSON.serialize(reqBodymap); 
        
        HttpRequest req = new HttpRequest();
        String endPoint = 'callout:AWSBedrock'+aiModel.ccai__EndPoint_URL__c;
        req.setEndpoint(endPoint);
        
        req.setMethod('POST');
        req.setTimeout(120000);
        req.setHeader('Content-Type', 'application/json');
        req.setHeader('Accept', 'application/json');
        req.setBody(strBody);
        Http api = new Http();
        HttpResponse response = api.send(req);

    return response;        
    }
    
}