Download the PHP package arikislam/replicate-php-client without Composer
On this page you can find all versions of the php package arikislam/replicate-php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arikislam/replicate-php-client
More information about arikislam/replicate-php-client
Files in arikislam/replicate-php-client
Package replicate-php-client
Short Description A PHP client for the Replicate API
License MIT
Informations about the package replicate-php-client
Replicate PHP Client
A simple PHP client for interacting with the Replicate API, enabling the ability to run machine learning models from your PHP applications. This library provides a clean and reusable way to interact with the API in a Laravel environment but can also be used in other PHP applications.
Features
- Simple API client for Replicate
- Supports Laravel out of the box
- Uses Guzzle HTTP client for HTTP requests
- Allows easy integration with machine learning models using Replicate
Installation
To install the package, simply use Composer:
Laravel Configuration
For Laravel applications, the package will automatically register the ReplicatePhpClientServiceProvider
and the Replicate
alias.
You can publish the config file with:
Usage
Configuration
To use this package, you must have an API key from Replicate.
Set up the API key in your environment file:
Example Request
To create an inference using the Replicate API, use the Replicate
facade in your application as shown below:
This example demonstrates how to send a request to the Replicate API with the required parameters.
Detailed Breakdown
1. Input
The input
parameter specifies the model input options. In this case:
prompt
: The text prompt for generating the image.go_fast
: A boolean indicating whether the model should prioritize speed over quality.num_outputs
: The number of outputs required from the model.aspect_ratio
: The aspect ratio of the output (e.g., 16:9).output_format
: The format of the generated output (e.g.,png
).output_quality
: The quality of the output (percentage-based, 80 means 80% quality).megapixels
: Controls the megapixel size for the image (e.g., .25).
2. Webhooks
Although webhooks can be used to track the progress of asynchronous tasks, this package allows you to specify a webhook
URL and webhook_events_filter
to listen for certain events. Currently, the webhook
parameter is set to null
in the example for simplicity.
3. API Version
The version
is an identifier for the version of the Replicate API being used. You can specify which model version you are targeting by using the correct version hash.
Response Handling
The response from the API will contain details of the prediction, including the generated content or the status of the request. You can handle the response as follows:
Testing
This package includes support for unit testing. You can run tests using PHPUnit:
Advanced Usage
Custom HTTP Client
You can provide your own custom HTTP client if needed by extending the Guzzle client. For example:
Facades in Laravel
For Laravel users, the Replicate
facade provides a convenient way to interact with the API. However, if you are not using Laravel, you can directly instantiate the Replicate
class and make API requests.
Contributing
Contributions are welcome! Please submit a pull request or open an issue to contribute to the development of this package.
License
This package is licensed under the MIT License. See the LICENSE file for more information.
Author
This package is maintained by S M Ariq Islam.