Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/softcreatr/php-perplexity-ai-sdk
A powerful and easy-to-use PHP SDK for the pplx API, allowing seamless integration of advanced AI-powered features into your PHP projects.
https://github.com/softcreatr/php-perplexity-ai-sdk
ai api api-client api-wrapper artificial-intelligence gpt gpt-3 gpt-4 hacktoberfest llama machine-learning mistral natural-language-processing nlp perplexity php pplx replit sdk
Last synced: 19 days ago
JSON representation
A powerful and easy-to-use PHP SDK for the pplx API, allowing seamless integration of advanced AI-powered features into your PHP projects.
- Host: GitHub
- URL: https://github.com/softcreatr/php-perplexity-ai-sdk
- Owner: SoftCreatR
- License: isc
- Created: 2023-10-19T06:10:41.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-17T21:24:44.000Z (2 months ago)
- Last Synced: 2024-11-22T09:26:27.020Z (about 1 month ago)
- Topics: ai, api, api-client, api-wrapper, artificial-intelligence, gpt, gpt-3, gpt-4, hacktoberfest, llama, machine-learning, mistral, natural-language-processing, nlp, perplexity, php, pplx, replit, sdk
- Language: PHP
- Homepage: https://docs.perplexity.ai
- Size: 43 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# PerplexityAI API Wrapper for PHP
[![Build](https://img.shields.io/github/actions/workflow/status/SoftCreatR/php-perplexity-ai-sdk/.github/workflows/create-release.yml?branch=main)](https://github.com/SoftCreatR/php-perplexity-ai-sdk/actions/workflows/create-release.yml) [![Latest Release](https://img.shields.io/packagist/v/SoftCreatR/php-perplexity-ai-sdk?color=blue&label=Latest%20Release)](https://packagist.org/packages/softcreatr/php-perplexity-ai-sdk) [![ISC licensed](https://img.shields.io/badge/license-ISC-blue.svg)](./LICENSE.md) [![Plant Tree](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Plant%20Tree&query=%24.total&url=https%3A%2F%2Fpublic.offset.earth%2Fusers%2Fsoftcreatr%2Ftrees)](https://ecologi.com/softcreatr?r=61212ab3fc69b8eb8a2014f4) [![Codecov branch](https://img.shields.io/codecov/c/github/SoftCreatR/php-perplexity-ai-sdk)](https://codecov.io/gh/SoftCreatR/php-perplexity-ai-sdk) [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/SoftCreatR/php-perplexity-ai-sdk)](https://codeclimate.com/github/SoftCreatR/php-perplexity-ai-sdk)
This PHP library provides a simple wrapper for the PerplexityAI API, allowing you to easily integrate the PerplexityAI API into your PHP projects.
## Features
- Easy integration with PerplexityAI API
- Supports all PerplexityAI API endpoints
- Streaming support for real-time responses in chat completions
- Utilizes PSR-17 and PSR-18 compliant HTTP clients and factories for making API requests## Requirements
- PHP 8.1 or higher
- A PSR-17 HTTP Factory implementation (e.g., [guzzle/psr7](https://github.com/guzzle/psr7) or [nyholm/psr7](https://github.com/Nyholm/psr7))
- A PSR-18 HTTP Client implementation (e.g., [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) or [symfony/http-client](https://github.com/symfony/http-client))## Installation
You can install the library via [Composer](https://getcomposer.org/):
```bash
composer require softcreatr/php-perplexity-ai-sdk
```## Usage
First, include the library in your project:
```php
createChatCompletion([
'model' => 'llama-3.1-sonar-small-128k-online',
'messages' => [
[
'role' => 'system',
'content' => 'Be precise and concise.'
],
[
'role' => 'user',
'content' => 'How many stars are there in our galaxy?'
]
],
]);// Process the API response
if ($response->getStatusCode() === 200) {
$responseObj = json_decode($response->getBody()->getContents(), true);
print_r($responseObj);
} else {
echo "Error: " . $response->getStatusCode();
}
```### Streaming Example
You can enable real-time streaming for chat completions:
```php
$streamCallback = static function ($data) {
if (isset($data['choices'][0]['delta']['content'])) {
echo $data['choices'][0]['delta']['content'];
}
};$pplx->createChatCompletion(
[
'model' => 'llama-3.1-sonar-small-128k-online',
'messages' => [
[
'role' => 'user',
'content' => 'Tell me a story about a brave knight.',
],
],
'stream' => true,
],
$streamCallback
);
```For more details on how to use each endpoint, refer to the [PerplexityAI API documentation](https://docs.perplexity.ai/reference), and the [examples](https://github.com/SoftCreatR/php-perplexity-ai-sdk/tree/main/examples) provided in the repository.
## Supported Methods
### Chat Completions
- [Create Chat Completion](https://docs.perplexity.ai/api-reference/chat-completions) - [Example](https://github.com/SoftCreatR/php-perplexity-ai-sdk/blob/main/examples/chat/createChatCompletion.php)
- `createChatCompletion(array $options = [])`## Changelog
For a detailed list of changes and updates, please refer to the [CHANGELOG.md](https://github.com/SoftCreatR/php-perplexity-ai-sdk/blob/main/CHANGELOG.md) file. We adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and document notable changes for each release.
## Known Problems and limitations
### Streaming Support
Streaming is now supported for real-time token generation in chat completions. Please make sure you are handling streams correctly using a callback, as demonstrated in the examples.
## License
This library is licensed under the ISC License. See the [LICENSE](https://github.com/SoftCreatR/php-perplexity-ai-sdk/blob/main/LICENSE.md) file for more information.
## Maintainers 🛠️
## Contributors ✨