maximerenou/pi-chat

There is no license information available for the latest version (0.0.2) of this package.

Pi client

0.0.2 2024-03-21 21:48 UTC

This package is auto-updated.

Last update: 2024-10-24 22:44:00 UTC


README

License Latest Stable Version PHP version cURL extension required

This is an unofficial PHP client for Pi chatbot (from Inflection AI). It doesn't require authentication.

This package isn't actively maintained and may be unstable due to Inflection AI's Cloudflare configuration.

This package is stricly meant for educational purpose. Use at your own risks.

Installation

composer require maximerenou/pi-chat

Demo

Clone this repo, run composer install and run examples/chat.php to test it.

Prompt Demo

Usage

use MaximeRenou\PiChat\Client as PiChat;
use MaximeRenou\PiChat\Prompt;

$chatbot = new PiChat();

$conversation = $chatbot->createConversation();

// $answer - full answer
$answer = $conversation->ask(new Prompt("Hello World"));
Real-time / progressive answer

You may pass a function as second argument to get real-time progression:

// $current_answer - incomplete answer
// $tokens - last tokens received
$final_answer = $conversation->ask($prompt, function ($current_answer, $tokens) {
    echo $tokens;
});
Resume a conversation

If you want to resume a previous conversation, you can retrieve its identifiers:

// Get current identifiers
$identifiers = $conversation->getIdentifiers();

// ...
// Resume conversation with $identifiers parameter
$conversation = $chatbot->resumeConversation($identifiers);
Error handling

The code throws exceptions when it receives an error from Pi. You can therefore use a try/catch block to handle errors.

Disclaimer

This code is for educational purpose only. Using Pi outside pi.ai may violate Inflection AI terms.