fix(covers): retry without prompt_optimizer on silent empty-image failure
Build and Deploy / verify (push) Successful in 10s
Build and Deploy / deploy (push) Successful in 17s

This commit is contained in:
2026-10-15 00:11:42 +00:00
parent d2e24522be
commit 6aae919bf7
+7 -2
View File
@@ -55,6 +55,11 @@ class CoverGenerator
$response = $this->requestImage($this->neutralPrompt($style), $model);
}
// 少数提示词在 prompt_optimizer 下静默失败(success 但无图):关掉优化器重试一次。
if ($response->successful() && ! is_string($response->json('data.image_urls.0'))) {
$response = $this->requestImage($this->buildPrompt($post, $style), $model, false);
}
if ($response->failed()) {
throw new \RuntimeException('HTTP '.$response->status().':'.Str::limit($response->body(), 200));
}
@@ -112,7 +117,7 @@ class CoverGenerator
return "博客文章封面配图。{$style}。画面中不要出现任何文字";
}
private function requestImage(string $prompt, ?string $model = null): \Illuminate\Http\Client\Response
private function requestImage(string $prompt, ?string $model = null, bool $optimizer = true): \Illuminate\Http\Client\Response
{
$llm = $this->llm();
@@ -124,7 +129,7 @@ class CoverGenerator
'aspect_ratio' => '16:9',
'response_format' => 'url',
'n' => 1,
'prompt_optimizer' => true,
'prompt_optimizer' => $optimizer,
]);
}
}