Paul Magee commited on
Commit
f4fc950
·
1 Parent(s): c594ca1

updated docs

Browse files
Future_Improvements.md CHANGED
@@ -147,14 +147,19 @@ This improvement would significantly enhance the chatbot's usability by making i
147
  - Added timestamps and metadata to feedback records
148
  - Organized feedback in dedicated feedback directory
149
 
150
- 2. **Add Flexible Storage System** ✅
 
 
 
 
 
151
  - Created feedback manager with save_feedback interface
152
  - Implemented custom save_feedback_with_prefix function for better organization
153
  - Added logging for feedback events
154
  - Ensured proper error handling and success tracking
155
 
156
- 3. **Next Steps**
157
- - Implement Supabase integration for persistent feedback storage on Streamlit Cloud
158
  - Consider other database options: MongoDB Atlas (free tier) for JSON-like storage
159
  - Add indexing capability for feedback analytics
160
  - Create migration utility to move file-based feedback to database
 
147
  - Added timestamps and metadata to feedback records
148
  - Organized feedback in dedicated feedback directory
149
 
150
+ 2. **Implement Supabase Database Storage** ✅
151
+ - Feedback is now stored in a Supabase database for persistent, structured storage and analytics.
152
+ - **Note:** Due to unresolved issues with Supabase Row Level Security (RLS) and the anon key, the application currently uses the Supabase service (admin) key to insert feedback, bypassing RLS. This is a workaround and should be reviewed with Supabase for a more secure, production-ready solution.
153
+ - All feedback fields are now saved and can be reviewed in the Supabase dashboard.
154
+
155
+ 3. **Add Flexible Storage System** ✅
156
  - Created feedback manager with save_feedback interface
157
  - Implemented custom save_feedback_with_prefix function for better organization
158
  - Added logging for feedback events
159
  - Ensured proper error handling and success tracking
160
 
161
+ 4. **Next Steps**
162
+ - If Supabase resolves the anon key/RLS issue, update the app to use the anon key and a secure RLS policy for public feedback.
163
  - Consider other database options: MongoDB Atlas (free tier) for JSON-like storage
164
  - Add indexing capability for feedback analytics
165
  - Create migration utility to move file-based feedback to database
README.md CHANGED
@@ -74,4 +74,14 @@ If you experience issues with imports or module reloading:
74
  streamlit run Public_Chat.py --server.runOnSave=true
75
  ```
76
 
77
- See [DEPLOYMENT.md](DEPLOYMENT.md) for cloud deployment options.
 
 
 
 
 
 
 
 
 
 
 
74
  streamlit run Public_Chat.py --server.runOnSave=true
75
  ```
76
 
77
+ See [DEPLOYMENT.md](DEPLOYMENT.md) for cloud deployment options.
78
+
79
+ ## Feedback System (Updated)
80
+
81
+ - User feedback is now stored in a Supabase database for persistent, structured storage and future analytics.
82
+ - Due to issues with Supabase Row Level Security (RLS) and the anon key, the application currently uses the Supabase service (admin) key to insert feedback. This bypasses RLS and allows all feedback to be saved securely from the backend.
83
+ - **Note:** Using the service key is a workaround. For production, consult Supabase support or documentation to implement a more secure, best-practice solution for public/anon feedback collection.
84
+
85
+ ## Progress
86
+ - Feedback database integration with Supabase is complete and operational.
87
+ - All feedback fields are now saved and can be reviewed in the Supabase dashboard.
architecture.md CHANGED
@@ -82,60 +82,16 @@ The application follows a multi-page Streamlit structure with clear separation o
82
 
83
  ## Feedback System
84
 
85
- The application includes a comprehensive feedback collection system:
86
-
87
- ### Components
88
-
89
- 1. **UI Components**:
90
- - Thumbs up/down buttons after each chatbot response
91
- - Detailed feedback form for negative ratings
92
- - Categories for feedback classification
93
- - Optional free-text input for detailed comments
94
- - Thank you messages after feedback submission
95
-
96
- 2. **Feedback Storage**:
97
- - JSON files with rating prefix in filenames (pos_/neg_)
98
- - Timestamped feedback records
99
- - Storage in dedicated feedback directory
100
- - File-based persistence for simplicity
101
-
102
- 3. **Implementation Details**:
103
- - Unique message IDs based on content hash
104
- - Feedback state tracking in session state
105
- - Independent feedback for each assistant message
106
- - Proper state management across page refreshes
107
-
108
- ### Feedback Flow
109
-
110
- 1. User receives a response from the chatbot
111
- 2. Feedback buttons appear below the response
112
- 3. User clicks thumbs up or thumbs down
113
- 4. For positive feedback:
114
- - Feedback is immediately saved
115
- - Thank you message is displayed
116
- 5. For negative feedback:
117
- - Detailed feedback form appears
118
- - User selects a category and optional comments
119
- - On submission, feedback is saved
120
- - Thank you message is displayed
121
-
122
- ### Technical Implementation
123
-
124
- 1. **Message Identification**:
125
- - Each message has a unique ID based on its content hash
126
- - This ensures consistent identification across sessions
127
-
128
- 2. **Feedback Storage**:
129
- - Uses `save_feedback_with_prefix()` function
130
- - Creates files with naming pattern: `{pos|neg}_feedback_{timestamp}.json`
131
- - Stores complete feedback data including query, response, rating, and comments
132
-
133
- 3. **State Management**:
134
- - Tracks feedback status in `st.session_state.feedback`
135
- - Maintains proper UI state for each message
136
- - Ensures independent feedback for each response
137
-
138
- This system allows for continuous improvement of the chatbot based on user feedback, providing valuable insights into response quality and areas for enhancement.
139
 
