|
|
@@ -2167,6 +2167,26 @@ class AnimeService
|
|
|
|
|
|
// 轮训获取图片任务结果
|
|
|
private function loopGetPicTaskResult($task_id) {
|
|
|
+ $task = MpGeneratePicTask::where('id', $task_id)->first();
|
|
|
+ if (!$task) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查任务模型类型
|
|
|
+ $model = getProp($task, 'model');
|
|
|
+ $isVolcModel = in_array($model, \App\Consts\BaseConst::VOLC_PIC_MODELS);
|
|
|
+
|
|
|
+ // 火山API是同步返回结果的,直接检查任务状态
|
|
|
+ if ($isVolcModel) {
|
|
|
+ // 火山API任务,直接返回结果(已在创建时处理完成)
|
|
|
+ if ($task->status === 'success' && $task->result_url) {
|
|
|
+ $result_urls = is_array($task->result_url) ? $task->result_url : json_decode($task->result_url, true);
|
|
|
+ return is_array($result_urls) ? $result_urls[0] : $task->result_url;
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 即梦AI需要轮询查询状态
|
|
|
$start_count = 0;
|
|
|
$img_url = '';
|
|
|
while ($start_count <= 20) { // 循环20次请求,每3s一次
|
|
|
@@ -2802,6 +2822,7 @@ class AnimeService
|
|
|
|
|
|
public function generateImg($data) {
|
|
|
$prompt = getProp($data, 'prompt');
|
|
|
+ $model = getProp($data, 'model', 'doubao-seedream-5-0-lite-260128');
|
|
|
|
|
|
// 参数验证
|
|
|
if (!$prompt) Utils::throwError('20003:请提供提示词');
|
|
|
@@ -2810,6 +2831,7 @@ class AnimeService
|
|
|
// 创建图片生成任务
|
|
|
$params = [
|
|
|
'prompt' => $prompt,
|
|
|
+ 'model' => $model,
|
|
|
'ref_img_urls' => [],
|
|
|
'width' => 2048,
|
|
|
'height' => 2048
|
|
|
@@ -2822,7 +2844,31 @@ class AnimeService
|
|
|
Utils::throwError('20003:创建图片生成任务失败');
|
|
|
}
|
|
|
|
|
|
- // 轮询获取结果(3分钟超时,每3秒查询一次)
|
|
|
+ // 检查任务模型类型
|
|
|
+ $model = getProp($task, 'model');
|
|
|
+ $isVolcModel = in_array($model, \App\Consts\BaseConst::VOLC_PIC_MODELS);
|
|
|
+
|
|
|
+ // 火山API是同步返回结果的,直接检查任务状态
|
|
|
+ if ($isVolcModel) {
|
|
|
+ // 等待队列处理(火山API通过队列异步处理)
|
|
|
+ sleep(5);
|
|
|
+
|
|
|
+ // 刷新任务状态
|
|
|
+ $task = MpGeneratePicTask::where('id', $task_id)->first();
|
|
|
+
|
|
|
+ if ($task->status === 'success' && $task->result_url) {
|
|
|
+ $result_urls = is_array($task->result_url) ? $task->result_url : json_decode($task->result_url, true);
|
|
|
+ $img_url = is_array($result_urls) ? $result_urls[0] : $task->result_url;
|
|
|
+ return $img_url;
|
|
|
+ } elseif ($task->status === 'failed') {
|
|
|
+ Utils::throwError('20003:图片生成失败,' . ($task->error_message ?? '未知错误'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果还在处理中,提示用户稍后查看
|
|
|
+ Utils::throwError('20003:图片生成中,请稍后刷新查看结果');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 即梦AI需要轮询获取结果(3分钟超时,每3秒查询一次)
|
|
|
$start_time = time();
|
|
|
$timeout = 180; // 3分钟
|
|
|
$img_url = '';
|