stajor/perspectiveapi

如果技术能够帮助改善在线对话,那会怎样?

2.0.0 2024-02-14 15:15 UTC

This package is auto-updated.

Last update: 2024-09-14 16:50:22 UTC


README

Minimal PHP version

PHP库,用于Perspective评论分析API。

安装

通过Composer

composer require stajor/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上提交错误报告和拉取请求:https://github.com/Stajor/perspectiveapi。此项目旨在为协作提供一个安全、欢迎的空间,贡献者应遵守贡献者公约行为准则。

许可证

此软件库在MIT许可证的条款下作为开源软件提供。