new ingest und profile settings
This commit is contained in:
102
src/Controller/Admin/IngestProfileController.php
Normal file
102
src/Controller/Admin/IngestProfileController.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\IngestProfile;
|
||||
use App\Index\IndexConfigurationProvider;
|
||||
use App\Index\IndexMetaManager;
|
||||
use App\Index\IndexStructureComparator;
|
||||
use App\Repository\IngestProfileRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
#[Route('/admin/ingest-profiles')]
|
||||
class IngestProfileController extends AbstractController
|
||||
{
|
||||
#[Route('/', name: 'admin_ingest_profile_list')]
|
||||
public function list(
|
||||
IngestProfileRepository $repo,
|
||||
IndexMetaManager $metaManager,
|
||||
IndexConfigurationProvider $provider,
|
||||
IndexStructureComparator $comparator
|
||||
): Response {
|
||||
|
||||
$profiles = $repo->findBy([], ['version' => 'DESC']);
|
||||
$activeProfile = $repo->findActive();
|
||||
|
||||
$meta = $metaManager->readMeta();
|
||||
$currentStructure = $provider->getConfiguration()->toStructureArray();
|
||||
|
||||
$diff = $comparator->compare($meta, $currentStructure);
|
||||
|
||||
$structureMismatch = false;
|
||||
foreach ($diff as $row) {
|
||||
if (!$row['equal']) {
|
||||
$structureMismatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('admin/ingest_profile/list.html.twig', [
|
||||
'profiles' => $profiles,
|
||||
'activeProfile' => $activeProfile,
|
||||
'indexMeta' => $meta,
|
||||
'diff' => $diff,
|
||||
'structureMismatch' => $structureMismatch,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/create', name: 'admin_ingest_profile_create', methods: ['GET', 'POST'])]
|
||||
public function create(
|
||||
Request $request,
|
||||
IngestProfileRepository $repo,
|
||||
EntityManagerInterface $em
|
||||
): Response {
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
|
||||
$latest = $repo->findLatestVersion();
|
||||
$nextVersion = $latest ? $latest->getVersion() + 1 : 1;
|
||||
|
||||
$profile = new IngestProfile(
|
||||
$nextVersion,
|
||||
(int)$request->request->get('chunk_size'),
|
||||
(int)$request->request->get('chunk_overlap'),
|
||||
(string)$request->request->get('embedding_model'),
|
||||
(int)$request->request->get('embedding_dimension'),
|
||||
(int)$request->request->get('scoring_version')
|
||||
);
|
||||
|
||||
$em->persist($profile);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('admin_ingest_profile_list');
|
||||
}
|
||||
|
||||
return $this->render('admin/ingest_profile/create.html.twig');
|
||||
}
|
||||
|
||||
#[Route('/activate/{id}', name: 'admin_ingest_profile_activate')]
|
||||
public function activate(
|
||||
IngestProfile $profile,
|
||||
IngestProfileRepository $repo,
|
||||
EntityManagerInterface $em
|
||||
): Response {
|
||||
|
||||
$active = $repo->findActive();
|
||||
if ($active) {
|
||||
$active->deactivate();
|
||||
}
|
||||
|
||||
$profile->activate();
|
||||
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('admin_ingest_profile_list');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user