PHP code example of hbb / cmer-knowledge-base
1. Go to this page and download the library: Download hbb/cmer-knowledge-base library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hbb / cmer-knowledge-base example snippets
ey="xxxxxxxxxx"; # 授权码
$cmer = new \Hbb\CmerKnowledgeBase\CmerClient($apikey);
# 知识库索引
$index_name = "hbb-gpts";
# 新增知识库
$model = new \Hbb\CmerKnowledgeBase\models\CreateEmbeddingModel($index_name, "Q:你是谁?\n A:我是一个聊天机器人。");
$model->tag = "chatbot";
# 扩展字段
$model->meta = [
"cate" => "退款"
];
$response = $cmer->crud_create($model);
print_r($response->getBody()->getContents());
# 通过ES召回知识库
$model = new \Hbb\CmerKnowledgeBase\models\SelectEmbeddingEsModel($index_name, "你是谁");
$response = $cmer->crud_select_es($model);
$esdoc = json_decode($response->getBody()->getContents(), true);
print_r($esdoc);
# 通过向量召回知识库
$model = new \Hbb\CmerKnowledgeBase\models\SelectEmbeddingModel($index_name, "你是谁");
$response = $cmer->crud_select_vector($model);
$doc = json_decode($response->getBody()->getContents(), true);
print_r($doc);
# 修改知识库
$model = new \Hbb\CmerKnowledgeBase\models\UpdateEmbeddingModel($index_name, "Q:你是谁?\n A:我是一个聊天机器人。你呢?", $doc[0]["uuid"]);
$model->tag = '测试';
$model->meta = [
"cate" => "退款测试"
];
$response = $cmer->crud_update($model);
print_r($response->getBody()->getContents());