inzanty / perspectiveapi
如果技术能够帮助提高在线对话,会怎么样?这是原始仓库stajor/perspectiveapi的分支。
dev-master
2023-07-16 16:58 UTC
Requires
- php: >=7.1
- ext-json: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- vlucas/phpdotenv: ^5.0
This package is auto-updated.
Last update: 2024-09-17 00:58:39 UTC
README
PHP库用于Perspective评论分析API。最小PHP版本为7.4。
安装
通过Composer
composer require inzanty/perspectiveapi
使用
评分评论:AnalyzeComment
<?php $commentsClient = new PerspectiveApi\CommentsClient('PERSPECTIVE-API-TOKEN'); $commentsClient->comment(['text' => 'What kind of idiot name is foo? Sorry, I like your name.']); $commentsClient->languages(['en']); $commentsClient->context(['entries' => ['text' => 'off-topic', 'type' => 'PLAIN_TEXT']]); $commentsClient->requestedAttributes(['TOXICITY' => ['scoreType' => 'PROBABILITY', 'scoreThreshold' => 0]]); // Analyze and get response $response = $commentsClient->analyze(); // Print scores print_r($response->attributeScores());
发送反馈:SuggestCommentScore
<?php $commentsClient = new PerspectiveApi\CommentsClient('PERSPECTIVE-API-TOKEN'); $commentsClient->comment(['text' => 'What kind of idiot name is foo? Sorry, I like your name.']); $commentsClient->languages(['en']); $commentsClient->context(['entries' => ['text' => 'off-topic', 'type' => 'PLAIN_TEXT']]); $commentsClient->clientToken('some-token'); $commentsClient->communityId('unit-test'); $commentsClient->attributeScores(['TOXICITY' => [ 'summaryScore' => ['value' => 0.83785176, 'type' => 'PROBABILITY'], 'spanScores' => [['begin' => 0, 'end' => 32, 'score' => ['value' => 0.9208521, 'type' => 'PROBABILITY']]]] ]); // Suggest Score and get response $response = $commentsClient->suggestScore(); // Print scores print_r($response->attributeScores());
贡献
欢迎在GitHub上提交错误报告和pull请求:https://github.com/inzanty/perspectiveapi。本项目旨在成为一个安全、欢迎的协作空间,并期望贡献者遵守贡献者公约的行为准则。
许可证
该软件作为开源软件,在MIT许可证的条款下提供。