denyAccessUnlessGranted(ApplicationRoles::ROLE_KNOWLEDGE_ADMIN); $selectedType = trim((string) $request->query->get('type', '')); if ($selectedType === '' || !in_array($selectedType, $evals->supportedTypeNames(), true)) { $selectedType = 'retrieval'; } return $this->render('admin/evals/index.html.twig', [ 'types' => $evals->supportedTypes(), 'overview' => $evals->overview(), 'cases_by_type' => $evals->casesByType(), 'selected_type' => $selectedType, 'selected_report' => $evals->readTypeReport($selectedType), 'last_report' => $evals->readLastReport(), ]); } #[Route('/run', name: 'admin_evals_run', methods: ['POST'])] public function run(Request $request, EvalAdminService $evals): Response { $this->denyAccessUnlessGranted(ApplicationRoles::ROLE_KNOWLEDGE_ADMIN); if (!$this->isCsrfTokenValid('admin_eval_run', (string) $request->request->get('_token'))) { throw $this->createAccessDeniedException(); } $type = trim((string) $request->request->get('type', 'retrieval')); $caseId = trim((string) $request->request->get('case_id', '')); try { $report = $evals->run($type, $caseId !== '' ? $caseId : null); $type = trim((string) ($report['type'] ?? $type)); $this->addFlash( ((int) ($report['failed'] ?? 0)) === 0 ? 'success' : 'danger', sprintf( 'Eval %s abgeschlossen: %d/%d bestanden.', $type, (int) ($report['passed'] ?? 0), (int) ($report['total'] ?? 0) ) ); } catch (\Throwable $e) { $this->addFlash('danger', $e->getMessage()); } return $this->redirectToRoute('admin_evals_index', [ 'type' => $type, ]); } #[Route('/case/create', name: 'admin_evals_case_create', methods: ['POST'])] public function createCase(Request $request, EvalAdminService $evals): Response { $this->denyAccessUnlessGranted(ApplicationRoles::ROLE_KNOWLEDGE_ADMIN); if (!$this->isCsrfTokenValid('admin_eval_case_create', (string) $request->request->get('_token'))) { throw $this->createAccessDeniedException(); } $type = trim((string) $request->request->get('type', 'retrieval')); try { $created = $evals->createCase( type: $type, id: (string) $request->request->get('id', ''), prompt: (string) $request->request->get('prompt', ''), assertJson: (string) $request->request->get('assert_json', ''), historyJson: (string) $request->request->get('history_json', ''), requestContextHint: (string) $request->request->get('request_context_hint', ''), ); $type = (string) ($created['type'] ?? $type); $this->addFlash( 'success', sprintf('Eval-Case "%s" wurde in %s.ndjson gespeichert.', (string) ($created['id'] ?? ''), $type) ); } catch (\Throwable $e) { $this->addFlash('danger', $e->getMessage()); } if (!in_array($type, $evals->supportedTypeNames(), true)) { $type = 'retrieval'; } return $this->redirectToRoute('admin_evals_index', [ 'type' => $type, ]); } }