GithubHelp home page GithubHelp logo

pxpxltd / php-perplexity-ai-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from softcreatr/php-perplexity-ai-sdk

0.0 0.0 0.0 31 KB

A powerful and easy-to-use PHP SDK for the pplx API, allowing seamless integration of advanced AI-powered features into your PHP projects.

Home Page: https://docs.perplexity.ai

License: ISC License

PHP 100.00%

php-perplexity-ai-sdk's Introduction

PerplexityAI API Wrapper for PHP

Build Latest Release ISC licensed Plant Tree Codecov branch Code Climate maintainability

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
  • Utilizes PSR-17 and PSR-18 compliant HTTP clients, and factories for making API requests

Requirements

Installation

You can install the library via Composer:

composer require softcreatr/php-perplexity-ai-sdk

Usage

First, include the library in your project:

<?php

require_once 'vendor/autoload.php';

Then, create an instance of the PerplexityAI class with your API key, organization (optional), an HTTP client, an HTTP request factory, and an HTTP stream factory:

use SoftCreatR\PerplexityAI\PerplexityAI;

$apiKey = 'your_api_key';

// Replace these lines with your chosen PSR-17 and PSR-18 compatible HTTP client and factories
$httpClient = new YourChosenHttpClient();
$requestFactory = new YourChosenRequestFactory();
$streamFactory = new YourChosenStreamFactory();
$uriFactory = new YourChosenUriFactory();

$pplx = new PerplexityAI($requestFactory, $streamFactory, $uriFactory, $httpClient, $apiKey);

Now you can call any supported PerplexityAI API endpoint using the magic method __call:

$response = $pplx->createChatCompletion([
    'model' => 'mistral-7b-instruct',
    '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();
}

For more details on how to use each endpoint, refer to the PerplexityAI API documentation, and the examples provided in the repository.

Supported Methods

Chat Completions

Changelog

For a detailed list of changes and updates, please refer to the CHANGELOG.md file. We adhere to Semantic Versioning and document notable changes for each release.

Known Problems and limitations

Streaming Support

Currently, streaming is not supported. It's planned to address this limitation asap. For now, please be aware that these methods cannot be used for streaming purposes.

If you require streaming functionality, consider using an alternative implementation or keep an eye out for future updates to this library.

License

This library is licensed under the ISC License. See the LICENSE file for more information.

Maintainers 🛠️

Sascha Greuel
Sascha Greuel

Contributors ✨

php-perplexity-ai-sdk's People

Contributors

softcreatr avatar jamzy118 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.