From 4056a7090e1ab761a4b3f003b7957fec67113c42 Mon Sep 17 00:00:00 2001 From: Maxime Renou Date: Sat, 29 Apr 2023 12:04:12 +0200 Subject: [PATCH] wip: stop generating --- README.md | 16 +++++++++++++++- src/Conversation.php | 13 +++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1dce35..af4e81c 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,21 @@ $summary = $conversation->getSummary(); // Result: Famous genius mathematician. ``` - + + +
+ Stop answer generation + +If HuggingChat is taking too much time to answer or starts writing too much, you can stop generation in a parallel process/request using this method: + +```php +// See "Resume a conversation" +$conversation = $ai->resumeChatConversation($identifiers); + +$conversation->stopGenerating(); +``` + +
Handle HuggingChat errors diff --git a/src/Conversation.php b/src/Conversation.php index 9f67233..6284491 100644 --- a/src/Conversation.php +++ b/src/Conversation.php @@ -184,4 +184,17 @@ public function getSummary() return trim($data['title'], '"'); } + + public function stopGenerating() + { + $headers = [ + 'method: POST', + 'accept: */*', + "referer: https://huggingface.co/chat/conversation/{$this->id}", + 'content-type: application/json', + "cookie: hf-chat={$this->cookie}" + ]; + + $data = Tools::request("https://huggingface.co/chat/conversation/{$this->id}/stop-generating", $headers, '', true); + } }