Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maximerenou/php-pi-chat
PHP client for Pi.ai chatbot (Inflection AI)
https://github.com/maximerenou/php-pi-chat
ai chatbot inflection-ai pi
Last synced: about 2 months ago
JSON representation
PHP client for Pi.ai chatbot (Inflection AI)
- Host: GitHub
- URL: https://github.com/maximerenou/php-pi-chat
- Owner: maximerenou
- License: mit
- Created: 2023-05-04T21:21:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-24T21:15:01.000Z (10 months ago)
- Last Synced: 2024-04-25T06:42:53.538Z (9 months ago)
- Topics: ai, chatbot, inflection-ai, pi
- Language: PHP
- Homepage:
- Size: 331 KB
- Stars: 21
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pi chatbot client
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/MIT)
[![Latest Stable Version](https://img.shields.io/github/v/release/maximerenou/php-pi-chat)](https://packagist.org/packages/maximerenou/pi-chat)
[![PHP version](https://img.shields.io/packagist/dependency-v/maximerenou/pi-chat/php)](https://packagist.org/packages/maximerenou/pi-chat)
[![cURL extension required](https://img.shields.io/packagist/dependency-v/maximerenou/pi-chat/ext-curl)](https://packagist.org/packages/maximerenou/pi-chat)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](examples/demo.gif)
## Usage
```php
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:
```php
// $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:
```php
// 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.