maximerenou/pi-chat

此包最新版本(0.0.2)没有可用的许可证信息。

Pi 客户端

0.0.2 2024-03-21 21:48 UTC

This package is auto-updated.

Last update: 2024-09-24 22:30:27 UTC


README

License Latest Stable Version PHP version cURL extension required

这是一个非官方的PHP客户端,用于Pi聊天机器人(来自Inflection AI)。它不需要认证。

此包未积极维护,可能因Inflection AI的Cloudflare配置而不稳定。

此包仅限教育目的使用。使用风险自负。

安装

composer require maximerenou/pi-chat

演示

克隆此仓库,运行composer install,然后运行examples/chat.php进行测试。

Prompt Demo

用法

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"));
实时/渐进式回答

您可以将一个函数作为第二个参数传递以获取实时进度

// $current_answer - incomplete answer
// $tokens - last tokens received
$final_answer = $conversation->ask($prompt, function ($current_answer, $tokens) {
    echo $tokens;
});
恢复对话

如果您想恢复之前的对话,可以检索其标识符

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

// ...
// Resume conversation with $identifiers parameter
$conversation = $chatbot->resumeConversation($identifiers);
错误处理

当代码从Pi收到错误时,会抛出异常。因此,您可以使用try/catch块来处理错误。

免责声明

此代码仅用于教育目的。在pi.ai之外使用Pi可能违反Inflection AI条款。