optimize reset and ux

This commit is contained in:
team 1
2026-02-15 16:49:43 +01:00
parent c099f72703
commit 402838adfa
4 changed files with 71 additions and 31 deletions

View File

@@ -3,6 +3,8 @@
# ------------------------------------------------------------ # ------------------------------------------------------------
parameters: parameters:
mto.kernel.dir: '%kernel.project_dir%'
mto.index.chunk_size: 800 mto.index.chunk_size: 800
mto.index.chunk_overlap: 100 mto.index.chunk_overlap: 100
mto.index.embedding_model: 'nomic-embed-text' mto.index.embedding_model: 'nomic-embed-text'
@@ -11,6 +13,8 @@ parameters:
mto.vector.python_bin: '/var/www/html/.venv/bin/python3' mto.vector.python_bin: '/var/www/html/.venv/bin/python3'
mto.vector.ingest_script: '/src/Vector/vector_ingest.py' mto.vector.ingest_script: '/src/Vector/vector_ingest.py'
mto.vector.data.path: '%kernel.project_dir%/var/knowledge'
mto.vector.timeout: 600 mto.vector.timeout: 600
# ------------------------------------------------------------ # ------------------------------------------------------------
@@ -42,7 +46,7 @@ services:
App\Controller\: App\Controller\:
resource: '../src/Controller/' resource: '../src/Controller/'
tags: ['controller.service_arguments'] tags: [ 'controller.service_arguments' ]
# ------------------------------------------------------------ # ------------------------------------------------------------
# AI Agent Infrastructure # AI Agent Infrastructure

View File

@@ -14,4 +14,5 @@ final class DashboardController extends AbstractController
{ {
return $this->render('admin/dashboard/index.html.twig'); return $this->render('admin/dashboard/index.html.twig');
} }
} }

View File

