mazin/replicate-php

这是 Replicate 的 PHP 客户端。

安装次数: 6

依赖项: 0

建议者: 0

安全: 0

星标: 4

关注者: 1

分支: 0

开放问题: 0

类型:客户端库

0.0.1 2023-03-09 00:54 UTC

This package is auto-updated.

Last update: 2024-09-09 04:15:14 UTC


README

这是一个简单的 Replicate PHP 客户端。它涵盖了 Replicate HTTP API 的主要预测功能。

要求

  • PHP 8.1

安装

使用 composer 安装包

composer require replicate/replicate-php

用法

使用您的 API 令牌初始化 replicate 客户端

从您的 Replicate 账户 获取您的 API 令牌。

$replicate = new Replicate('token');

创建一个预测

try {
    $prediction = $replicate->createPrediction(
        version: 'v1',
        input: ['text' => 'foo'],
    );

    echo $prediction->id; // take a look at Prediction data class for available fields
} catch (ReplicateException|ReplicateWebhookInputException|ResponseException $e) {
    echo $e->getMessage();
}

获取一个预测

try {
    $prediction = $this->replicate->prediction(predictionId: 'prediction-id');

    echo $prediction->id;
} catch (ReplicateException|ResponseException $e) {
    // log error
}

获取预测列表

try {
    $predictions = $this->replicate->predictions();

    // if you would like to paginate.
    if ($predictions->next) {
        
        // extract the cursor from the next url
        $nextUrl = $predictions->next;
        $query = parse_url($nextUrl, PHP_URL_QUERY);
        parse_str($query, $params);
        $cursor = $params['cursor'];
        
        $predictions = $this->replicate->predictions(cursor: $cursor);
        // $predictions->results;
    }
    
    // take a look at the Predictions data class for available fields.
} catch (ReplicateException|ResponseException $e) {
    // log error
}

取消预测

try {
    $response = $this->replicate->cancelPrediction(predictionId: 'prediction-id');

    echo $response->status;
} catch (ReplicateException|ResponseException $e) {
    // log error
}

开发

安装依赖项

composer install

运行测试

composer test

许可证

MIT