adachsoft / internet-search-perplexity
Perplexity internet search client implementation for adachsoft/internet-search-contract.
Installs: 2
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/adachsoft/internet-search-perplexity
Requires
- adachsoft/internet-search-contract: 0.1.0
- guzzlehttp/guzzle: 7.10.0
Requires (Dev)
- adachsoft/php-code-style: 0.3.0
- friendsofphp/php-cs-fixer: ^3.89
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^12.4
- rector/rector: ^2.3.3
- vlucas/phpdotenv: ^5.6
This package is not auto-updated.
Last update: 2026-02-14 16:36:07 UTC
README
Perplexity internet search client implementation for the adachsoft/internet-search-contract.
This library provides a thin adapter around the Perplexity AI HTTP API using Guzzle and exposes it via the shared InternetSearchClientInterface.
Requirements
- PHP 8.3 or higher
adachsoft/internet-search-contractguzzlehttp/guzzle7.10.0
Installation
composer require adachsoft/internet-search-perplexity
This will also install adachsoft/internet-search-contract and guzzlehttp/guzzle as required dependencies.
Usage
<?php
declare(strict_types=1);
use AdachSoft\InternetSearchContract\InternetSearchClientInterface;
use AdachSoft\InternetSearchPerplexity\Adapter\GuzzleHttpClientAdapter;
use AdachSoft\InternetSearchPerplexity\InternetSearchApiClient;
use GuzzleHttp\Client as GuzzleClient;
$guzzleClient = new GuzzleClient();
$httpAdapter = new GuzzleHttpClientAdapter($guzzleClient);
$apiKey = getenv('PERPLEXITY_KEY') ?: '';
/** @var InternetSearchClientInterface $client */
$client = new InternetSearchApiClient($httpAdapter, $apiKey, 'sonar');
$result = $client->search('What is the capital of France?');
echo $result . PHP_EOL;
Custom options
The search() method accepts an optional second argument with options:
model(string) c�b4 Perplexity model name (e.g.sonar,sonar-pro).system_prompt(string) c�b4 custom system message to control the answer style.
Example:
$result = $client->search('Explain quantum computing in simple terms', [
'model' => 'sonar-pro',
'system_prompt' => 'You are a programming expert. Provide technical but concise answers.',
]);
Testing
This library ships with a full PHPUnit test suite:
- unit tests for the HTTP adapter and exception classes,
- unit tests for the Perplexity API client,
- an optional production test that can call the real Perplexity API when
PERPLEXITY_KEYis set.
Run tests with:
composer test
(Or directly via vendor/bin/phpunit if you prefer.)
Code style and static analysis
The project uses adachsoft/php-code-style as a shared configuration for:
- PHP-CS-Fixer,
- PHPStan,
- Rector.
You can run the tools using your local Composer scripts, for example:
composer cs:check
composer cs:fix
composer stan
composer rector