Delete playground_chat.py
Browse files- playground_chat.py +0 -79
playground_chat.py
DELETED
|
@@ -1,79 +0,0 @@
|
|
| 1 |
-
"""Playground script for testing the full chat pipeline (Orchestrator β Retriever β Chatbot).
|
| 2 |
-
|
| 3 |
-
Usage:
|
| 4 |
-
uv run python playground_chat.py
|
| 5 |
-
|
| 6 |
-
Tweak the variables in the CONFIG section below and re-run.
|
| 7 |
-
"""
|
| 8 |
-
|
| 9 |
-
import asyncio
|
| 10 |
-
import json
|
| 11 |
-
from langchain_core.messages import HumanMessage
|
| 12 |
-
|
| 13 |
-
from src.agents.orchestration import orchestrator
|
| 14 |
-
from src.agents.chatbot import chatbot
|
| 15 |
-
from src.rag.retriever import retriever
|
| 16 |
-
from src.api.v1.chat import _format_context, _extract_sources
|
| 17 |
-
|
| 18 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 19 |
-
# CONFIG β change these freely
|
| 20 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 21 |
-
MESSAGE = "Berapa digital rate card untuk Net Message?"
|
| 22 |
-
USER_ID = "8b6c18fd-8971-46e5-b106-35b7afb412e0"
|
| 23 |
-
TOP_K = 5 # number of chunks to retrieve
|
| 24 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
async def main():
|
| 28 |
-
print(f"\n{'='*60}")
|
| 29 |
-
print(f"Message : {MESSAGE}")
|
| 30 |
-
print(f"User ID : {USER_ID}")
|
| 31 |
-
print(f"Top-K : {TOP_K}")
|
| 32 |
-
print(f"{'='*60}\n")
|
| 33 |
-
|
| 34 |
-
# Step 1: Orchestrator β intent analysis
|
| 35 |
-
print("ββ Step 1: Orchestrator ββββββββββββββββββββββββββββββββββ")
|
| 36 |
-
intent_result = await orchestrator.analyze_message(MESSAGE)
|
| 37 |
-
print(json.dumps(intent_result, indent=2, ensure_ascii=False))
|
| 38 |
-
|
| 39 |
-
context = ""
|
| 40 |
-
sources = []
|
| 41 |
-
|
| 42 |
-
# Step 2: Retriever (only if orchestrator says so)
|
| 43 |
-
if intent_result.get("needs_search"):
|
| 44 |
-
search_query = intent_result.get("search_query", MESSAGE)
|
| 45 |
-
print(f"\nββ Step 2: Retriever (query: {search_query!r}) ββββββββββββββ")
|
| 46 |
-
raw_results = await retriever.retrieve(
|
| 47 |
-
query=search_query,
|
| 48 |
-
user_id=USER_ID,
|
| 49 |
-
db=None,
|
| 50 |
-
k=TOP_K,
|
| 51 |
-
)
|
| 52 |
-
context = _format_context(raw_results)
|
| 53 |
-
sources = _extract_sources(raw_results)
|
| 54 |
-
|
| 55 |
-
print(f"Retrieved {len(raw_results)} chunk(s). Sources:")
|
| 56 |
-
for s in sources:
|
| 57 |
-
print(f" - {s['filename']} p.{s['page_label']}")
|
| 58 |
-
print(f"\nContext preview:\n{context[:500]}{'...' if len(context) > 500 else ''}")
|
| 59 |
-
else:
|
| 60 |
-
print("\nββ Step 2: Retriever β skipped (no search needed)")
|
| 61 |
-
|
| 62 |
-
# Step 3: Direct response (greetings, etc.)
|
| 63 |
-
if intent_result.get("direct_response"):
|
| 64 |
-
print("\nββ Step 3: Direct response (no LLM call) ββββββββββββββββ")
|
| 65 |
-
print(intent_result["direct_response"])
|
| 66 |
-
return
|
| 67 |
-
|
| 68 |
-
# Step 4: Chatbot β generate answer
|
| 69 |
-
print("\nββ Step 4: Chatbot response ββββββββββββββββββββββββββββββ")
|
| 70 |
-
messages = [HumanMessage(content=MESSAGE)]
|
| 71 |
-
response = await chatbot.generate_response(messages, context)
|
| 72 |
-
print(response)
|
| 73 |
-
|
| 74 |
-
print(f"\nββ Sources βββββββββββββββββββββββββββββββββββββββββββββββ")
|
| 75 |
-
print(json.dumps(sources, indent=2, ensure_ascii=False))
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
if __name__ == "__main__":
|
| 79 |
-
asyncio.run(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|