PHP code example of vaersaagod / aimate

1. Go to this page and download the library: Download vaersaagod/aimate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vaersaagod / aimate example snippets




use craft\helpers\App;

return [
    'openAIApiKey' => App::env('OPENAI_API_KEY'),
];

'prompts' => [
    'improveWriting' => [
        'handle'   => 'improveWriting',      // plate' => 'Improve the writing of the following text, keeping its meaning: <text>', //              // int, or false for no limit
        'maxWordsMultiplier' => 1.5,
        'sites'       => ['default'],         // limit the prompt to certain sites
        'rules'       => [],                  // extra instructions passed to the model
    ],
],

'fields' => [
    '*'            => true,   // default for every field
    'internalNote' => false,  // …except this one
],

use vaersaagod\aimate\AIMate;

$asset = \craft\elements\Asset::find()->kind('image')->one();
$service = AIMate::getInstance()->asset;

// Generate + save alt text (returns bool)
$service->generateAltTextForAsset($asset);

// Detect + save a focal point, clearing transforms (returns bool)
$service->getFocalPointForAsset($asset);

// Generate keywords — returned, not saved (returns ?array)
$keywords = $service->getKeywordsForAsset($asset, maxKeywords: 20, language: 'en', existingKeywords: []);

// Everything in one vision call — returned, not saved
$result = $service->analyzeImage($asset, 

use yii\base\Event;
use vaersaagod\aimate\helpers\CpHelper;
use vaersaagod\aimate\events\DefineAiActionsEvent;

Event::on(
    CpHelper::class,
    CpHelper::EVENT_DEFINE_ELEMENT_ACTIONS,
    static function (DefineAiActionsEvent $event) {
        // $event->element is the element the menu is being built for
        $event->actions[] = [
            'label' => 'My custom AI action',
            'attributes' => ['data-my-action' => '1'],
        ];
    }
);
bash
composer ugin/install _aimate
bash
# Generate alt text for image assets
php craft _aimate/asset/alt-text  [--volume=<handle>] [--site=<handle>] [--assetId=<id>] [--onlyEmpty=1]

# Generate focal points for image assets
php craft _aimate/asset/focal-point [--volume=<handle>] [--site=<handle>] [--assetId=<id>] [--onlyEmpty=1]