Files
rag-from-scratch/gui/worker.py
T
davide f947131f16 feat(gui): aggiunge interfaccia desktop PySide6 con tema light/dark
- chat con Markdown e formule KaTeX (via QWebEngineView + CDN)
- top bar con selezione collezione ChromaDB e bottone ☀️/🌙
- input multiriga con Enter per inviare e Shift+Enter per andare a capo
- animazione thinking durante la generazione
- fonti dei chunk mostrate sotto ogni risposta

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-09 09:50:37 +02:00

29 lines
912 B
Python

from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
from PySide6.QtCore import QThread, Signal
import chromadb
class RagWorker(QThread):
finished = Signal(str, list) # response, chunks
error = Signal(str)
def __init__(self, question: str, collection: chromadb.Collection, parent=None):
super().__init__(parent)
self.question = question
self.collection = collection
def run(self) -> None:
try:
from rag.rag import retrieve, build_prompt, call_ollama
chunks = retrieve(self.collection, self.question)
system, prompt = build_prompt(self.question, chunks)
response = call_ollama(prompt, system=system)
self.finished.emit(response, chunks)
except Exception as exc:
self.error.emit(str(exc))