PHP code example of kolasai / clean-talk-php-client

1. Go to this page and download the library: Download kolasai/clean-talk-php-client 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/ */

    

kolasai / clean-talk-php-client example snippets


use CleanTalk\KolasAiOAuthClient;

$oauthClient = new KolasAiOAuthClient();
$authResult = $oauthClient->auth(YOUR_CLIENT_ID, YOUR_CLIENT_SECRET);

use CleanTalk\CleanTalkPredictionClient;
use CleanTalk\Request\Message;
use CleanTalk\Request\PredictRequest;

$client = new CleanTalkPredictionClient($authResult->getAccessToken());

$response = $client->predict(
    new PredictRequest(
        YOUR_PROJECT_ID,
        [
            new Message('11177c92-1266-4817-ace5-cda430481111', 'Hello world!'),
            new Message('22277c92-1266-4817-ace5-cda430482222', 'Good buy world!'),
        ]
    )
);

foreach ($response->getPredictions() as $prediction) {
echo "MessageId: {$prediction->getMessageId()}\n";
echo "Message: {$prediction->getMessage()}\n";
echo "Prediction: {$prediction->getPrediction()}\n";
echo "Probability: {$prediction->getProbability()}\n";
echo "Categories: " . implode(', ', $prediction->getCategories()) . "\n";

use CleanTalk\CleanTalkPredictionClient;
use CleanTalk\Request\Message;
use CleanTalk\Request\PredictRequest;

$client = new CleanTalkPredictionClient($authResult->getAccessToken());
$client->asyncPredict(new PredictRequest(
    YOUR_PROJECT_ID,
    [
        new Message('11177c92-1266-4817-ace5-cda430481111', 'Hello world!'),
        new Message('22277c92-1266-4817-ace5-cda430482222', 'Good buy world!'),
    ]
));
bash
composer