Download the PHP package compredict/ai-sdk without Composer

On this page you can find all versions of the php package compredict/ai-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ai-sdk

COMPREDICT's AI CORE API Client

Latest Version on Packagist GitHub Tests Action Status Total Downloads

PHP client for connecting to the COMPREDICT V1 REST API.

To find out more, visit the official documentation website: https://compredict.de

Requirements

To connect to the API with basic auth you need the following:

Installation

Use the following Composer command to install the API client from the COMPREDICT vendor on Packagist:

 $ composer require compredict/ai-sdk
 $ composer update

Namespace

All the examples below assume the Compredict\API\Client class is imported into the scope with the following namespace declaration:

use Compredict\API\Algorithms\Client as Compredict;

Configuration

To use the API client in your PHP code, ensure that you can access Compredict\API in your autoload path (using Composer’s vendor/autoload.php hook is recommended).

Provide your credentials to the static configuration hook to prepare the API client for connecting to a store on the COMPREDICT platform:

Basic Auth

$compredict_client = Compredict::getInstance(
    'Your-token',
    'Your-callback-url',  //optional
    'path-to-ppk',  //optional
    'passphrase-of-the-ppk'  //optional
);

Accessing Algorithms (GET)

To list all the algorithms in a collection:

$algorithms = $compredict_client->getAlgorithms();

foreach ($algorithms as $algorithm) {
    echo $algorithm->name;
    var_dump($algorithm->getTemplate());
}

To access a single algorithm:

$algorithm = $compredict_client->getAlgorithm('ecolife');

echo $algorithm->name;
echo $algorithm->description;

Algorithm Prediction (POST)

Some resources support creation of new items by posting to the collection. This can be done by passing an array or stdClass object representing the new resource to the global create method:

// pass as array
$X_test = [
    "feature_1" => [1, 2, 3, 4], 
    "feature_2" => [2, 3, 4, 5]
];

$algorithm = $compredict_client->getAlgorithm('algorithm_id');
$result = $algorithm->predict($X_test);

// pass as file_path
$X_test = "/path/to/file.parquet";

$algorithm = $compredict_client->getAlgorithm('algorithm_id');
$result = $algorithm->predict($X_test, file_content_type="application/parquet");

Depending on the algorithm's computation requirement, the result can be:

You can identify when the algorithm dispatches the processing to queue or send the results instantly by:

echo $algorithm->getResponseTime();

or dynamically:

$result = $algorithm->predict($X_test, $evaluate="True");

if($result instanceof Compredict\API\Algorithms\Resources\Task){
    echo $result->getCurrentStatus();
    while($result->getCurrentStatus() != Compredict\API\Algorithms\Resources\Task::STATUS_FINISHED){
        sleep("3"); # wait some time.
        $result->update(); // check Compredict for updated results.
    }
    echo $result->success;
    var_dump($result->predictions);
}

If you set up callback_url then the results will be POSTed automatically to you once the calculation is finished.

Each algorithm has its own evaluation methods that are used to evaluate the performance of the algorithm given the data. You can identify the evaluation metric by calling:

$algorithm->evaluations;  // associative array.

When running the algorithm, with evaluate = True, then the algorithm will be evaluated by the default parameters. In order to tweek these parameters, you have to specify an associative array with the modified parameters. For example:

$evaluate = [];
$evaluate['rainflow-counting'] = [];  // name of the evaluation method
$evaluate['rainflow-counting']["hysteresis"] = 0.2;  // evaluation method parameter 1
$evaluate['rainflow-counting']["N"] = 0.2;  // evaluation method parameter 2

$result = $algorithm->predict(X_test, evaluate=$evaluate);

Data Privacy

When the calculation is queued in COMPREDICT, the result of the calculations will be stored temporarily for three days. If the data is private and there are organizational issues in keeping this data stored in COMPREDICT, then you can encrypt the data using RSA. COMPREDICT allow user's to add RSA public key in the Dashboard. Then, COMPREDICT will use the public key to encrypt the stored results. In return, The SDK will use the provided private key to decrypt the returned results.

COMPREDICT will only encrypt the results when:

Here is an example:

// First, you should provide public key in COMPREDICT's dashboard.

// Second, Call predict and set encrypt as True
$result = $algorithm->predict($X_test, $evaluate=True, $encrypt=True);

if($result instanceof Compredict\API\Algorithms\Resources\Task){
    echo $result->getCurrentStatus();
    while($result->getCurrentStatus() != Compredict\API\Algorithms\Resources\Task::STATUS_FINISHED){
        sleep("10"); # wait some time.
        $result->update(); // check Compredict for updated results.
    }
    echo $result->is_encrypted;  // will return True
}

Handling Errors And Timeouts

For whatever reason, the HTTP requests at the heart of the API may not always succeed.

Every method will return false if an error occurred, and you should always check for this before acting on the results of the method call.

In some cases, you may also need to check the reason why the request failed. This would most often be when you tried to save some data that did not validate correctly.

$algorithms = $compredict_client->getAlgorithms();

if (!$algorithms) {
    $error = $compredict_client->getLastError();
    echo $error->code;
    echo $error->message;
}

Returning false on errors, and using error objects to provide context is good for writing quick scripts but is not the most robust solution for larger and more long-term applications.

An alternative approach to error handling is to configure the API client to throw exceptions when errors occur. Bear in mind, that if you do this, you will need to catch and handle the exception in code yourself. The exception throwing behavior of the client is controlled using the failOnError method:

$compredict_client->failOnError();

try {
    $orders = $compredict_client->getAlgorithms();

} catch(Compredict\API\Algorithms\Error $error) {
    echo $error->getCode();
    echo $error->getMessage();
}

The exceptions thrown are subclasses of Error, representing client errors and server errors. The API documentation for response codes contains a list of all the possible error conditions the client may encounter.

Verifying SSL certificates

By default, the client will attempt to verify the SSL certificate used by the COMPREDICT AI Core. In cases where this is undesirable, or where an unsigned certificate is being used, you can turn off this behavior using the verifyPeer switch, which will disable certificate checking on all subsequent requests:

$compredict_client->verifyPeer(false);

All versions of ai-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^7.3
ext-curl Version *
ext-openssl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package compredict/ai-sdk contains the following files

Loading the files please wait ....