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/ */
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