110 lines
4.2 KiB
PHP
110 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\AiModelResource\Pages;
|
|
use App\Filament\Resources\AiModelResource\RelationManagers;
|
|
use App\Models\AiModel;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Tables\Actions\Action;
|
|
|
|
class AiModelResource extends Resource
|
|
{
|
|
protected static ?string $model = AiModel::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
TextInput::make('name')
|
|
->label(__('filament.resource.ai_model.form.name'))
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('model_id')
|
|
->label(__('filament.resource.ai_model.form.model_id'))
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('model_type')
|
|
->nullable()
|
|
->maxLength(255),
|
|
Forms\Components\Toggle::make('enabled')
|
|
->label(__('filament.resource.ai_model.form.enabled'))
|
|
->default(true),
|
|
Select::make('apiProviders')
|
|
->relationship('apiProviders', 'name')
|
|
->multiple()
|
|
->preload()
|
|
->searchable(false)
|
|
->label(__('filament.resource.ai_model.form.api_providers')),
|
|
Forms\Components\Textarea::make('parameters')
|
|
->label(__('filament.resource.ai_model.form.parameters'))
|
|
->nullable()
|
|
->rows(15)
|
|
->json()
|
|
->helperText(__('filament.resource.ai_model.form.parameters_help'))
|
|
->formatStateUsing(fn (?array $state): ?string => $state ? json_encode($state, JSON_PRETTY_PRINT) : null),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('name')->label(__('filament.resource.ai_model.table.name'))->searchable()->sortable(),
|
|
TextColumn::make('model_id')->label(__('filament.resource.ai_model.table.model_id'))->searchable()->sortable(),
|
|
TextColumn::make('model_type')->label(__('filament.resource.ai_model.table.model_type'))->searchable()->sortable(),
|
|
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(),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
Action::make('duplicate')
|
|
->label(__('filament.resource.style.action.duplicate'))
|
|
->icon('heroicon-o-document-duplicate')
|
|
->action(function (AiModel $record, $livewire) {
|
|
$livewire->redirect(AiModelResource::getUrl('create', ['sourceRecord' => $record->id]));
|
|
}),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
])
|
|
->emptyStateActions([
|
|
Tables\Actions\CreateAction::make(),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListAiModels::route('/'),
|
|
'create' => Pages\CreateAiModel::route('/create'),
|
|
'edit' => Pages\EditAiModel::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|