PHP code example of partitech / php-tei-client

1. Go to this page and download the library: Download partitech/php-tei-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/ */

    

partitech / php-tei-client example snippets




use Partitech\PhpTeiClient\TeiClient;

$client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey');

// Embed a single string
$result = $client->embed(content: 'What is Deep Learning?');

// Embed an array of strings
$contents = ['What is Deep Learning?', 'What is Machine Learning?'];
$result = $client->embed(content: $contents);

Array
(
    [0] => Array
        (
            [0] => 0.007737029
            [1] => -0.06754478
            [2] => -0.0380035
-----
            [1023] => 0.026126498
        )

)



use Partitech\PhpTeiClient\TeiClient;

$client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey');


// Rerank an array of texts based on a query
$content = ['Deep learning is...', 'cheese is made of', 'Deep Learning is not...'];
$result = $client->rerank('What is the difference between Deep Learning and Machine Learning?', $content);

Array
(
    [0] => Array
        (
            [index] => 0
            [score] => 0.94238955
        )

    [1] => Array
        (
            [index] => 2
            [score] => 0.120219156
        )

    [2] => Array
        (
            [index] => 1
            [score] => 3.7323738E-5
        )

)




use Partitech\PhpTeiClient\TeiClient;

$client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey');


// Rerank an array of texts based on a query
$content = ['Deep learning is...', 'cheese is made of', 'Deep Learning is not...'];
$result = $client->getRerankedContent('What is the difference between Deep Learning and Machine Learning?', $content);
 
Array
(
    [0] => Array
        (
            [index] => 0
            [score] => 0.94238955
            [content] => Deep learning is...
        )

    [1] => Array
        (
            [index] => 2
            [score] => 0.120219156
            [content] => Deep Learning is not...
        )

)




use Partitech\PhpTeiClient\TeiClient;

$client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey');

// Predict the sentiment of a string
$result = $client->predict('I love this product!');
 
Array
(
    [0] => Array
        (
            [score] => 0.986059
            [label] => love
        )

    [1] => Array
        (
            [score] => 0.006502793
            [label] => admiration
        )

    [2] => Array
        (
            [score] => 0.0020027023
            [label] => approval
        )

    [3] => Array
        (
            [score] => 0.0008381181
            [label] => neutral
        )

    [4] => Array
        (
            [score] => 0.0005737838
            [label] => joy
        )
---------

    [27] => Array
        (
            [score] => 2.2074879E-5
            [label] => grief
        )

)




use Partitech\PhpTeiClient\TeiClient;

$client = new TeiClient(url: 'http://localhost:8080', apiKey: 'yourApiKey');
$result = $client->embedSparse(content: 'What is Deep Learning?');

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [index] => 1012
                    [value] => 1.0751953
                )

            [1] => Array
                (
                    [index] => 2003
                    [value] => 1.5722656
                )

            [2] => Array
                (
                    [index] => 2784
                    [value] => 2.9082031
                )

            [3] => Array
                (
                    [index] => 4083
                    [value] => 2.7929688
                )

        )

)

bash
composer