halilcosdu/laravel-replicate

Replicate Laravel PHP 客户端

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

This package is auto-updated.

Last update: 2024-09-20 11:15:00 UTC


README

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

halilcosdu/laravel-replicate 包是用于 Replicate API 的 Laravel 客户端。它提供了一个方便的方式来使用 PHP 和 Laravel 的 Facade 模式与 Replicate API 进行交互。该包包括管理和与 Replicate 服务各个方面(如账户、集合、部署、硬件、模型、预测和训练)交互的方法。例如,您可以列出所有集合,获取特定集合,创建新的部署,获取或更新现有部署,列出所有硬件,创建新的模型,获取特定模型或其版本,列出模型的全部版本,删除模型版本,列出所有模型,创建预测,获取或取消预测,列出所有预测,列出所有训练,创建新的训练,获取或取消训练,获取默认密钥,以及创建部署或模型预测。该包可以通过 Laravel 的配置系统进行配置,允许您通过环境文件设置您的 API 令牌和 URL。

安装

您可以通过 composer 安装此包

composer require halilcosdu/laravel-replicate

您可以使用以下命令发布配置文件

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

这是发布配置文件的内容

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

用法

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)

参考:https://replicate.com/docs/reference/http

示例

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;

除了上面列出的响应方法外,以下方法可以用来确定响应是否具有给定的状态码

$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

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

贡献

有关详细信息,请参阅 CONTRIBUTING

安全漏洞

有关如何报告安全漏洞的更多信息,请参阅 我们的安全策略

鸣谢

许可协议

MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件