@@ -8,24 +8,21 @@ use App\Entity\IngestJob;
use App\Service\DocumentService; use App\Service\DocumentService;
use App\Service\FormatText; use App\Service\FormatText;
use App\Service\IngestJobService; use App\Service\IngestJobService;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\File\Exception\FileException; use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Uid\Uuid;
#[Route('/admin/documents')] #[Route('/admin/documents')]
class DocumentController extends AbstractController class DocumentController extends AbstractController
{ {
public function __construct(
private readonly FormatText $formatText,
)
{
}
#[Route('', name: 'admin_documents')] #[Route('', name: 'admin_documents')]
public function index(EntityManagerInterface $em): Response public function index(EntityManagerInterface $em): Response
@@ -63,14 +60,14 @@ class DocumentController extends AbstractController
} }
#[Route('/new', name: 'admin_document_new')] #[Route('/new', name: 'admin_document_new')]
public function new(Request $request, DocumentService $documentService): Response public function new(Request $request, DocumentService $documentService, FormatText $formatText): Response
{ {
if ($request->isMethod('POST')) { if ($request->isMethod('POST')) {
$file = $request->files->get('file'); $file = $request->files->get('file');
$title = $request->request->get('title') ?: $file->getClientOriginalName(); $title = $request->request->get('title') ?: $file->getClientOriginalName();
$title = $this->formatText->slugify($title); $title = $formatText->slugify($title);
if (!$file || !$title) { if (!$file || !$title) {
$this->addFlash('error', 'Titel und Datei sind erforderlich.'); $this->addFlash('error', 'Titel und Datei sind erforderlich.');
@@ -107,11 +104,12 @@ class DocumentController extends AbstractController
#[Route('/{id}/version/new', name: 'admin_document_version_new', requirements: ['id' => '[0-9a-fA-F\-]{36}'])] #[Route('/{id}/version/new', name: 'admin_document_version_new', requirements: ['id' => '[0-9a-fA-F\-]{36}'])]
public function newVersion( public function newVersion(
string $id, string $id,
Request $request, Request $request,
EntityManagerInterface $em, EntityManagerInterface $em,
DocumentService $documentService DocumentService $documentService
): Response { ): Response
{
$document = $em->getRepository(Document::class)->find($id); $document = $em->getRepository(Document::class)->find($id);
@@ -165,11 +163,12 @@ class DocumentController extends AbstractController
methods: ['POST'] methods: ['POST']
)] )]
public function activateVersion( public function activateVersion(
string $versionId, string $versionId,
Request $request, Request $request,
EntityManagerInterface $em, EntityManagerInterface $em,
DocumentService $documentService DocumentService $documentService
): RedirectResponse { ): RedirectResponse
{
if (!$this->isCsrfTokenValid('activate_version', $request->request->get('_token'))) { if (!$this->isCsrfTokenValid('activate_version', $request->request->get('_token'))) {
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
@@ -195,11 +194,12 @@ class DocumentController extends AbstractController
methods: ['POST'] methods: ['POST']
)] )]
public function ingestVersion( public function ingestVersion(
string $versionId, string $versionId,
Request $request, Request $request,
EntityManagerInterface $em, EntityManagerInterface $em,
IngestJobService $jobService, IngestJobService $jobService,
): ?RedirectResponse { ): ?RedirectResponse
{
$dryRun = false; $dryRun = false;
if (!$this->isCsrfTokenValid('ingest_version', $request->request->get('_token'))) { if (!$this->isCsrfTokenValid('ingest_version', $request->request->get('_token'))) {
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
@@ -238,14 +238,14 @@ class DocumentController extends AbstractController
); );
// Hintergrundprozess starten (Provider-kompatibel, kein Worker/Daemon) // Hintergrundprozess starten (Provider-kompatibel, kein Worker/Daemon)
$projectDir = (string) $this->getParameter('kernel.project_dir'); $projectDir = (string)$this->getParameter('kernel.project_dir');
$console = $projectDir . '/bin/console'; $console = $projectDir . '/bin/console';
$cmd = sprintf( $cmd = sprintf(
'%s %s %s %s > /dev/null 2>&1 &', '%s %s %s %s > /dev/null 2>&1 &',
escapeshellarg($console), escapeshellarg($console),
escapeshellarg('mto:agent:ingest:run'), escapeshellarg('mto:agent:ingest:run'),
escapeshellarg((string) $job->getId()), escapeshellarg((string)$job->getId()),
escapeshellarg('--no-interaction'), escapeshellarg('--no-interaction'),
); );
@@ -261,8 +261,32 @@ class DocumentController extends AbstractController
exec($cmd); exec($cmd);
return $this->redirectToRoute('admin_job_show', [ return $this->redirectToRoute('admin_job_show', [
'id' => (string) $job->getId(), 'id' => (string)$job->getId(),
]); ]);
} }
#[Route(
'/reset',
name: 'admin_document_reset',
methods: ['POST']
)]
public function resetCompleteSystem(ParameterBagInterface $params, Connection $connection): ?RedirectResponse
{
@unlink($params->get('mto.vector.data.path') . '/index.ndjson');
@unlink($params->get('mto.vector.data.path') . '/vector.index');
@unlink($params->get('mto.vector.data.path') . '/vector.index.meta.json');
$sql = '
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE db.document;
SET FOREIGN_KEY_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE db.document_version;
SET FOREIGN_KEY_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE db.ingest_job;
SET FOREIGN_KEY_CHECKS = 1;
';
$connection->executeQuery($sql);
return $this->redirectToRoute('admin_dashboard');
}
} }

View File

@@ -16,6 +16,17 @@
<hr class="border-secondary"> <hr class="border-secondary">
<form method="post" action="/admin/documents/reset" class="text-danger" onsubmit="return resetSystem()">
<p class="fw-bold">Reset des Systems</p>
<p>Unwiderruflicher Reset des gesamten Systems</p>
<button type="submit" class="btn btn-outline-danger">Reset System</button>
</form>
</div> </div>
</div> </div>
<script>
function resetSystem() {
return confirm('Sind Sie sicher, dass Sie das gesamte System zurücksetzen möchten?');
}
</script>
{% endblock %} {% endblock %}