essprasad commited on
Commit
cc3f67c
·
verified ·
1 Parent(s): 1d44ecf

Delete utils/feedback.py

Browse files
Files changed (1) hide show
  1. utils/feedback.py +0 -105
utils/feedback.py DELETED
@@ -1,105 +0,0 @@
1
- """
2
- utils/feedback.py
3
- Unified feedback handler for Clinical Research Chatbot.
4
-
5
- Includes:
6
- 1️⃣ Feedback Queue (unanswered/low-confidence queries)
7
- 2️⃣ User Voting (👍 Helpful / 👎 Not Helpful)
8
- """
9
-
10
- import os
11
- import json
12
- from datetime import datetime
13
-
14
- # ----------------------------
15
- # File Paths
16
- # ----------------------------
17
- FEEDBACK_QUEUE_LOG = "logs/feedback_queue.jsonl"
18
- FEEDBACK_VOTES_LOG = "logs/feedback_votes.jsonl"
19
-
20
-
21
- # ----------------------------
22
- # Feedback Queue (for Admin Review)
23
- # ----------------------------
24
- def log_feedback(query: str, notes: str = "", sources=None):
25
- """
26
- Store unanswered or low-confidence queries for admin review.
27
- Saves to JSONL (one entry per line).
28
- """
29
- entry = {
30
- "timestamp": datetime.utcnow().isoformat(),
31
- "query": query,
32
- "notes": notes,
33
- "sources": sources or [],
34
- }
35
-
36
- os.makedirs(os.path.dirname(FEEDBACK_QUEUE_LOG), exist_ok=True)
37
- with open(FEEDBACK_QUEUE_LOG, "a", encoding="utf-8") as f:
38
- f.write(json.dumps(entry, ensure_ascii=False) + "\n")
39
-
40
- print(f"📝 Feedback queued for admin review: {query}")
41
-
42
-
43
- def load_feedback(limit: int = 20):
44
- """
45
- Load last N feedback entries for admin dashboard.
46
- """
47
- if not os.path.exists(FEEDBACK_QUEUE_LOG):
48
- return []
49
- with open(FEEDBACK_QUEUE_LOG, "r", encoding="utf-8") as f:
50
- lines = f.readlines()
51
- entries = [json.loads(line) for line in lines]
52
- return entries[-limit:]
53
-
54
-
55
- def clear_feedback():
56
- """
57
- Clear feedback log (admin only).
58
- """
59
- if os.path.exists(FEEDBACK_QUEUE_LOG):
60
- os.remove(FEEDBACK_QUEUE_LOG)
61
- print("🗑️ Feedback log cleared.")
62
-
63
-
64
- # ----------------------------
65
- # User Voting (for “Helpful / Not Helpful”)
66
- # ----------------------------
67
- def save_vote_feedback(query: str, vote: str, context=None):
68
- """
69
- Log user votes (👍 / 👎) on chatbot responses.
70
- """
71
- entry = {
72
- "timestamp": datetime.utcnow().isoformat(),
73
- "query": query,
74
- "vote": vote,
75
- "context": context or {},
76
- }
77
-
78
- os.makedirs(os.path.dirname(FEEDBACK_VOTES_LOG), exist_ok=True)
79
- try:
80
- with open(FEEDBACK_VOTES_LOG, "a", encoding="utf-8") as f:
81
- f.write(json.dumps(entry, ensure_ascii=False) + "\n")
82
- print(f"🗳️ User voted '{vote}' for query: {query}")
83
- except Exception as e:
84
- print(f"⚠️ Failed to save vote feedback: {e}")
85
-
86
-
87
- def load_votes(limit: int = 50):
88
- """
89
- Load last N user votes for analysis.
90
- """
91
- if not os.path.exists(FEEDBACK_VOTES_LOG):
92
- return []
93
- with open(FEEDBACK_VOTES_LOG, "r", encoding="utf-8") as f:
94
- lines = f.readlines()
95
- entries = [json.loads(line) for line in lines]
96
- return entries[-limit:]
97
-
98
-
99
- def clear_votes():
100
- """
101
- Clear user voting log (admin only).
102
- """
103
- if os.path.exists(FEEDBACK_VOTES_LOG):
104
- os.remove(FEEDBACK_VOTES_LOG)
105
- print("🗑️ User vote feedback cleared.")