halilcosdu/laravel-replicate

Replicate Laravel PHP client

v1.0.2 2024-04-27 15:09 UTC

This package is auto-updated.

Last update: 2024-05-09 13:14:23 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

The halilcosdu/laravel-replicate package is a Laravel client for the Replicate API. It provides a convenient way to interact with the Replicate API using PHP and Laravel's Facade pattern. The package includes methods for managing and interacting with various aspects of the Replicate service, such as accounts, collections, deployments, hardware, models, predictions, and trainings. For example, you can list all collections, get a specific collection, create a new deployment, get or update an existing deployment, list all hardware, create a new model, get a specific model or its version, list all versions of a model, delete a model version, list all models, create a prediction, get or cancel a prediction, list all predictions, list all trainings, create a new training, get or cancel a training, get the default secret, and create a deployment or model prediction. The package is configurable via Laravel's configuration system, allowing you to set your API token and URL through your environment file.

Installation

You can install the package via composer:

composer require halilcosdu/laravel-replicate

You can publish the config file with:

php artisan vendor:publish --tag="replicate-config"

This is the contents of the published config file:

return [
    'api_token' => env('REPLICATE_API_TOKEN'),
    'api_url' => env('REPLICATE_API_URL', 'https://api.replicate.com/v1'),
];

Usage

Replicate::account()
Replicate::getCollection(string $slug)
Replicate::listCollections()
Replicate::listDeployments()
Replicate::createDeployment(array $data)
Replicate::getDeployment(string $owner, string $name)
Replicate::updateDeployment(string $owner, string $name, array $data)
Replicate::listHardware()
Replicate::createModel(array $data)
Replicate::getModel(string $owner, string $name)
Replicate::getModelVersion(string $owner, string $name, string $version)
Replicate::listModelVersions(string $owner, string $name)
Replicate::deleteModelVersion(string $owner, string $name, string $version)
Replicate::listModels()
Replicate::createPrediction(array $data)
Replicate::getPrediction(string $id)
Replicate::cancelPrediction($id)
Replicate::listPredictions()
Replicate::listTrainings()
Replicate::createTraining(string $owner, string $name, string $version, array $data)
Replicate::getTraining(string $id)
Replicate::cancelTraining($id)
Replicate::defaultSecret()
Replicate::createDeploymentPrediction(string $owner, string $name, array $data)
Replicate::createModelPrediction(string $owner, string $name, string $version, array $data)

Reference: https://replicate.com/docs/reference/http

Example

use HalilCosdu\Replicate\Facades\Replicate;

$response = Replicate::account();
$response->body() : string;
$response->json($key = null, $default = null) : mixed;
$response->object() : object;
$response->collect($key = null) : Illuminate\Support\Collection;
$response->status() : int;
$response->successful() : bool;
$response->redirect(): bool;
$response->failed() : bool;
$response->clientError() : bool;
$response->header($header) : string;
$response->headers() : array;

In addition to the response methods listed above, the following methods may be used to determine if the response has a given status code:

$response->ok() : bool;                  // 200 OK
$response->created() : bool;             // 201 Created
$response->accepted() : bool;            // 202 Accepted
$response->noContent() : bool;           // 204 No Content
$response->movedPermanently() : bool;    // 301 Moved Permanently
$response->found() : bool;               // 302 Found
$response->badRequest() : bool;          // 400 Bad Request
$response->unauthorized() : bool;        // 401 Unauthorized
$response->paymentRequired() : bool;     // 402 Payment Required
$response->forbidden() : bool;           // 403 Forbidden
$response->notFound() : bool;            // 404 Not Found
$response->requestTimeout() : bool;      // 408 Request Timeout
$response->conflict() : bool;            // 409 Conflict
$response->unprocessableEntity() : bool; // 422 Unprocessable Entity
$response->tooManyRequests() : bool;     // 429 Too Many Requests
$response->serverError() : bool;         // 500 Internal Server Error

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.