tabelle ai_model_api_provider entfernt

This commit is contained in:
2025-08-29 14:09:01 +02:00
parent 9b1f6a479f
commit d271f256b7
11 changed files with 47 additions and 103 deletions

View File

@@ -138,23 +138,19 @@ class ImageController extends Controller
if ($request->style_id) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['primaryApiProvider', 'apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
$query->where('enabled', true)->with('primaryApiProvider');
}])->find($request->style_id);
} else {
// Attempt to get default style from settings
$defaultStyleSetting = \App\Models\Setting::where('key', 'default_style_id')->first();
if ($defaultStyleSetting && $defaultStyleSetting->value) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['primaryApiProvider', 'apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
$query->where('enabled', true)->with('primaryApiProvider');
}])->find($defaultStyleSetting->value);
}
}
if (!$style || !$style->aiModel || $style->aiModel->apiProviders->isEmpty()) {
if (!$style || !$style->aiModel || !$style->aiModel->primaryApiProvider) {
\Illuminate\Support\Facades\Log::warning('Style or provider not found', [
'style' => $style ? $style->toArray() : null,
'ai_model' => $style && $style->aiModel ? $style->aiModel->toArray() : null
@@ -163,16 +159,8 @@ class ImageController extends Controller
}
try {
// Use the primary API provider for this AI model if available
// Use the primary API provider for this AI model
$apiProvider = $style->aiModel->primaryApiProvider;
if (!$apiProvider) {
// Fallback to the first enabled API provider from the many-to-many relationship
$apiProvider = $style->aiModel->apiProviders->where('enabled', true)->first();
}
if (!$apiProvider) {
// If no enabled provider found, try any provider
$apiProvider = $style->aiModel->apiProviders->first();
}
if (!$apiProvider) {
\Illuminate\Support\Facades\Log::error('No API provider found for style', [
'style_id' => $style->id,
@@ -276,9 +264,7 @@ class ImageController extends Controller
try {
// Find the image associated with the prompt_id, eagerly loading relationships
$image = Image::with(['style.aiModel' => function ($query) {
$query->with(['primaryApiProvider', 'apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
$query->with('primaryApiProvider');
}])->where('comfyui_prompt_id', $promptId)->first();
if (!$image) {
@@ -302,26 +288,18 @@ class ImageController extends Controller
}
Log::info('fetchStyledImage: AI Model found.', ['ai_model_id' => $style->aiModel->id, 'ai_model_name' => $style->aiModel->name]);
if ($style->aiModel->apiProviders->isEmpty()) {
Log::warning('fetchStyledImage: No enabled API Providers found for AI Model.', ['ai_model_id' => $style->aiModel->id]);
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
}
// Use the primary API provider for this AI model if available
// Use the primary API provider for this AI model
$apiProvider = $style->aiModel->primaryApiProvider;
if (!$apiProvider) {
// Fallback to the first enabled API provider from the many-to-many relationship
$apiProvider = $style->aiModel->apiProviders->where('enabled', true)->first();
}
if (!$apiProvider) {
// If no enabled provider found, try any provider
$apiProvider = $style->aiModel->apiProviders->first();
Log::warning('fetchStyledImage: No API Provider found for AI Model.', ['ai_model_id' => $style->aiModel->id]);
return response()->json(['error' => __('api.style_or_provider_not_found')], 404);
}
Log::info('fetchStyledImage: API Provider found.', ['api_provider_id' => $apiProvider->id, 'api_provider_name' => $apiProvider->name]);
Log::info('Fetching base64 image from plugin.', ['prompt_id' => $promptId, 'api_provider' => $apiProvider->name]);
// Use the plugin to get the final image data (e.g., from ComfyUI's history/view)
$plugin = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
$base64Image = $plugin->waitForResult($promptId); // Re-purpose waitForResult for final fetch
$base64Image = $plugin->getStyledImage($promptId); // Use the new method
if (empty($base64Image)) {
Log::error('Received empty base64 image from plugin.', ['prompt_id' => $promptId]);
@@ -376,43 +354,23 @@ class ImageController extends Controller
// If style_id is provided, get the API provider for that style
if ($styleId) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['primaryApiProvider', 'apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
$query->where('enabled', true)->with('primaryApiProvider');
}])->find($styleId);
if ($style && $style->aiModel) {
// Use the primary API provider for this AI model if available
// Use the primary API provider for this AI model
$apiProvider = $style->aiModel->primaryApiProvider;
if (!$apiProvider) {
// Fallback to the first enabled API provider from the many-to-many relationship
$apiProvider = $style->aiModel->apiProviders->where('enabled', true)->first();
}
if (!$apiProvider) {
// If no enabled provider found, try any provider
$apiProvider = $style->aiModel->apiProviders->first();
}
}
}
// If image_uuid is provided, get the API provider for that image's style
elseif ($imageUuid) {
$image = Image::with(['style.aiModel' => function ($query) {
$query->with(['primaryApiProvider', 'apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
$query->with('primaryApiProvider');
}])->where('uuid', $imageUuid)->first();
if ($image && $image->style && $image->style->aiModel) {
// Use the primary API provider for this AI model if available
// Use the primary API provider for this AI model
$apiProvider = $image->style->aiModel->primaryApiProvider;
if (!$apiProvider) {
// Fallback to the first enabled API provider from the many-to-many relationship
$apiProvider = $image->style->aiModel->apiProviders->where('enabled', true)->first();
}
if (!$apiProvider) {
// If no enabled provider found, try any provider
$apiProvider = $image->style->aiModel->apiProviders->first();
}
}
}
// Fallback to the old behavior if no style_id or image_uuid is provided
@@ -421,22 +379,12 @@ class ImageController extends Controller
$defaultStyleSetting = \App\Models\Setting::where('key', 'default_style_id')->first();
if ($defaultStyleSetting && $defaultStyleSetting->value) {
$style = Style::with(['aiModel' => function ($query) {
$query->where('enabled', true)->with(['primaryApiProvider', 'apiProviders' => function ($query) {
$query->where('enabled', true);
}]);
$query->where('enabled', true)->with('primaryApiProvider');
}])->find($defaultStyleSetting->value);
if ($style && $style->aiModel) {
// Use the primary API provider for this AI model if available
// Use the primary API provider for this AI model
$apiProvider = $style->aiModel->primaryApiProvider;
if (!$apiProvider) {
// Fallback to the first enabled API provider from the many-to-many relationship
$apiProvider = $style->aiModel->apiProviders->where('enabled', true)->first();
}
if (!$apiProvider) {
// If no enabled provider found, try any provider
$apiProvider = $style->aiModel->apiProviders->first();
}
}
}