140
  ## Document Indexing System
141
 
 
82
 
83
  ## Feedback System
84
 
85
+ The application now uses Supabase as the backend for storing user feedback:
86
+
87
+ - All feedback is saved in a Supabase database table for persistent, structured storage and future analytics.
88
+ - Due to unresolved issues with Supabase Row Level Security (RLS) and the anon key, the application currently uses the Supabase service (admin) key to insert feedback. This bypasses RLS and allows all feedback to be saved securely from the backend.
89
+ - **Security Note:** Using the service key is a workaround. For production, consult Supabase support or documentation to implement a more secure, best-practice solution for public/anon feedback collection. Never expose the service key in frontend or public code.
90
+ - All feedback fields are now saved and can be reviewed in the Supabase dashboard.
91
+
92
+ #### Progress
93
+ - Feedback database integration with Supabase is complete and operational.
94
+ - The feedback manager now supports saving feedback directly to the database.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  ## Document Indexing System
97
 
feedback/feedback_advanced.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ "id","user_id","query","normalized_query","question_hash","response","rating","category","comment","tags","status","admin_note","assigned_to","document_id","source","priority","reviewed","timestamp"
2
+ "b1a7c1e2-1234-4a5b-8c9d-1e2f3a4b5c6d","alice","What is a habit?","what is a habit","a1b2c3d4","A habit is a routine behavior repeated regularly.","positive","","","","open","","","doc_001","user","low","FALSE","2024-06-01T12:00:00Z"
3
+ "c2b8d2f3-2345-5b6c-9d0e-2f3a4b5c6d7e","bob","How do I form a new habit?","how do i form a new habit","b2c3d4e5","Start small, be consistent, and track your progress.","negative","Incomplete answer","Did not mention rewards or triggers.","habit formation,incomplete","in progress","Will add more detail to doc_002","admin1","doc_002","user","high","TRUE","2024-06-01T12:05:00Z"
4
+ "d3c9e3f4-3456-6c7d-0e1f-3a4b5c6d7e8f","carol","What is a habit?","what is a habit","a1b2c3d4","A habit is a routine behavior repeated regularly.","negative","Irrelevant to question","Answer was off-topic.","habit formation,off-topic","open","","","doc_001","user","medium","FALSE","2024-06-01T12:10:00Z"
supabase_test.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from supabase import create_client
2
+
3
+ SUPABASE_URL = "https://cxptnhxhrhlwiuzdcyxl.supabase.co" # Replace with your new project URL
4
+ SUPABASE_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImN4cHRuaHhocmhsd2l1emRjeXhsIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0NDg2NDc0NiwiZXhwIjoyMDYwNDQwNzQ2fQ.22iQvvjU94vD2asqny7D5_18T4drmx7Q1dVZFQroDs4" # Replace with your new anon key
5
+
6
+ supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
7
+ data = {"query": "test", "response": "test", "rating": "positive"}
8
+ result = supabase.table("feedback_test").insert(data).execute()
9
+ print(result)
utils/feedback.py CHANGED
@@ -6,6 +6,20 @@ from datetime import datetime
6
  # Setup logging
7
  logger = logging.getLogger(__name__)
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  class FeedbackManager:
10
  """Handles the storage and retrieval of user feedback for chatbot responses."""
11
 
@@ -61,5 +75,25 @@ class FeedbackManager:
61
  logger.error(f"Error retrieving feedback: {str(e)}")
62
  return []
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  # Create a singleton instance
65
  feedback_manager = FeedbackManager()
 
6
  # Setup logging
7
  logger = logging.getLogger(__name__)
8
 
9
+ # Supabase integration
10
+ try:
11
+ from supabase import create_client, Client
12
+ SUPABASE_URL = os.getenv("SUPABASE_URL")
13
+ SUPABASE_KEY = os.getenv("SUPABASE_KEY")
14
+ if SUPABASE_URL and SUPABASE_KEY:
15
+ supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
16
+ else:
17
+ supabase = None
18
+ logger.warning("Supabase URL or Key not set. Supabase feedback saving will be disabled.")
19
+ except ImportError:
20
+ supabase = None
21
+ logger.warning("supabase-py not installed. Supabase feedback saving will be disabled.")
22
+
23
  class FeedbackManager:
24
  """Handles the storage and retrieval of user feedback for chatbot responses."""
25
 
 
75
  logger.error(f"Error retrieving feedback: {str(e)}")
76
  return []
77
 
78
+ def save_feedback_supabase(self, feedback_data):
79
+ """
80
+ Save feedback to Supabase table 'feedback'.
81
+ Args:
82
+ feedback_data (dict): Dictionary containing feedback information matching the table schema.
83
+ Returns:
84
+ bool: True if feedback was saved successfully, False otherwise
85
+ """
86
+ if not supabase:
87
+ logger.error("Supabase client not available. Feedback not saved to Supabase.")
88
+ return False
89
+ try:
90
+ logger.info(f"Attempting to insert feedback: {feedback_data}") # Debug outgoing data
91
+ data, count = supabase.table('feedback').insert(feedback_data).execute()
92
+ logger.info(f"Feedback saved to Supabase: {data}")
93
+ return True
94
+ except Exception as e:
95
+ logger.error(f"Error saving feedback to Supabase: {str(e)}")
96
+ return False
97
+
98
  # Create a singleton instance
99
  feedback_manager = FeedbackManager()