Ocillus commited on
Commit
5865d99
·
verified ·
1 Parent(s): 7a1d277

Update nylon.py

Browse files
Files changed (1) hide show
  1. nylon.py +21 -17
nylon.py CHANGED
@@ -107,17 +107,22 @@ class ChatDatabase:
107
  self.messages.append(message)
108
 
109
  self.messages_array = np.array(self.messages, dtype=object)
110
- self.sender_array = self.messages_array[:, 0]
 
 
 
 
111
  print(f'Database loaded. Number of messages: {len(self.messages_array)}')
112
 
113
  def add_message(self, sender, time, text, tag=None):
114
- message = (sender, time, text, tag)
115
  self.messages.append(message)
116
- self.messages_array = np.append(self.messages_array, [message], axis=0)
117
  self.sender_array = np.append(self.sender_array, sender)
118
  with open(self.filename, 'a') as f:
119
  f.write(f'{sender}\t{time}\t{text}\t{tag}\n')
120
 
 
121
  def predict_response_separate(self, query, sender, cache):
122
  if self.messages_array is None:
123
  print("Error: messages_array is None")
@@ -150,17 +155,16 @@ class ChatDatabase:
150
 
151
  query_keywords = query.lower().split()
152
 
 
 
 
 
153
  # Filter messages by sender, tag, and keywords in a single line
154
- if query_tag:
155
- sender_messages = self.messages_array[
156
- (self.sender_array == sender) &
157
- np.array([any(keyword in message.lower() for keyword in query_keywords) for message in self.messages_array[:, 2]])
158
- ]
159
- else:
160
- sender_messages = self.messages_array[
161
- (self.sender_array == sender) &
162
- np.array([any(keyword in message.lower() for keyword in query_keywords) for message in self.messages_array[:, 2]])
163
- ]
164
 
165
  if len(sender_messages) == 0:
166
  print(f"No messages found for sender: {sender} with the given keywords")
@@ -213,14 +217,14 @@ class ChatDatabase:
213
  # Usage example remains the same
214
  '''
215
  # Usage example
216
- db = ChatDatabase('messages.txt')
217
 
218
  # Example 1: Get relevant messages
219
- query = 'Goodnight.'
220
- sender = 'Alice'
221
  N = 10
222
  cache = {}
223
- query_tag = 'evening'
224
 
225
  relevant_messages = db.get_relevant_messages(sender, query, N, cache, query_tag)
226
 
 
107
  self.messages.append(message)
108
 
109
  self.messages_array = np.array(self.messages, dtype=object)
110
+ print(self.messages_array,'hihii')
111
+ if len(self.messages_array)==0:
112
+ self.sender_array = []
113
+ else:
114
+ self.sender_array = self.messages_array[:, 0]
115
  print(f'Database loaded. Number of messages: {len(self.messages_array)}')
116
 
117
  def add_message(self, sender, time, text, tag=None):
118
+ message = np.array((sender, time, text, tag)).flatten()
119
  self.messages.append(message)
120
+ self.messages_array = np.append(self.messages_array, message, axis=0)
121
  self.sender_array = np.append(self.sender_array, sender)
122
  with open(self.filename, 'a') as f:
123
  f.write(f'{sender}\t{time}\t{text}\t{tag}\n')
124
 
125
+
126
  def predict_response_separate(self, query, sender, cache):
127
  if self.messages_array is None:
128
  print("Error: messages_array is None")
 
155
 
156
  query_keywords = query.lower().split()
157
 
158
+ #Filter by sender
159
+ sender_messages = self.messages_array[self.sender_array == sender]
160
+ print(f"Number of messages from sender {sender}: {len(sender_messages)}")
161
+
162
  # Filter messages by sender, tag, and keywords in a single line
163
+ sender_messages = self.messages_array[
164
+ (self.sender_array == sender) &
165
+ np.array([any(keyword in message.lower() for keyword in query_keywords) for message in self.messages_array[:, 2]])
166
+ ]
167
+
 
 
 
 
 
168
 
169
  if len(sender_messages) == 0:
170
  print(f"No messages found for sender: {sender} with the given keywords")
 
217
  # Usage example remains the same
218
  '''
219
  # Usage example
220
+ db = ChatDatabase('memory.txt')
221
 
222
  # Example 1: Get relevant messages
223
+ query = 'fisical policy'
224
+ sender = 'Arcana'
225
  N = 10
226
  cache = {}
227
+ query_tag = None
228
 
229
  relevant_messages = db.get_relevant_messages(sender, query, N, cache, query_tag)
230