Yousuf / Chatman
Chatbot 是一个 PHP 库,它使用机器学习根据已知的对话集合生成响应。
v1.0.1
2024-04-08 13:31 UTC
Requires
- php: >=7.2
- php-ai/php-ml: ^0.9.0
- writecrow/lemmatizer: dev-master
This package is auto-updated.
Last update: 2024-09-08 14:42:39 UTC
README
Chatman 是一个基于机器学习的 PHP 聊天机器人库。它可以通过学习对话来生成响应。Chatman 非常易于使用。它可以用于生成社交媒体、客户支持、电子商务网站、个人娱乐等自动响应。
阅读 文档
安装
首先确保您的系统已安装 composer。
composer require yousuf/chatman
如果您遇到任何类似以下错误
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires yousuf/chatman ^1.0 -> satisfiable by yousuf/chatman[v1.0.0].
- yousuf/chatman v1.0.0 requires writecrow/lemmatizer dev-master -> found writecrow/lemmatizer[dev-master] but it does not match your minimum-stability.
然后运行以下命令
composer require writecrow/lemmatizer:dev-master
composer require yousuf/chatman
训练数据集
{ "intents": [ {"tag": "intro", "patterns": ["Hello", "Hi", "Hi there", "hey", "Whats up"], "responses": ["Hi, how can I help you ?", "Hey, do you need any help ?", "How are you doing?", "Greetings !"] }, {"tag": "age", "patterns": ["how old are you?", "can i know your age", "what is your age"], "responses": ["I am 19 years old", "My age is 19", "My birthday is Jan 5th and I was born in 2002, so I am 19 years old !"] }] }
示例代码
require_once __DIR__ . '/vendor/autoload.php'; use Chatman\BotWithPatterns; $bot = new BotWithPatterns("chatbot.json"); $bot->defaultMsg = "I did not understand !"; $bot->train(); $resp = $bot->getResponse("hello"); echo $resp['resp'];