1. Go to this page and download the library: Download sepehr-mohseni/exaravel 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/ */
sepehr-mohseni / exaravel example snippets
use Sepehr_Mohseni\Exaravel\Facades\Exa;
use Sepehr_Mohseni\Exaravel\Enums\SearchType;
use Sepehr_Mohseni\Exaravel\Enums\Category;
// Basic search
$results = Exa::search('Laravel best practices')->get();
// Advanced search with fluent builder
$results = Exa::search('Machine learning frameworks')
->type(SearchType::Neural)
->category(Category::GitHub)
->numResults(20)
->P 8.4 features')->first();
// Find content similar to a URL
$results = Exa::findSimilar('https://laravel.com/docs/eloquent')
->numResults(10)
->excludeSourceDomain()
->category(Category::ResearchPaper)
->withContents(text: true, summary: true)
->get();
// Retrieve full content for specific document IDs
$contents = Exa::contents(['doc-id-1', 'doc-id-2', 'doc-id-3'])
->withText(maxCharacters: 10000)
->withMarkdown()
->withHighlights(perUrl: 3)
->withSummary('What are the key points?')
->get();
foreach ($contents as $content) {
echo $content->title . PHP_EOL;
echo $content->getPreferredContent(); // Returns markdown if available, otherwise text
}
// Get a direct answer with citations
$response = Exa::answer('What are the new features in PHP 8.4?')
->numResults(5)
->neural()
->>citations as $citation) {
echo "Source: {$citation->url}" . PHP_EOL;
}
// Get just the answer text
$answerText = Exa::answer('Explain Laravel service providers')->text();
$results = Exa::using('premium')
->search('Complex query')
->get();
// Or use a custom API key on the fly
$results = Exa::withApiKey('custom-key')
->search('Query')
->get();
use Sepehr_Mohseni\Exaravel\Exceptions\AuthenticationException;
use Sepehr_Mohseni\Exaravel\Exceptions\RateLimitException;
use Sepehr_Mohseni\Exaravel\Exceptions\InsufficientCreditsException;
use Sepehr_Mohseni\Exaravel\Exceptions\ValidationException;
try {
$results = Exa::search('query')->get();
} catch (AuthenticationException $e) {
// Invalid API key
} catch (RateLimitException $e) {
// Rate limit exceeded
$retryAfter = $e->retryAfter; // seconds to wait
} catch (InsufficientCreditsException $e) {
// Need more API credits
} catch (ValidationException $e) {
// Invalid request parameters
$errors = $e->errors;
}