maximerenou/hugging-chat

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v0.5.2) of this package.

HuggingChat client

v0.5.2 2023-05-05 10:16 UTC

This package is auto-updated.

Last update: 2024-04-05 12:31:37 UTC


README

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:

// $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 = $ai->resumeConversation($identifiers);
Use another model

You can use a specific model:

$conversation = $ai->createConversation("bigcode/starcoder");

Default is OpenAssistant.

Generate a conversation's summary

Useful to give a title to a conversation.

// 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:

$conversation->enableSharing(); // on

$conversation->disableSharing(); // off (module default)
Delete a conversation
$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.