Skip to content

Commit

Permalink
Updated readme and few cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedmaazin committed Mar 9, 2023
1 parent 0dae50e commit 5db4b25
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 4 deletions.
106 changes: 105 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,107 @@
# Replicate PHP client

This is a PHP client for the [Replicate](https://replicate.com/) .
This is a simple PHP client for the [Replicate](https://replicate.com/). It covers the main prediction functionalities
of the [Replicate HTTP API](https://replicate.com/docs/reference/http).

## Requirements

- PHP 8.1

## Installation

Install the package with composer:

```bash
composer require replicate/replicate-php
```

## Usage

### Initialize the replicate client with your API token

Get your API token from your [Replicate account](https://replicate.com/account).

```php
$replicate = new Replicate('token');
```

### Create a prediction

```php
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();
}
```

### Get a prediction

```php
try {
$prediction = $this->replicate->prediction('prediction-id');

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

### Get a list of predictions

```php
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);
}

// take a look at the Predictions data class for available fields.
} catch (ReplicateException|ResponseException $e) {
// log error
}
```

### Cancel a prediction

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

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

## Development

### Install dependencies

```bash
composer install
```

### Run tests

```bash
composer test
```

## License

MIT
2 changes: 0 additions & 2 deletions examples/ExampleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public function __construct()

public function exampleCreateAPrediction(): void
{
$this->replicate = new Replicate('token');

try {
$prediction = $this->replicate->createPrediction(
version: 'v1',
Expand Down
1 change: 0 additions & 1 deletion tests/Validators/ReplicateWebhookValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public function test_validate(): void
{
$validator = new ReplicateWebhookValidator();

// Test valid input
$input = [
'webhook' => 'https://example.com',
'webhook_events_filter' => ['start', 'output', 'logs', 'completed']
Expand Down

0 comments on commit 5db4b25

Please sign in to comment.