mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-31 10:37:12 -04:00 
			
		
		
		
	Add llmindex to systemstatus
This commit is contained in:
		
							parent
							
								
									20e7f01cec
								
							
						
					
					
						commit
						e2fc7f596d
					
				| @ -314,6 +314,9 @@ describe('SettingsComponent', () => { | |||||||
|         sanity_check_status: SystemStatusItemStatus.ERROR, |         sanity_check_status: SystemStatusItemStatus.ERROR, | ||||||
|         sanity_check_last_run: new Date().toISOString(), |         sanity_check_last_run: new Date().toISOString(), | ||||||
|         sanity_check_error: 'Error running sanity check.', |         sanity_check_error: 'Error running sanity check.', | ||||||
|  |         llmindex_status: SystemStatusItemStatus.DISABLED, | ||||||
|  |         llmindex_last_modified: new Date().toISOString(), | ||||||
|  |         llmindex_error: null, | ||||||
|       }, |       }, | ||||||
|     } |     } | ||||||
|     jest.spyOn(systemStatusService, 'get').mockReturnValue(of(status)) |     jest.spyOn(systemStatusService, 'get').mockReturnValue(of(status)) | ||||||
|  | |||||||
| @ -254,6 +254,43 @@ | |||||||
|                   <h6><ng-container i18n>Error</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.sanity_check_error}}</span> |                   <h6><ng-container i18n>Error</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.sanity_check_error}}</span> | ||||||
|                 } |                 } | ||||||
|               </ng-template> |               </ng-template> | ||||||
|  |               @if (aiEnabled) { | ||||||
|  |                 <dt i18n>AI Index</dt> | ||||||
|  |                 <dd class="d-flex align-items-center"> | ||||||
|  |                   <button class="btn btn-sm d-flex align-items-center btn-dark text-uppercase small" [ngbPopover]="llmIndexStatus" triggers="click mouseenter:mouseleave"> | ||||||
|  |                     {{status.tasks.llmindex_status}} | ||||||
|  |                     @if (status.tasks.llmindex_status === 'OK') { | ||||||
|  |                       @if (isStale(status.tasks.llmindex_last_modified)) { | ||||||
|  |                         <i-bs name="exclamation-triangle-fill" class="text-warning ms-2 lh-1"></i-bs> | ||||||
|  |                       } @else { | ||||||
|  |                         <i-bs name="check-circle-fill" class="text-primary ms-2 lh-1"></i-bs> | ||||||
|  |                       } | ||||||
|  |                     } @else { | ||||||
|  |                       <i-bs name="exclamation-triangle-fill" class="ms-2 lh-1" | ||||||
|  |                       [class.text-danger]="status.tasks.llmindex_status === SystemStatusItemStatus.ERROR" | ||||||
|  |                       [class.text-warning]="status.tasks.llmindex_status === SystemStatusItemStatus.WARNING" | ||||||
|  |                       [class.text-muted]="status.tasks.llmindex_status === SystemStatusItemStatus.DISABLED"></i-bs> | ||||||
|  |                     } | ||||||
|  |                   </button> | ||||||
|  |                   @if (currentUserIsSuperUser) { | ||||||
|  |                     @if (isRunning(PaperlessTaskName.LLMIndexUpdate)) { | ||||||
|  |                       <div class="spinner-border spinner-border-sm ms-2" role="status"></div> | ||||||
|  |                     } @else { | ||||||
|  |                       <button class="btn btn-sm d-flex align-items-center btn-dark small ms-2" (click)="runTask(PaperlessTaskName.LLMIndexUpdate)"> | ||||||
|  |                         <i-bs name="play-fill"></i-bs>  | ||||||
|  |                         <ng-container i18n>Run Task</ng-container> | ||||||
|  |                       </button> | ||||||
|  |                     } | ||||||
|  |                   } | ||||||
|  |                 </dd> | ||||||
|  |                 <ng-template #llmIndexStatus> | ||||||
|  |                   @if (status.tasks.llmindex_status === 'OK') { | ||||||
|  |                     <h6><ng-container i18n>Last Run</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.llmindex_last_modified | customDate:'medium'}}</span> | ||||||
|  |                   } @else { | ||||||
|  |                     <h6><ng-container i18n>Error</ng-container>:</h6> <span class="font-monospace small">{{status.tasks.llmindex_error}}</span> | ||||||
|  |                   } | ||||||
|  |                 </ng-template> | ||||||
|  |               } | ||||||
|             </dl> |             </dl> | ||||||
|           </div> |           </div> | ||||||
|         </div> |         </div> | ||||||
|  | |||||||
| @ -67,6 +67,9 @@ const status: SystemStatus = { | |||||||
|     sanity_check_status: SystemStatusItemStatus.OK, |     sanity_check_status: SystemStatusItemStatus.OK, | ||||||
|     sanity_check_last_run: new Date().toISOString(), |     sanity_check_last_run: new Date().toISOString(), | ||||||
|     sanity_check_error: null, |     sanity_check_error: null, | ||||||
|  |     llmindex_status: SystemStatusItemStatus.OK, | ||||||
|  |     llmindex_last_modified: new Date().toISOString(), | ||||||
|  |     llmindex_error: null, | ||||||
|   }, |   }, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -12,9 +12,11 @@ import { | |||||||
|   SystemStatus, |   SystemStatus, | ||||||
|   SystemStatusItemStatus, |   SystemStatusItemStatus, | ||||||
| } from 'src/app/data/system-status' | } from 'src/app/data/system-status' | ||||||
|  | import { SETTINGS_KEYS } from 'src/app/data/ui-settings' | ||||||
| import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe' | import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe' | ||||||
| import { FileSizePipe } from 'src/app/pipes/file-size.pipe' | import { FileSizePipe } from 'src/app/pipes/file-size.pipe' | ||||||
| import { PermissionsService } from 'src/app/services/permissions.service' | import { PermissionsService } from 'src/app/services/permissions.service' | ||||||
|  | import { SettingsService } from 'src/app/services/settings.service' | ||||||
| import { SystemStatusService } from 'src/app/services/system-status.service' | import { SystemStatusService } from 'src/app/services/system-status.service' | ||||||
| import { TasksService } from 'src/app/services/tasks.service' | import { TasksService } from 'src/app/services/tasks.service' | ||||||
| import { ToastService } from 'src/app/services/toast.service' | import { ToastService } from 'src/app/services/toast.service' | ||||||
| @ -41,6 +43,7 @@ export class SystemStatusDialogComponent implements OnInit { | |||||||
|   private tasksService = inject(TasksService) |   private tasksService = inject(TasksService) | ||||||
|   private toastService = inject(ToastService) |   private toastService = inject(ToastService) | ||||||
|   private permissionsService = inject(PermissionsService) |   private permissionsService = inject(PermissionsService) | ||||||
|  |   private settingsService = inject(SettingsService) | ||||||
| 
 | 
 | ||||||
|   public SystemStatusItemStatus = SystemStatusItemStatus |   public SystemStatusItemStatus = SystemStatusItemStatus | ||||||
|   public PaperlessTaskName = PaperlessTaskName |   public PaperlessTaskName = PaperlessTaskName | ||||||
| @ -56,6 +59,10 @@ export class SystemStatusDialogComponent implements OnInit { | |||||||
|     return this.permissionsService.isSuperUser() |     return this.permissionsService.isSuperUser() | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   get aiEnabled(): boolean { | ||||||
|  |     return this.settingsService.get(SETTINGS_KEYS.AI_ENABLED) | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   public ngOnInit() { |   public ngOnInit() { | ||||||
|     this.versionMismatch = |     this.versionMismatch = | ||||||
|       environment.production && |       environment.production && | ||||||
|  | |||||||
| @ -182,6 +182,7 @@ export class DocumentDetailComponent | |||||||
| { | { | ||||||
|   private documentsService = inject(DocumentService) |   private documentsService = inject(DocumentService) | ||||||
|   private route = inject(ActivatedRoute) |   private route = inject(ActivatedRoute) | ||||||
|  |   private tagService = inject(TagService) | ||||||
|   private correspondentService = inject(CorrespondentService) |   private correspondentService = inject(CorrespondentService) | ||||||
|   private documentTypeService = inject(DocumentTypeService) |   private documentTypeService = inject(DocumentTypeService) | ||||||
|   private router = inject(Router) |   private router = inject(Router) | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ export enum SystemStatusItemStatus { | |||||||
|   OK = 'OK', |   OK = 'OK', | ||||||
|   ERROR = 'ERROR', |   ERROR = 'ERROR', | ||||||
|   WARNING = 'WARNING', |   WARNING = 'WARNING', | ||||||
|  |   DISABLED = 'DISABLED', | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface SystemStatus { | export interface SystemStatus { | ||||||
| @ -43,5 +44,8 @@ export interface SystemStatus { | |||||||
|     sanity_check_status: SystemStatusItemStatus |     sanity_check_status: SystemStatusItemStatus | ||||||
|     sanity_check_last_run: string // ISO date string
 |     sanity_check_last_run: string // ISO date string
 | ||||||
|     sanity_check_error: string |     sanity_check_error: string | ||||||
|  |     llmindex_status: SystemStatusItemStatus | ||||||
|  |     llmindex_last_modified: string // ISO date string
 | ||||||
|  |     llmindex_error: string | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -558,12 +558,18 @@ def llmindex_index( | |||||||
|         ) |         ) | ||||||
|         from paperless_ai.indexing import update_llm_index |         from paperless_ai.indexing import update_llm_index | ||||||
| 
 | 
 | ||||||
|         result = update_llm_index( |         try: | ||||||
|             progress_bar_disable=progress_bar_disable, |             result = update_llm_index( | ||||||
|             rebuild=rebuild, |                 progress_bar_disable=progress_bar_disable, | ||||||
|         ) |                 rebuild=rebuild, | ||||||
|         task.status = states.SUCCESS |             ) | ||||||
|         task.result = result |             task.status = states.SUCCESS | ||||||
|  |             task.result = result | ||||||
|  |         except Exception as e: | ||||||
|  |             logger.error("LLM index error: " + str(e)) | ||||||
|  |             task.status = states.FAILURE | ||||||
|  |             task.result = str(e) | ||||||
|  | 
 | ||||||
|         task.date_done = timezone.now() |         task.date_done = timezone.now() | ||||||
|         task.save(update_fields=["status", "result", "date_done"]) |         task.save(update_fields=["status", "result", "date_done"]) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -185,6 +185,7 @@ from paperless.serialisers import UserSerializer | |||||||
| from paperless.views import StandardPagination | from paperless.views import StandardPagination | ||||||
| from paperless_ai.ai_classifier import get_ai_document_classification | from paperless_ai.ai_classifier import get_ai_document_classification | ||||||
| from paperless_ai.chat import stream_chat_with_documents | from paperless_ai.chat import stream_chat_with_documents | ||||||
|  | from paperless_ai.indexing import update_llm_index | ||||||
| from paperless_ai.matching import extract_unmatched_names | from paperless_ai.matching import extract_unmatched_names | ||||||
| from paperless_ai.matching import match_correspondents_by_name | from paperless_ai.matching import match_correspondents_by_name | ||||||
| from paperless_ai.matching import match_document_types_by_name | from paperless_ai.matching import match_document_types_by_name | ||||||
| @ -2465,6 +2466,10 @@ class TasksViewSet(ReadOnlyModelViewSet): | |||||||
|             sanity_check, |             sanity_check, | ||||||
|             {"scheduled": False, "raise_on_error": False}, |             {"scheduled": False, "raise_on_error": False}, | ||||||
|         ), |         ), | ||||||
|  |         PaperlessTask.TaskName.LLMINDEX_UPDATE: ( | ||||||
|  |             update_llm_index, | ||||||
|  |             {"scheduled": False, "rebuild": False}, | ||||||
|  |         ), | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     def get_queryset(self): |     def get_queryset(self): | ||||||
| @ -2970,6 +2975,31 @@ class SystemStatusView(PassUserMixin): | |||||||
|             last_sanity_check.date_done if last_sanity_check else None |             last_sanity_check.date_done if last_sanity_check else None | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|  |         ai_config = AIConfig() | ||||||
|  |         if not ai_config.llm_index_enabled: | ||||||
|  |             llmindex_status = "DISABLED" | ||||||
|  |             llmindex_error = None | ||||||
|  |             llmindex_last_modified = None | ||||||
|  |         else: | ||||||
|  |             last_llmindex_update = ( | ||||||
|  |                 PaperlessTask.objects.filter( | ||||||
|  |                     task_name=PaperlessTask.TaskName.LLMINDEX_UPDATE, | ||||||
|  |                 ) | ||||||
|  |                 .order_by("-date_done") | ||||||
|  |                 .first() | ||||||
|  |             ) | ||||||
|  |             llmindex_status = "OK" | ||||||
|  |             llmindex_error = None | ||||||
|  |             if last_llmindex_update is None: | ||||||
|  |                 llmindex_status = "WARNING" | ||||||
|  |                 llmindex_error = "No LLM index update tasks found" | ||||||
|  |             elif last_llmindex_update and last_llmindex_update.status == states.FAILURE: | ||||||
|  |                 llmindex_status = "ERROR" | ||||||
|  |                 llmindex_error = last_llmindex_update.result | ||||||
|  |             llmindex_last_modified = ( | ||||||
|  |                 last_llmindex_update.date_done if last_llmindex_update else None | ||||||
|  |             ) | ||||||
|  | 
 | ||||||
|         return Response( |         return Response( | ||||||
|             { |             { | ||||||
|                 "pngx_version": current_version, |                 "pngx_version": current_version, | ||||||
| @ -3007,6 +3037,9 @@ class SystemStatusView(PassUserMixin): | |||||||
|                     "sanity_check_status": sanity_check_status, |                     "sanity_check_status": sanity_check_status, | ||||||
|                     "sanity_check_last_run": sanity_check_last_run, |                     "sanity_check_last_run": sanity_check_last_run, | ||||||
|                     "sanity_check_error": sanity_check_error, |                     "sanity_check_error": sanity_check_error, | ||||||
|  |                     "llmindex_status": llmindex_status, | ||||||
|  |                     "llmindex_last_modified": llmindex_last_modified, | ||||||
|  |                     "llmindex_error": llmindex_error, | ||||||
|                 }, |                 }, | ||||||
|             }, |             }, | ||||||
|         ) |         ) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user