maximerenou / php-hugging-chat

🚧 Deprecated 🚧 HuggingChat PHP client (OpenAssistant's LLaMA)
MIT License
18 stars 2 forks source link
ai chatbot huggingchat huggingface llama openassistant

HuggingChat + PHP

HuggingChat client

License Latest Stable Version PHP version cURL extension required

This is an unofficial PHP client for HuggingChat (OpenAssistant's LLaMA model).

HuggingChat API is evolving fast with recurring breaking changes. I try to keep up with it, but it may not always work as expected. Feel free to open an issue if you encounter any problem.

Installation

composer require maximerenou/hugging-chat

Demo

Run examples/chat.php to test it.

Prompt Demo

Usage

use MaximeRenou\HuggingChat\Client as HuggingChat;
use MaximeRenou\HuggingChat\Prompt;

$ai = new HuggingChat();

$conversation = $ai->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 = $ai->resumeConversation($identifiers); ```
Use another model You can use a specific model: ```php $conversation = $ai->createConversation("bigcode/starcoder"); ``` Default is OpenAssistant.
Generate a conversation's summary Useful to give a title to a conversation. ```php // Question asked: "Who's Einstein?" // ... $summary = $conversation->getSummary(); // Result: Famous genius mathematician. ```
Turn on/off data sharing HuggingChat share your conversations to improve the model. You can turn on/off data sharing: ```php $conversation->enableSharing(); // on $conversation->disableSharing(); // off (module default) ```
Delete a conversation ```php $conversation->delete(); ```
Handle HuggingChat errors The code throws exceptions when it receives an error from HuggingChat. You can therefore use a try/catch block to handle errors.
Answers are sometimes malformed (or dumb) Answers quality depends on the model you're using.

Disclaimer

Using HuggingChat outside huggingface.co/chat may violate HuggingFace terms. Use it at your own risk.