maximerenou / hugging-chat
该软件包已被弃用,不再维护。未建议替代软件包。
关于该软件包的最新版本(v0.5.2)没有可用的许可信息。
HuggingChat客户端
v0.5.2
2023-05-05 10:16 UTC
Requires
- php: >=7.1
- ext-curl: *
- eislambey/eventsource: ^0.1.0
README
HuggingChat客户端
这是一个非官方的PHP客户端,用于HuggingChat(OpenAssistant的LLaMA模型)。
HuggingChat API 正在快速发展,频繁出现破坏性变更。我会尽力跟上,但它可能不会始终按预期工作。如果您遇到任何问题,请随时提交问题。
安装
composer require maximerenou/hugging-chat
演示
运行examples/chat.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"));
实时/渐进式回答
您可以将一个函数作为第二个参数传递,以获取实时进度
// $current_answer - incomplete answer // $tokens - last tokens received $final_answer = $conversation->ask($prompt, function ($current_answer, $tokens) { echo $tokens; });
恢复对话
如果您想恢复之前的对话,可以检索其标识符
// Get current identifiers $identifiers = $conversation->getIdentifiers(); // ... // Resume conversation with $identifiers parameter $conversation = $ai->resumeConversation($identifiers);
使用另一个模型
您可以使用特定的模型
$conversation = $ai->createConversation("bigcode/starcoder");
默认为OpenAssistant。
生成对话摘要
用于为对话添加标题。
// Question asked: "Who's Einstein?" // ... $summary = $conversation->getSummary(); // Result: Famous genius mathematician.
开启/关闭数据共享
HuggingChat会将您的对话分享以提高模型。您可以开启/关闭数据共享
$conversation->enableSharing(); // on $conversation->disableSharing(); // off (module default)
删除对话
$conversation->delete();
处理HuggingChat错误
代码在接收到HuggingChat的错误时会抛出异常。因此,您可以使用try/catch块来处理错误。
有时答案格式不正确(或愚蠢)
答案质量取决于您使用的模型。
免责声明
在huggingface.co/chat之外使用HuggingChat可能违反HuggingFace条款。请自行承担风险使用。