adachsoft/internet-search-perplexity
最新稳定版本:v0.1.0
Composer 安装命令:
composer require adachsoft/internet-search-perplexity
包简介
Perplexity internet search client implementation for adachsoft/internet-search-contract.
README 文档
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
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-13