Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maximerenou/php-hugging-chat
🚧 Deprecated 🚧 HuggingChat PHP client (OpenAssistant's LLaMA)
https://github.com/maximerenou/php-hugging-chat
ai chatbot huggingchat huggingface llama openassistant
Last synced: 6 days ago
JSON representation
🚧 Deprecated 🚧 HuggingChat PHP client (OpenAssistant's LLaMA)
- Host: GitHub
- URL: https://github.com/maximerenou/php-hugging-chat
- Owner: maximerenou
- License: mit
- Archived: true
- Created: 2023-04-26T16:31:28.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-05T10:18:26.000Z (over 1 year ago)
- Last Synced: 2025-01-12T04:35:42.423Z (14 days ago)
- Topics: ai, chatbot, huggingchat, huggingface, llama, openassistant
- Language: PHP
- Homepage:
- Size: 84 KB
- Stars: 17
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![HuggingChat + PHP](logo.png)
# HuggingChat 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-hugging-chat)](https://packagist.org/packages/maximerenou/hugging-chat)
[![PHP version](https://img.shields.io/packagist/dependency-v/maximerenou/hugging-chat/php)](https://packagist.org/packages/maximerenou/hugging-chat)
[![cURL extension required](https://img.shields.io/packagist/dependency-v/maximerenou/hugging-chat/ext-curl)](https://packagist.org/packages/maximerenou/hugging-chat)This is an unofficial PHP client for **HuggingChat** (OpenAssistant's LLaMA model).
> HuggingChat API [is evolving fast](https://huggingface.co/spaces/huggingchat/chat-ui/commits/main) 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](examples/demo.gif)
## Usage
```php
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.