Verfügbarkeitstest für API Provider ergänzt.
This commit is contained in:
@@ -15,4 +15,5 @@ interface ApiPluginInterface
|
||||
public function getStyledImage(string $promptId): string;
|
||||
public function testConnection(array $data): bool;
|
||||
public function searchModels(string $searchTerm): array;
|
||||
public function checkAvailability(): array;
|
||||
}
|
||||
@@ -255,6 +255,60 @@ class ComfyUi implements ApiPluginInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function checkAvailability(): array
|
||||
{
|
||||
$this->logInfo('Checking ComfyUI availability.');
|
||||
|
||||
if (!$this->apiProvider->enabled) {
|
||||
$this->logDebug('ComfyUI provider is disabled.');
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Provider is disabled',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($this->apiProvider->api_url)) {
|
||||
$this->logDebug('ComfyUI API URL is not configured.');
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'API URL not configured',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(5)->get(rtrim($this->apiProvider->api_url, '/') . '/queue');
|
||||
if ($response->successful()) {
|
||||
$this->logInfo('ComfyUI is available.');
|
||||
return [
|
||||
'available' => true,
|
||||
'reason' => 'Connection successful',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
} else {
|
||||
$this->logError('ComfyUI connection failed.', ['status' => $response->status()]);
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection failed: ' . $response->status(),
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('ComfyUI availability check failed.', ['error' => $e->getMessage()]);
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection error: ' . $e->getMessage(),
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function searchModels(string $searchTerm): array
|
||||
{
|
||||
$this->logInfo('ComfyUI does not support model search. Returning empty list.', ['searchTerm' => $searchTerm]);
|
||||
|
||||
@@ -139,6 +139,84 @@ class RunwareAi implements ApiPluginInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function checkAvailability(): array
|
||||
{
|
||||
$this->logInfo('Checking RunwareAI availability.');
|
||||
|
||||
if (!$this->apiProvider->enabled) {
|
||||
$this->logDebug('RunwareAI provider is disabled.');
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Provider is disabled',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($this->apiProvider->api_url)) {
|
||||
$this->logDebug('RunwareAI API URL is not configured.');
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'API URL not configured',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($this->apiProvider->token)) {
|
||||
$this->logDebug('RunwareAI API token is not configured.');
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'API token not configured',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::withHeaders([
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
])->timeout(5)->post(rtrim($this->apiProvider->api_url, '/'), [
|
||||
'taskType' => 'authentication',
|
||||
'apiKey' => $this->apiProvider->token,
|
||||
'taskUUID' => (string) Str::uuid(),
|
||||
]);
|
||||
|
||||
$responseData = $response->json();
|
||||
|
||||
if ($response->successful() && isset($responseData['data']) && !isset($responseData['error'])) {
|
||||
$this->logInfo('RunwareAI is available.');
|
||||
return [
|
||||
'available' => true,
|
||||
'reason' => 'Connection successful',
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
} else {
|
||||
$errorMessage = $responseData['error'] ?? 'Unknown error';
|
||||
$this->logError('RunwareAI connection failed.', [
|
||||
'status' => $response->status(),
|
||||
'error_message' => $errorMessage
|
||||
]);
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection failed: ' . $errorMessage,
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logError('RunwareAI availability check failed.', ['error' => $e->getMessage()]);
|
||||
return [
|
||||
'available' => false,
|
||||
'reason' => 'Connection error: ' . $e->getMessage(),
|
||||
'provider_id' => $this->apiProvider->id,
|
||||
'provider_name' => $this->apiProvider->name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function searchModels(string $searchTerm): array
|
||||
{
|
||||
|
||||
79
app/Http/Controllers/Api/AiStatusController.php
Normal file
79
app/Http/Controllers/Api/AiStatusController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ApiProvider;
|
||||
use App\Api\Plugins\PluginLoader;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AiStatusController extends Controller
|
||||
{
|
||||
public function checkStatus(Request $request)
|
||||
{
|
||||
$providers = ApiProvider::where('enabled', true)->get();
|
||||
$results = [];
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
try {
|
||||
$plugin = PluginLoader::getPlugin($provider->plugin, $provider);
|
||||
$status = $plugin->checkAvailability();
|
||||
$results[] = $status;
|
||||
} catch (\Exception $e) {
|
||||
$results[] = [
|
||||
'available' => false,
|
||||
'reason' => 'Plugin error: ' . $e->getMessage(),
|
||||
'provider_id' => $provider->id,
|
||||
'provider_name' => $provider->name
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($results);
|
||||
}
|
||||
|
||||
public function checkAndUpdateStatus(Request $request)
|
||||
{
|
||||
$providers = ApiProvider::all();
|
||||
$anyAvailable = false;
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
try {
|
||||
$plugin = PluginLoader::getPlugin($provider->plugin, $provider);
|
||||
$status = $plugin->checkAvailability();
|
||||
|
||||
if (!$status['available']) {
|
||||
// Deaktiviere den Provider, wenn nicht verfügbar
|
||||
$provider->enabled = false;
|
||||
$provider->save();
|
||||
|
||||
// Deaktiviere alle zugehörigen Modelle
|
||||
foreach ($provider->aiModels as $model) {
|
||||
$model->enabled = false;
|
||||
$model->save();
|
||||
|
||||
// Deaktiviere alle zugehörigen Styles
|
||||
foreach ($model->styles as $style) {
|
||||
$style->enabled = false;
|
||||
$style->save();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$anyAvailable = true;
|
||||
// Stelle sicher, dass der Provider aktiviert ist, wenn er verfügbar ist
|
||||
$provider->enabled = true;
|
||||
$provider->save();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$provider->enabled = false;
|
||||
$provider->save();
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'any_available' => $anyAvailable,
|
||||
'message' => 'AI status check and update completed'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class AiModel extends Model
|
||||
|
||||
protected $casts = [
|
||||
'parameters' => 'array',
|
||||
'enabled' => 'boolean',
|
||||
];
|
||||
|
||||
public function primaryApiProvider()
|
||||
|
||||
@@ -23,6 +23,26 @@ class ApiProvider extends Model
|
||||
'enabled' => 'boolean',
|
||||
];
|
||||
|
||||
public function disableWithDependencies()
|
||||
{
|
||||
$this->enabled = false;
|
||||
$this->save();
|
||||
|
||||
// Deaktiviere alle zugehörigen Modelle
|
||||
foreach ($this->aiModels as $model) {
|
||||
$model->enabled = false;
|
||||
$model->save();
|
||||
|
||||
// Deaktiviere alle zugehörigen Styles
|
||||
foreach ($model->styles as $style) {
|
||||
$style->enabled = false;
|
||||
$style->save();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function styles()
|
||||
{
|
||||
return $this->hasMany(Style::class);
|
||||
|
||||
Reference in New Issue
Block a user