symfony/ai-perplexity-platform
Symfony AI bridge for the Perplexity Platform. Provides integration with Perplexity’s Sonar chat completions API for building AI chat experiences in Symfony apps, with links to Perplexity docs and contribution resources.
Message, ModelClient, DeltaInterface). This introduces architectural friction unless abstracted via adapters like spatie/laravel-symfony-support. Laravel’s native HTTP client (Guzzle) and DI system will need custom facades or service providers to interface with Symfony’s HttpClient and AI components.DeltaInterface for streaming responses is ideal for real-time use cases (e.g., chatbots, live content generation). However, Laravel’s synchronous request/response cycle may struggle with Symfony’s streaming format, necessitating custom queue workers (e.g., Swoole, ReactPHP) or event-driven processing.HttpClient vs. Laravel HttpClient (Guzzle): Requires a bridge layer (e.g., symfony/http-client-guzzle) to avoid duplicating middleware (retries, authentication). Alternatively, a custom facade can wrap Symfony’s HttpClient for Laravel compatibility..env or Vault can store PERPLEXITY_API_KEY, but Symfony’s HttpClient may need custom authentication plugins for Perplexity’s API (e.g., Bearer tokens).ramsey/uuid for Symfony’s Uuid).Message, ModelClient) that may conflict with existing Laravel AI logic.ApiError to Laravel’s HttpResponse or ProblemDetail.DeltaInterface): Laravel’s synchronous request/response cycle may struggle with asynchronous Symfony streams, requiring custom queue workers or event-driven processing to avoid blocking requests.HttpClient, AI\Message, or Provider abstractions may complicate future migrations to non-Symfony stacks or custom Laravel AI solutions.php-ai/perplexity or a custom Guzzle wrapper)?HttpClient (e.g., retries, middleware) without performance penalties?DeltaInterface streaming integrate with Laravel’s queue system (e.g., sync:flush, Swoole) for real-time use cases?symfony/rate-limiter vs. custom middleware)?503, 429) trigger fallback providers (e.g., OpenAI) in Laravel’s circuit breaker or retry logic?laravel-ai, ai-sdk) that could reduce Symfony dependency?spatie/laravel-symfony-support to bridge DI containers and symfony/http-client-guzzle to unify HTTP clients. This minimizes boilerplate and ensures middleware (retries, auth) is shared between Symfony and Laravel.PerplexityClient with Guzzle interop:
$this->app->bind(\App\Services\PerplexityService::class, function ($app) {
$httpClient = \Symfony\Contracts\HttpClient\HttpClient::create([
'base_uri' => 'https://api.perplexity.ai',
'auth_bearer' => $app['config']['perplexity.api_key'],
'plugins' => [
new \Symfony\Contracts\HttpClient\Plugin\RetryPlugin(),
],
]);
return new \App\Services\PerplexityService(
new \Symfony\AI\Perplexity\PerplexityClient($httpClient, 'sonar')
);
});
schedule:run to batch Perplexity calls (e.g., nightly content generation) with queue workers for async processing.MessageCreated) to Laravel’s events system for reactive workflows:
$client->chat([...], function ($response) {
event(new \App\Events\AIResponseGenerated($response));
});
Phase 1: Dependency Setup
composer require symfony/ai-perplexity-platform symfony/ai-platform symfony/http-client spatie/laravel-symfony-support
.env:
PERPLEXITY_API_KEY=your_key_here
SYMFONY_HTTP_CLIENT_PLUGINS='[{"id":"retry","enabled":true}]'
spatie/laravel-symfony-support):
php artisan vendor:publish --provider="Spatie\SymfonySupport\SymfonySupportServiceProvider"
Phase 2: Service Integration
PerplexityClient to simplify usage:
// app/Facades/Perplexity.php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Perplexity extends Facade {
protected static function getFacadeAccessor() {
return \App\Services\PerplexityService::class;
}
}
// app/Providers/PerplexityServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class PerplexityServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton(\App\Services\PerplexityService::class, function ($app) {
$httpClient = \Symfony\Contracts\HttpClient\HttpClient::create([
How can I help you explore Laravel packages today?