|
@@ -442,15 +442,17 @@ class AIImageGenerationService
|
|
|
throw new \Exception('JSON解析失败: ' . json_last_error_msg());
|
|
throw new \Exception('JSON解析失败: ' . json_last_error_msg());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- dLog('generate')->info('GPT-Image2 API响应', $responseData);
|
|
|
|
|
- logDB('generate', 'info', 'GPT-Image2 API响应', ['task_id' => $task->task_id, 'response' => $responseData]);
|
|
|
|
|
|
|
+ // 移除 b64_json 字段用于日志记录,避免生成超大日志
|
|
|
|
|
+ $logResponseData = $this->removeB64JsonFromResponse($responseData);
|
|
|
|
|
+ dLog('generate')->info('GPT-Image2 API响应', $logResponseData);
|
|
|
|
|
+ logDB('generate', 'info', 'GPT-Image2 API响应', ['task_id' => $task->task_id, 'response' => $logResponseData]);
|
|
|
|
|
|
|
|
if (isset($responseData['error'])) {
|
|
if (isset($responseData['error'])) {
|
|
|
// API返回错误
|
|
// API返回错误
|
|
|
logDB('generate', 'error', 'GPT-Image2任务失败', ['task_id' => $task->task_id, 'error' => $responseData['error']['message'] ?? 'API Error']);
|
|
logDB('generate', 'error', 'GPT-Image2任务失败', ['task_id' => $task->task_id, 'error' => $responseData['error']['message'] ?? 'API Error']);
|
|
|
$task->updateStatus(MpGeneratePicTask::STATUS_FAILED, [
|
|
$task->updateStatus(MpGeneratePicTask::STATUS_FAILED, [
|
|
|
'error_message' => $responseData['error']['message'] ?? 'API Error',
|
|
'error_message' => $responseData['error']['message'] ?? 'API Error',
|
|
|
- 'result_json' => $responseData
|
|
|
|
|
|
|
+ 'result_json' => $logResponseData
|
|
|
]);
|
|
]);
|
|
|
} else {
|
|
} else {
|
|
|
// 任务提交成功,直接处理结果
|
|
// 任务提交成功,直接处理结果
|
|
@@ -1778,4 +1780,31 @@ class AIImageGenerationService
|
|
|
return $imageStream;
|
|
return $imageStream;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 从响应数据中移除 b64_json 字段
|
|
|
|
|
+ * 避免在日志和数据库中存储大量 Base64 数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array $responseData
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ private function removeB64JsonFromResponse(array $responseData): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $cleanedData = $responseData;
|
|
|
|
|
+
|
|
|
|
|
+ if (isset($cleanedData['data']) && is_array($cleanedData['data'])) {
|
|
|
|
|
+ foreach ($cleanedData['data'] as &$imageData) {
|
|
|
|
|
+ if (isset($imageData['b64_json'])) {
|
|
|
|
|
+ // 移除 b64_json 字段,可选择性保留数据长度信息
|
|
|
|
|
+ $b64Length = strlen($imageData['b64_json']);
|
|
|
|
|
+ unset($imageData['b64_json']);
|
|
|
|
|
+ $imageData['b64_json_removed'] = true;
|
|
|
|
|
+ $imageData['b64_json_length'] = $b64Length;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ unset($imageData); // 解除引用
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $cleanedData;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|