bahasaai/klasifikasi-php
v0.0.1
2020-12-16 02:46 UTC
Requires
- guzzlehttp/guzzle: ^7.2
This package is not auto-updated.
Last update: 2024-10-03 18:52:35 UTC
README
官方 Klasifikasi API 客户端库
要求
- PHP >= 7.2.5
安装
使用 composer 安装 klasifikasi-php
composer require bahasaai/klasifikasi-php
快速开始
您需要一个有效的模型 clientId 和 clientSecret。您可以从模型页面凭证部分获取这些信息,这些信息对于每个模型是唯一的。
use klasifikasi\Klasifikasi; $klasifikasiInstance = Klasifikasi::build([ [ 'clientId' => 'client-id-1', 'clientSecret' => 'client-id-2' ] ]);
您也可以传递多个 clientId 和 clientSecret
$klasifikasiInstance = Klasifikasi::build([ [ 'clientId' => 'client-id-1', 'clientSecret' => 'client-secret-1' ], [ 'clientId' => 'client-id-2', 'clientSecret' => 'client-secret-2' ] ]);
分类
您需要模型的 publicId 才能开始使用模型进行分类。您可以从模型页面获取模型的 publicId,或者从这里获取。
foreach ($klasifikasiInstance->getModels() as $publicId => $model) { echo $publicId; }
分类示例
$result = $publicId->classify('publicId', 'query'); /** * $result example = array[ * 'result' => array[ * [ * 'label' => 'tag 1', * 'score' => 0.53 * ], * [ * 'label' => 'tag 2', * 'score' => 0.23 * ] * ] * ] */
日志
您可以根据模型的 publicId 获取分类日志。
$startedAtString = '10 December 2020'; $endedAtString = '16 December 2020'; $logs = $instance->logs('publicId', [ 'startedAt' => new DateTime($startedAtString), 'endedAt' => new DateTime($endedAtString), 'take' => 10 'skip' => 1 ]); /** * $logs example = array[ * 'histories' => array[ * [ * 'id' => 1, * 'createdAt' => '2020-12-15T11:13:12+07:00', * 'query' => 'query', * 'modelResult' => array[ * [ * 'label' => 'tag 1', * 'score' => 0.53 * ], * [ * 'label' => 'tag 2', * 'score' => 0.23 * ] * ] * ], * ... * ], * 'length' => int * ] */
错误
如果发生错误,上述所有功能都会抛出异常。请始终在每个函数内部运行 try 和 catch 块。