Spaces:
Runtime error
Runtime error
File size: 1,507 Bytes
3849d4d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
"""
Simple Usage Example - UPB RAG System
Demonstrates basic usage of the conversational RAG chain.
"""
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).parent))
from setup_retrieval import setup_retrieval_system
from rag.chain import UPBRAGChain
def main():
"""Simple example of using the RAG chain."""
print("Initializing UPB RAG system...")
# Setup retrieval system
retriever, _, _ = setup_retrieval_system(
vectorstore_path="vectorstore/faiss_index",
use_existing=True
)
# Create RAG chain
rag_chain = UPBRAGChain(retriever, retrieval_method="hybrid")
print("\nRAG system ready! Type your questions (or 'salir' to exit)\n")
print("=" * 70)
# Interactive loop
while True:
# Get user question
question = input("\nTu pregunta: ").strip()
if not question:
continue
if question.lower() in ['salir', 'exit', 'quit']:
print("\nGracias por usar el asistente UPB. Hasta pronto!")
break
if question.lower() == 'limpiar':
rag_chain.clear_history()
print("Historial de conversación limpiado.")
continue
# Get response
print("\nAsistente: ", end="", flush=True)
response = rag_chain.invoke(question, include_sources=False)
print(response['answer'])
print("\n" + "-" * 70)
if __name__ == "__main__":
main()
|