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))