parameter für Modelle eingeführt, Beschreibung aktualisiert
This commit is contained in:
@@ -82,16 +82,16 @@ class ComfyUi implements ApiPluginInterface
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
public function processImageStyleChange(string $imagePath, string $prompt, string $modelId, ?string $parameters = null): array
|
||||
public function processImageStyleChange(\App\Models\Image $image, \App\Models\Style $style): array
|
||||
{
|
||||
$this->logInfo('Starting ComfyUI style change process.', ['image_path' => $imagePath]);
|
||||
$this->logInfo('Starting ComfyUI style change process.', ['image_id' => $image->id, 'style_id' => $style->id]);
|
||||
|
||||
// 1. Upload image to ComfyUI
|
||||
$uploadResponse = $this->uploadImage($imagePath);
|
||||
$uploadResponse = $this->uploadImage(public_path('storage/' . $image->path));
|
||||
$filename = $uploadResponse['name'];
|
||||
|
||||
// 2. Construct the prompt
|
||||
$promptData = $this->constructPrompt($prompt, $filename, $modelId, $parameters);
|
||||
$promptData = $this->constructPrompt($style, $filename);
|
||||
|
||||
// 3. Queue the prompt
|
||||
$queueResponse = $this->queuePrompt($promptData);
|
||||
@@ -119,18 +119,39 @@ class ComfyUi implements ApiPluginInterface
|
||||
return $response->json();
|
||||
}
|
||||
|
||||
private function constructPrompt(string $prompt, string $filename, string $modelId, ?string $parameters): array
|
||||
private function constructPrompt(\App\Models\Style $style, string $filename): array
|
||||
{
|
||||
if (empty($parameters)) {
|
||||
$modelParams = $style->aiModel->parameters ?? [];
|
||||
$styleParams = $style->parameters ?? [];
|
||||
|
||||
if (empty($modelParams) && empty($styleParams)) {
|
||||
throw new \Exception('ComfyUI workflow (parameters) is missing.');
|
||||
}
|
||||
|
||||
$workflow = $parameters;
|
||||
$workflow = str_replace('__PROMPT__', $prompt, $workflow);
|
||||
$workflow = str_replace('__FILENAME__', $filename, $workflow);
|
||||
$workflow = str_replace('__MODEL_ID__', $modelId, $workflow);
|
||||
// Use array_replace_recursive for a deep merge
|
||||
$mergedParams = array_replace_recursive($modelParams, $styleParams);
|
||||
$workflow = json_encode($mergedParams);
|
||||
|
||||
return json_decode($workflow, true);
|
||||
// Properly escape the values for JSON injection
|
||||
$prompt = substr(json_encode($style->prompt, JSON_UNESCAPED_SLASHES), 1, -1);
|
||||
$filename_escaped = substr(json_encode($filename, JSON_UNESCAPED_SLASHES), 1, -1);
|
||||
$modelId_escaped = substr(json_encode($style->aiModel->model_id, JSON_UNESCAPED_SLASHES), 1, -1);
|
||||
|
||||
$workflow = str_replace('__PROMPT__', $prompt, $workflow);
|
||||
$workflow = str_replace('__FILENAME__', $filename_escaped, $workflow);
|
||||
$workflow = str_replace('__MODEL_ID__', $modelId_escaped, $workflow);
|
||||
|
||||
$decodedWorkflow = json_decode($workflow, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$this->logError('Failed to decode workflow JSON after placeholder replacement.', [
|
||||
'json_error' => json_last_error_msg(),
|
||||
'workflow_string' => $workflow
|
||||
]);
|
||||
throw new \Exception('Failed to construct valid ComfyUI workflow JSON: ' . json_last_error_msg());
|
||||
}
|
||||
|
||||
return $decodedWorkflow;
|
||||
}
|
||||
|
||||
private function queuePrompt(array $promptData): array
|
||||
|
||||
Reference in New Issue
Block a user