This is a framework-agnostic PHP client for Comfy Deploy.com built on the amazing Saloon v3 🤠 library. Use it to easily interact with machine learning models such as Stable Diffusion right from your PHP application.
Install with composer.
composer require soiposervices/comfydeploy
Create a new api instance.
use SoipoServices\ComfyDeploy\ComfyDeploy;
...
$api = new ComfyDeploy(
apiToken: $_ENV['COMFY_DEPLOY_API_TOKEN'],
);
Then use it to invoke your model (or in comfy deploy terms "create a workflow").
$deployment_id = 'e4a14vs9-q40j-4ee2-1375-778b2je3221c';
$input = [
'model' => 'prompt',
'postive_prompt' => 'a photo of an astronaut riding a horse on mars',
'seed' => null,
];
$data = $api->workflows()->run($deployment_id, $input);
$data->run_id; // 257b65b8-ac23-49be-8aca-53d2dd8556c6
Begin by adding your credentials to your services config file.
// config/services.php
'comfy_deploy' => [
'api_token' => env('COMFY_DEPLOY_API_TOKEN'),
],
Bind the ComfyDeploy
class in a service provider.
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bind(ComfyDeploy::class, function () {
return new ComfyDeploy(
apiToken: config('services.comfy_deploy.api_token'),
);
});
}
And use anywhere in your application.
$data = app(ComfyDeploy::class)->workflows()->get($run_id);
Test your integration using Saloon's amazing response recording.
use Saloon\Laravel\Saloon; // composer require sammyjo20/saloon-laravel "^2.0"
...
Saloon::fake([
MockResponse::fixture('getWorkflow'),
]);
$run_id = '257b65b8-ac23-49be-8aca-53d2dd8556c6';
// The initial request will check if a fixture called "getWorkflow"
// exists. Because it doesn't exist yet, the real request will be
// sent and the response will be recorded to tests/Fixtures/Saloon/getWorkflow.json.
$data = app(ComfyDeploy::class)->workflows()->get($run_id);
// However, the next time the request is made, the fixture will
// exist, and Saloon will not make the request again.
$data = app(ComfyDeploy::class)->workflows()->get($run_id);
All responses are returned as data objects. Detailed information can be found by inspecting the following class properties:
Comfy Deploy allows you to configure a webhook to be called when your prediction is complete. To do so chain withWebhook($url)
onto your api instance before calling the run
method. For example:
$api->workflows()->withWebhook('https://www.example.com/webhook')->run($deployment_id, $input);
$data->run_id; // 257b65b8-ac23-49be-8aca-53d2dd8556c6
Use to get details about an existing workflow.
use SoipoServices\ComfyDeploy\Data\GetWorkflowData;
...
$run_id = '257b65b8-ac23-49be-8aca-53d2dd8556c6'
/* @var GetWorkflowData $data */
$data = $api->workflows()->get($run_id);
$data->id;
Use to run a workflow via deployment_id. Returns an RunWorkflowData object.
use SoipoServices\ComfyDeploy\Data\RunWorkflowData
...
$deployment_id = 'e4a14vs9-q40j-4ee2-1375-778b2je3221c';
$input = [
'postive_prompt' => 'a photo of an astronaut riding a horse on mars',
];
/* @var RunWorkflowData $data */
$data = $api->workflows()
->withWebhook('https://www.example.com/webhook') // optional
->run($deployment_id, $input);
$data->run_id; // 257b65b8-ac23-49be-8aca-53d2dd8556c6
The MIT License (MIT). Please see License File for more information.