fixed migrations, changed settings to global settings, changed image list to have a "delete all" button instead of "create", fixed printing, added imagick for printing.
This commit is contained in:
@@ -32,11 +32,11 @@ class AiModelResource extends Resource
|
||||
->schema([
|
||||
Forms\Components\Section::make()
|
||||
->schema([
|
||||
Select::make('api_provider_id')
|
||||
->label(__('filament.resource.ai_model.form.api_provider'))
|
||||
Select::make('apiProviders')
|
||||
->label(__('filament.resource.ai_model.form.api_providers'))
|
||||
->relationship('apiProviders', 'name')
|
||||
->multiple()
|
||||
->live()
|
||||
->nullable()
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('model_search_result', null);
|
||||
}),
|
||||
@@ -44,20 +44,24 @@ class AiModelResource extends Resource
|
||||
->label(__('filament.resource.ai_model.form.search_model'))
|
||||
->searchable()
|
||||
->live()
|
||||
->hidden(fn (callable $get) => !static::canSearchModels($get('api_provider_id')))
|
||||
->hidden(fn (callable $get) => !static::canSearchModelsWithAnyProvider($get('apiProviders')))
|
||||
->getSearchResultsUsing(function (string $search, callable $get) {
|
||||
$apiProviderId = $get('api_provider_id');
|
||||
if (!$apiProviderId) {
|
||||
$apiProviderIds = $get('apiProviders');
|
||||
if (empty($apiProviderIds)) {
|
||||
return [];
|
||||
}
|
||||
$pluginInstance = static::getPluginInstance($apiProviderId);
|
||||
if ($pluginInstance && method_exists($pluginInstance, 'searchModels')) {
|
||||
$models = $pluginInstance->searchModels($search);
|
||||
$options = [];
|
||||
foreach ($models as $model) {
|
||||
$options[json_encode(['name' => $model['name'], 'id' => $model['id'], 'type' => $model['type'] ?? null])] = $model['name'] . ' (' . $model['id'] . ')';
|
||||
|
||||
// Try each API provider until we find one that works
|
||||
foreach ($apiProviderIds as $apiProviderId) {
|
||||
$pluginInstance = static::getPluginInstance($apiProviderId);
|
||||
if ($pluginInstance && method_exists($pluginInstance, 'searchModels')) {
|
||||
$models = $pluginInstance->searchModels($search);
|
||||
$options = [];
|
||||
foreach ($models as $model) {
|
||||
$options[json_encode(['name' => $model['name'], 'id' => $model['id'], 'type' => $model['type'] ?? null, 'api_provider_id' => $apiProviderId])] = $model['name'] . ' (' . $model['id'] . ')';
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
return [];
|
||||
})
|
||||
@@ -103,22 +107,28 @@ class AiModelResource extends Resource
|
||||
]);
|
||||
}
|
||||
|
||||
protected static function canSearchModels(?int $apiProviderId): bool
|
||||
protected static function canSearchModelsWithAnyProvider(?array $apiProviderIds): bool
|
||||
{
|
||||
if (!$apiProviderId) {
|
||||
if (empty($apiProviderIds)) {
|
||||
return false;
|
||||
}
|
||||
$apiProvider = ApiProvider::find($apiProviderId);
|
||||
if (!$apiProvider || !$apiProvider->plugin) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$pluginInstance = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
|
||||
return method_exists($pluginInstance, 'searchModels');
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception if needed
|
||||
return false;
|
||||
|
||||
foreach ($apiProviderIds as $apiProviderId) {
|
||||
$apiProvider = ApiProvider::find($apiProviderId);
|
||||
if (!$apiProvider || !$apiProvider->plugin) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$pluginInstance = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
|
||||
if (method_exists($pluginInstance, 'searchModels')) {
|
||||
return true;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception if needed
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static function getPluginInstance(?int $apiProviderId): ?ApiPluginInterface
|
||||
@@ -138,6 +148,24 @@ class AiModelResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
protected static function canSearchModels(?int $apiProviderId): bool
|
||||
{
|
||||
if (!$apiProviderId) {
|
||||
return false;
|
||||
}
|
||||
$apiProvider = ApiProvider::find($apiProviderId);
|
||||
if (!$apiProvider || !$apiProvider->plugin) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$pluginInstance = PluginLoader::getPlugin($apiProvider->plugin, $apiProvider);
|
||||
return method_exists($pluginInstance, 'searchModels');
|
||||
} catch (\Exception $e) {
|
||||
// Log the exception if needed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
@@ -148,7 +176,7 @@ class AiModelResource extends Resource
|
||||
Tables\Columns\IconColumn::make('enabled')
|
||||
->label(__('filament.resource.ai_model.table.enabled'))
|
||||
->boolean(),
|
||||
TextColumn::make('apiProviders.name')->label(__('filament.resource.ai_model.table.api_providers'))->searchable()->sortable(),
|
||||
TextColumn::make('apiProviders.name')->label(__('filament.resource.ai_model.table.api_providers'))->searchable()->sortable()->limit(50),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user