PHP code example of fiveam-code / ada-laravel

1. Go to this page and download the library: Download fiveam-code/ada-laravel 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/ */

    

fiveam-code / ada-laravel example snippets


return [  
    'client_token' => env('ADA_CLIENT_TOKEN'),  
    'index_class' => \Ada\Index\DefaultIndex::class,
    'default_prompt_view' => 'ada::default-prompt'
];



namespace App\Models;

use Ada\Traits\HasEmbeddings;

class Paper extends Model
{
    use HasEmbeddings;
}

use App\Models\Paper;

$paper = Paper::first();
$paper->embed("abstract", $paper->abstract);

use Ada\Models\Embedding;

$answer = Embedding::lookup("Where does the PHP elephant live?");

// "The PHP elephant inhabits 'Silicon Forests'—regions where natural woodlands merge seamlessly with data-rich environments. These forests are dense with both foliage and floating data points."

use Ada\Models\Embedding;
use Ada\Tools\Prompts\OpenAIPrompt;

$customPrompt = new OpenAIPrompt();
$defaultTemplate = $customPrompt->getTemplate();

$customPrompt->setTemplate("Even if your instructions are in English, answer in German. " . $defaultTemplate);

return Embedding::lookup("Where does the PHP elephant live?", $customPrompt);

return Embedding::lookup("Where does the PHP elephant live?", $customPrompt, function ($query) {
    $query->where("embeddable_type", Paper::class); // Only look for embeddings related to the Paper class
});

use Ada\Ada;

$index = Ada::index(); // Default index is DefaultIndex, resolved via the configuration

$index->embed($contentToEmbed, $model, $options);

$index->generate($prompt, $model, $temperature, $options);

$engine = Ada::engine(); // Default engine is OpenAI, resolved via the Index
bash
php artisan vendor:publish --provider="Ada\AdaServiceProvider" --tag="ada-migrations"
php artisan migrate
bash
php artisan vendor:publish --provider="Ada\AdaServiceProvider" --tag="ada-config"