How to set up LM Studio integration for P4 Code Review

To integrate LM Studio with P4 Code Review, follow these steps:

  1. Launch LM Studio.

  2. In LM Studio, download the AI model you want to use.

  3. In the Developer tab, select the relevant AI model and configure your server settings.

  4. To configure AI review integration for P4 Code Review, add the ai_review block configuration in SWARM_ROOT/data/config.php file, as in the following example:

    <?php
        'ai_review' => array(
             // Please read Perforce's Generative AI policy before enabling this feature.  
             // See https://www.perforce.com/generative-ai-policy 
             'enabled' => false, // set to true to enable the AI review feature
             'data_retention_lifetime' => '150 days',  // Delete AI summary records that are older than the
    					  	  // value provided. By default, this value is 30 days.
    						  // Enter a value in 'days' or 'months'.
    						  // For example, '30 days' or '2 months'.
    						  // A cron job is required to remove the
    						  // AI summaries on a schedule.
    						  // See Set up a cron job to delete AI summaries.	
            'timeout' => 500, // Setting timeout for the request sent from p4 code review to AI vendor 
                              //  Timeout set in seconds
            'ai_vendors' => array(
                'ai_model1' => array(
                    'ai_vendor'              => lmStudioAI', // Name of the AI provider being used
                    'ai_package_id'          => '1', // Ensure this remains as '1'. Do not modify the ai_package_id.
                    'ai_package_key'         => 'LMStudioPackage', // This is intended for future  
                                                                   // use when we will support
                                                                   // multiple models and have an 
                                                                   // AI configuration page in the UI.
                    'ai_package_value'       => 'AI LM Studio', // This is used to display 
                                                                // the model type in the
                                                                // summary of the
                                                                // AI vendor's response
                    'ai_package_type'        => "Explain the following code:", // This is the prompt for the AI.
                                                                               // You can modify the prompt  for
                                                                               // purposes other than explaining
                                                                               // the code, or to request the
                                                                               // output in a specific language.
                    'api_end_point'          => 'http://{LMStudioRunningHost}/v1/chat/completions',
                                                 // Replace {LMStudioRunningHos}t with your 
                                                 // LM Studio server IP address.
                    'ai_min_char_limit'      => 4, // Minimum number of characters required in the content
                                                   // submitted to the AI vendor for analysis.
                                                   // Defaults to 4 characters.
                    'ai_max_char_limit'      => 31000, // The maximum number of characters
                                                       // that can be submitted to the AI vendor for analysis
                                                       // Defaults to 31000 characters.
                ),
            ),
        ),

This setup will enable LM Studio to explain the diff code in your P4 Code Review.