rag-chatbot / test_response.py
Mobiworks's picture
Sync from GitHub via hub-sync
4cf1913 verified
Raw
History Blame Contribute Delete
1.22 kB
#!/usr/bin/env python
"""Test chatbot response with increased token limit."""
from components.vector_store import VectorStore
from components.embedder import HuggingFaceEmbedder
from components.retriever import Retriever
from components.llm_handler import LLMHandler
from components.prompt_template import build_prompt
from app.config import VECTOR_DB_PATH
# Setup
embedder = HuggingFaceEmbedder()
vs = VectorStore(embedder=embedder, index_path=VECTOR_DB_PATH)
vs.load()
retriever = Retriever(vs, use_reranker=True)
llm = LLMHandler()
# Query
query = 'Tell me about culture of Pakistan'
docs = retriever.retrieve_documents(query)
prompt = build_prompt(query, docs)
print(f'\nπŸ” Query: "{query}"')
print(f'πŸ“š Retrieved {len(docs)} chunks\n')
print('=' * 80)
print('πŸ“ RESPONSE:')
print('=' * 80)
answer = llm.generate(prompt)
print(answer)
print('=' * 80)
print(f'\nβœ… Complete response generated ({len(answer)} chars)')
# Check for complete sentences
sentence_terminators = {'.', '!', '?'}
ends_complete = answer.rstrip() and answer.rstrip()[-1] in sentence_terminators
status = "βœ“ Complete sentence" if ends_complete else "⚠ Incomplete"
print(f' Last character: "{answer.rstrip()[-1]}" β€” {status}\n')