Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

WIP: Stop answer generation #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,21 @@ $summary = $conversation->getSummary();
// Result: Famous genius mathematician.
```

</details>
</details>

<details>
<summary>Stop answer generation</summary>

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();
```

</details>

<details>
<summary>Handle HuggingChat errors</summary>
Expand Down
13 changes: 13 additions & 0 deletions src/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}