sepehr-mohseni/exaravel
Composer 安装命令:
composer require sepehr-mohseni/exaravel
包简介
Laravel wrapper for the Exa.ai API
README 文档
README
A high-performance, strictly-typed, and enterprise-grade Laravel wrapper for the Exa.ai v2.1 API.
Features
- 🚀 PHP 8.2+ with Asymmetric Visibility and Property Hooks (PHP 8.4)
- 🔧 Fluent Builder Pattern for maximum IDE discoverability
- 🛡️ Strictly Typed DTOs - No raw arrays reach the end-user
- 🔄 Automatic Retries with exponential backoff for 429 and 5xx errors
- 📊 Laravel Context Integration for enterprise observability
- 🔑 Multi-Connection Support for managing multiple API keys
- ✅ PHPStan Level 9 compliant
Requirements
- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
Installation
composer require sepehr-mohseni/exaravel
Publish the configuration file:
php artisan vendor:publish --tag=exaravel-config
Add your API key to your .env file:
EXA_API_KEY=your-api-key-here
Usage
Search
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) ->includeDomains(['github.com', 'gitlab.com']) ->excludeDomains(['stackoverflow.com']) ->startPublishedDate('2024-01-01') ->endPublishedDate(new DateTime('now')) ->withContents(text: true, highlights: true) ->withAutoprompt() ->get(); // Iterate over results foreach ($results as $result) { echo $result->title . ' - ' . $result->url . PHP_EOL; } // Get first result directly $firstResult = Exa::search('PHP 8.4 features')->first();
Find Similar
// 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();
Get Contents
// 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 }
Answer (Agentic Endpoint)
// Get a direct answer with citations $response = Exa::answer('What are the new features in PHP 8.4?') ->numResults(5) ->neural() ->includeDomains(['php.net', 'wiki.php.net']) ->systemPrompt('You are a PHP expert. Provide detailed technical explanations.') ->get(); echo $response->answer; foreach ($response->citations as $citation) { echo "Source: {$citation->url}" . PHP_EOL; } // Get just the answer text $answerText = Exa::answer('Explain Laravel service providers')->text();
Working with Results
$results = Exa::search('Laravel packages')->get(); // Collection-like methods $urls = $results->urls(); $titles = $results->titles(); // Filter results $highScoring = $results->filter(fn ($result) => $result->score > 0.8); // Map results $summaries = $results->map(fn ($result) => [ 'title' => $result->title, 'url' => $result->url, ]); // Check results if ($results->isEmpty()) { echo 'No results found'; } echo "Found {$results->count()} results";
Multiple Connections
Configure multiple API keys in config/exaravel.php:
'connections' => [ 'default' => [ 'api_key' => env('EXA_API_KEY'), ], 'premium' => [ 'api_key' => env('EXA_PREMIUM_API_KEY'), 'timeout' => 60, ], ],
Use a specific connection:
$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();
Error Handling
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; }
Livecrawl Mode
use Sepehr_Mohseni\Exaravel\Enums\LivecrawlMode; $results = Exa::search('Latest tech news') ->livecrawl(LivecrawlMode::Always, timeout: 10000) ->get();
Configuration
// config/exaravel.php return [ 'api_key' => env('EXA_API_KEY'), 'base_url' => env('EXA_BASE_URL', 'https://api.exa.ai'), 'timeout' => env('EXA_TIMEOUT', 30), 'connect_timeout' => env('EXA_CONNECT_TIMEOUT', 10), 'retry' => [ 'times' => env('EXA_RETRY_TIMES', 3), 'sleep_milliseconds' => env('EXA_RETRY_SLEEP', 500), 'when' => [429, 500, 502, 503, 504], ], 'default_search_type' => env('EXA_DEFAULT_SEARCH_TYPE', 'auto'), 'default_num_results' => env('EXA_DEFAULT_NUM_RESULTS', 10), 'logging' => [ 'enabled' => env('EXA_LOGGING_ENABLED', false), 'channel' => env('EXA_LOGGING_CHANNEL', 'stack'), ], ];
Testing
composer test
Run static analysis:
composer analyse
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
sepehr-mohseni/exaravel 适用场景与选型建议
sepehr-mohseni/exaravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 183 次下载、GitHub Stars 达 3, 最近一次更新时间为 2026 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「search」 「laravel」 「exa」 「ai」 「web-search」 「semantic-search」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sepehr-mohseni/exaravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sepehr-mohseni/exaravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sepehr-mohseni/exaravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package to retrieve data from Google Search Console
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Abstraction Layer to index and search entities
Pimcore 10.x Website Indexer (powered by Zend Search Lucene)
Plug-and-play Laravel package exposing a single contract over Brave Search, Tavily, Exa.ai, Firecrawl, WebSearchAPI.ai and DuckDuckGo — the search/extraction backbone for AI agents and product/catalog tooling.
Symfony bundle for Elasticsearch integration with round-robin load balancing
统计信息
- 总下载量: 183
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-16